-
Notifications
You must be signed in to change notification settings - Fork 643
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Copies over the sdkv2 client configuration to make the provider operate 1:1 regardless of the mechanism used.
- Loading branch information
1 parent
8ebcddf
commit a094993
Showing
19 changed files
with
687 additions
and
272 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package defaults | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier" | ||
"github.com/hashicorp/terraform-plugin-framework/types" | ||
) | ||
|
||
var _ planmodifier.Bool = boolDefaultModifier{} | ||
|
||
func DefaultBool(s bool) boolDefaultModifier { | ||
return boolDefaultModifier{Default: s} | ||
} | ||
|
||
type boolDefaultModifier struct { | ||
Default bool | ||
} | ||
|
||
// Description returns a plain text description of the validator's behavior, suitable for a practitioner to understand its impact. | ||
func (m boolDefaultModifier) Description(ctx context.Context) string { | ||
return fmt.Sprintf("If value is not configured, defaults to %v", m.Default) | ||
} | ||
|
||
// MarkdownDescription returns a markdown formatted description of the validator's behavior, suitable for a practitioner to understand its impact. | ||
func (m boolDefaultModifier) MarkdownDescription(ctx context.Context) string { | ||
return fmt.Sprintf("If value is not configured, defaults to `%v`", m.Default) | ||
} | ||
|
||
// PlanModifyBool updates the planned value with the default if its not null | ||
func (m boolDefaultModifier) PlanModifyBool(ctx context.Context, req planmodifier.BoolRequest, resp *planmodifier.BoolResponse) { | ||
// If the attribute configuration is not null, we are done here | ||
if !req.ConfigValue.IsNull() { | ||
return | ||
} | ||
|
||
// If the attribute plan is "known" and "not null", then a previous plan modifier in the sequence | ||
// has already been applied, and we don't want to interfere. | ||
if !req.PlanValue.IsUnknown() && !req.PlanValue.IsNull() { | ||
return | ||
} | ||
|
||
resp.PlanValue = types.BoolValue(m.Default) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package defaults | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/hashicorp/terraform-plugin-framework/attr" | ||
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier" | ||
"github.com/hashicorp/terraform-plugin-framework/types" | ||
) | ||
|
||
var _ planmodifier.List = listDefaultModifier{} | ||
|
||
func DefaultList(elements []attr.Value) listDefaultModifier { | ||
return listDefaultModifier{Elements: elements} | ||
} | ||
|
||
type listDefaultModifier struct { | ||
Elements []attr.Value | ||
} | ||
|
||
// Description returns a plain text description of the validator's behavior, suitable for a practitioner to understand its impact. | ||
func (m listDefaultModifier) Description(_ context.Context) string { | ||
return fmt.Sprintf("If value is not configured, defaults to %s", m.Elements) | ||
} | ||
|
||
// MarkdownDescription returns a markdown formatted description of the validator's behavior, suitable for a practitioner to understand its impact. | ||
func (m listDefaultModifier) MarkdownDescription(_ context.Context) string { | ||
return fmt.Sprintf("If value is not configured, defaults to `%s`", m.Elements) | ||
} | ||
|
||
// PlanModifyList updates the planned value with the default if its not null | ||
func (m listDefaultModifier) PlanModifyList(ctx context.Context, req planmodifier.ListRequest, resp *planmodifier.ListResponse) { | ||
// If the attribute configuration is not null, we are done here | ||
if !req.ConfigValue.IsNull() { | ||
return | ||
} | ||
|
||
// If the attribute plan is "known" and "not null", then a previous plan modifier in the sequence | ||
// has already been applied, and we don't want to interfere. | ||
if !req.PlanValue.IsUnknown() && !req.PlanValue.IsNull() { | ||
return | ||
} | ||
resp.PlanValue, resp.Diagnostics = types.ListValue(req.PlanValue.ElementType(ctx), m.Elements) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package defaults | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/hashicorp/terraform-plugin-framework/attr" | ||
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier" | ||
"github.com/hashicorp/terraform-plugin-framework/types" | ||
) | ||
|
||
var _ planmodifier.Map = mapDefaultModifier{} | ||
|
||
func DefaultMap(elements map[string]attr.Value) mapDefaultModifier { | ||
return mapDefaultModifier{Elements: elements} | ||
} | ||
|
||
type mapDefaultModifier struct { | ||
Elements map[string]attr.Value | ||
} | ||
|
||
// Description returns a plain text description of the validator's behavior, suitable for a practitioner to understand its impact. | ||
func (m mapDefaultModifier) Description(_ context.Context) string { | ||
return fmt.Sprintf("If value is not configured, defaults to %s", m.Elements) | ||
} | ||
|
||
// MarkdownDescription returns a markdown formatted description of the validator's behavior, suitable for a practitioner to understand its impact. | ||
func (m mapDefaultModifier) MarkdownDescription(_ context.Context) string { | ||
return fmt.Sprintf("If value is not configured, defaults to `%s`", m.Elements) | ||
} | ||
|
||
// PlanModifyMap updates the planned value with the default if its not null | ||
func (m mapDefaultModifier) PlanModifyMap(ctx context.Context, req planmodifier.MapRequest, resp *planmodifier.MapResponse) { | ||
// If the attribute configuration is not null, we are done here | ||
if !req.ConfigValue.IsNull() { | ||
return | ||
} | ||
|
||
// If the attribute plan is "known" and "not null", then a previous plan modifier in the sequence | ||
// has already been applied, and we don't want to interfere. | ||
if !req.PlanValue.IsUnknown() && !req.PlanValue.IsNull() { | ||
return | ||
} | ||
resp.PlanValue, resp.Diagnostics = types.MapValue(req.PlanValue.ElementType(ctx), m.Elements) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package defaults | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"math/big" | ||
|
||
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier" | ||
"github.com/hashicorp/terraform-plugin-framework/types" | ||
) | ||
|
||
var _ planmodifier.Number = numberDefaultModifier{} | ||
|
||
func DefaultNumber(s *big.Float) numberDefaultModifier { | ||
return numberDefaultModifier{Default: s} | ||
} | ||
|
||
type numberDefaultModifier struct { | ||
Default *big.Float | ||
} | ||
|
||
// Description returns a plain text description of the validator's behavior, suitable for a practitioner to understand its impact. | ||
func (m numberDefaultModifier) Description(ctx context.Context) string { | ||
return fmt.Sprintf("If value is not configured, defaults to %s", m.Default) | ||
} | ||
|
||
// MarkdownDescription returns a markdown formatted description of the validator's behavior, suitable for a practitioner to understand its impact. | ||
func (m numberDefaultModifier) MarkdownDescription(ctx context.Context) string { | ||
return fmt.Sprintf("If value is not configured, defaults to `%s`", m.Default) | ||
} | ||
|
||
// PlanModifyNumber updates the planned value with the default if its not null | ||
func (m numberDefaultModifier) PlanModifyNumber(ctx context.Context, req planmodifier.NumberRequest, resp *planmodifier.NumberResponse) { | ||
// If the attribute configuration is not null, we are done here | ||
if !req.ConfigValue.IsNull() { | ||
return | ||
} | ||
|
||
// If the attribute plan is "known" and "not null", then a previous plan modifier in the sequence | ||
// has already been applied, and we don't want to interfere. | ||
if !req.PlanValue.IsUnknown() && !req.PlanValue.IsNull() { | ||
return | ||
} | ||
resp.PlanValue = types.NumberValue(m.Default) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package defaults | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/hashicorp/terraform-plugin-framework/attr" | ||
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier" | ||
"github.com/hashicorp/terraform-plugin-framework/types" | ||
) | ||
|
||
var _ planmodifier.Object = objectDefaultModifier{} | ||
|
||
func DefaultObject(elements map[string]attr.Value) objectDefaultModifier { | ||
return objectDefaultModifier{Elements: elements} | ||
} | ||
|
||
type objectDefaultModifier struct { | ||
Elements map[string]attr.Value | ||
} | ||
|
||
// Description returns a plain text description of the validator's behavior, suitable for a practitioner to understand its impact. | ||
func (m objectDefaultModifier) Description(_ context.Context) string { | ||
return fmt.Sprintf("If value is not configured, defaults to %s", m.Elements) | ||
} | ||
|
||
// MarkdownDescription returns a markdown formatted description of the validator's behavior, suitable for a practitioner to understand its impact. | ||
func (m objectDefaultModifier) MarkdownDescription(_ context.Context) string { | ||
return fmt.Sprintf("If value is not configured, defaults to `%s`", m.Elements) | ||
} | ||
|
||
// PlanModifyObject updates the planned value with the default if its not null | ||
func (m objectDefaultModifier) PlanModifyObject(ctx context.Context, req planmodifier.ObjectRequest, resp *planmodifier.ObjectResponse) { | ||
// If the attribute configuration is not null, we are done here | ||
if !req.ConfigValue.IsNull() { | ||
return | ||
} | ||
|
||
// If the attribute plan is "known" and "not null", then a previous plan modifier in the sequence | ||
// has already been applied, and we don't want to interfere. | ||
if !req.PlanValue.IsUnknown() && !req.PlanValue.IsNull() { | ||
return | ||
} | ||
resp.PlanValue, resp.Diagnostics = types.ObjectValue(req.PlanValue.AttributeTypes(ctx), m.Elements) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package defaults | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/hashicorp/terraform-plugin-framework/attr" | ||
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier" | ||
"github.com/hashicorp/terraform-plugin-framework/types" | ||
) | ||
|
||
var _ planmodifier.Set = setDefaultModifier{} | ||
|
||
func DefaultSet(elements []attr.Value) setDefaultModifier { | ||
return setDefaultModifier{Elements: elements} | ||
} | ||
|
||
type setDefaultModifier struct { | ||
Elements []attr.Value | ||
} | ||
|
||
// Description returns a plain text description of the validator's behavior, suitable for a practitioner to understand its impact. | ||
func (m setDefaultModifier) Description(_ context.Context) string { | ||
return fmt.Sprintf("If value is not configured, defaults to %s", m.Elements) | ||
} | ||
|
||
// MarkdownDescription returns a markdown formatted description of the validator's behavior, suitable for a practitioner to understand its impact. | ||
func (m setDefaultModifier) MarkdownDescription(_ context.Context) string { | ||
return fmt.Sprintf("If value is not configured, defaults to `%s`", m.Elements) | ||
} | ||
|
||
// PlanModifySet updates the planned value with the default if its not null | ||
func (m setDefaultModifier) PlanModifySet(ctx context.Context, req planmodifier.SetRequest, resp *planmodifier.SetResponse) { | ||
// If the attribute configuration is not null, we are done here | ||
if !req.ConfigValue.IsNull() { | ||
return | ||
} | ||
|
||
// If the attribute plan is "known" and "not null", then a previous plan modifier in the sequence | ||
// has already been applied, and we don't want to interfere. | ||
if !req.PlanValue.IsUnknown() && !req.PlanValue.IsNull() { | ||
return | ||
} | ||
resp.PlanValue, resp.Diagnostics = types.SetValue(req.PlanValue.ElementType(ctx), m.Elements) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package defaults | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier" | ||
"github.com/hashicorp/terraform-plugin-framework/types" | ||
) | ||
|
||
var _ planmodifier.String = stringDefaultModifier{} | ||
|
||
func DefaultString(s string) stringDefaultModifier { | ||
return stringDefaultModifier{Default: s} | ||
} | ||
|
||
type stringDefaultModifier struct { | ||
Computed bool | ||
Default string | ||
} | ||
|
||
// Description returns a plain text description of the validator's behavior, suitable for a practitioner to understand its impact. | ||
func (m stringDefaultModifier) Description(ctx context.Context) string { | ||
return fmt.Sprintf("If value is not configured, defaults to %s", m.Default) | ||
} | ||
|
||
// MarkdownDescription returns a markdown formatted description of the validator's behavior, suitable for a practitioner to understand its impact. | ||
func (m stringDefaultModifier) MarkdownDescription(ctx context.Context) string { | ||
return fmt.Sprintf("If value is not configured, defaults to `%s`, computed? %t", m.Default, m.Computed) | ||
} | ||
|
||
// PlanModifyString updates the planned value with the default if its not null | ||
func (m stringDefaultModifier) PlanModifyString(ctx context.Context, req planmodifier.StringRequest, resp *planmodifier.StringResponse) { | ||
// If the attribute configuration is not null, we are done here | ||
if !req.ConfigValue.IsNull() { | ||
return | ||
} | ||
|
||
// If the attribute plan is "known" and "not null", then a previous plan modifier in the sequence | ||
// has already been applied, and we don't want to interfere. | ||
if !req.PlanValue.IsUnknown() && !req.PlanValue.IsNull() { | ||
return | ||
} | ||
resp.PlanValue = types.StringValue(m.Default) | ||
} |
Oops, something went wrong.