-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
There's a fair bit of complexity around handling computed settings. I'll look at adding this back in a follow up PR, but want to get this resource in a working state so we can make a new release. This covers the case where settings are applied as part of an index template
- Loading branch information
Showing
6 changed files
with
155 additions
and
160 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
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
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,39 @@ | ||
package planmodifiers | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier" | ||
"github.com/hashicorp/terraform-plugin-framework/types/basetypes" | ||
) | ||
|
||
func BoolUseDefaultIfUnknown(defaultValue bool) boolDefault { | ||
return boolDefault{defaultValue: defaultValue} | ||
} | ||
|
||
type boolDefault struct { | ||
defaultValue bool | ||
} | ||
|
||
func (bd boolDefault) PlanModifyBool(ctx context.Context, req planmodifier.BoolRequest, resp *planmodifier.BoolResponse) { | ||
// Do nothing if there is a known planned value. | ||
if !req.PlanValue.IsUnknown() { | ||
return | ||
} | ||
|
||
// Do nothing if there is an unknown configuration value, otherwise interpolation gets messed up. | ||
if req.ConfigValue.IsUnknown() { | ||
return | ||
} | ||
|
||
resp.PlanValue = basetypes.NewBoolValue(bd.defaultValue) | ||
} | ||
|
||
func (bd boolDefault) Description(context.Context) string { | ||
return fmt.Sprintf("Sets the value to [%t] if unknown", bd.defaultValue) | ||
} | ||
|
||
func (bd boolDefault) MarkdownDescription(ctx context.Context) string { | ||
return bd.Description(ctx) | ||
} |
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,39 @@ | ||
package planmodifiers | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier" | ||
"github.com/hashicorp/terraform-plugin-framework/types/basetypes" | ||
) | ||
|
||
func StringUseDefaultIfUnknown(defaultValue string) stringDefault { | ||
return stringDefault{defaultValue: defaultValue} | ||
} | ||
|
||
type stringDefault struct { | ||
defaultValue string | ||
} | ||
|
||
func (bd stringDefault) PlanModifyString(ctx context.Context, req planmodifier.StringRequest, resp *planmodifier.StringResponse) { | ||
// Do nothing if there is a known planned value. | ||
if !req.PlanValue.IsUnknown() { | ||
return | ||
} | ||
|
||
// Do nothing if there is an unknown configuration value, otherwise interpolation gets messed up. | ||
if req.ConfigValue.IsUnknown() { | ||
return | ||
} | ||
|
||
resp.PlanValue = basetypes.NewStringValue(bd.defaultValue) | ||
} | ||
|
||
func (bd stringDefault) Description(context.Context) string { | ||
return fmt.Sprintf("Sets the value to [%s] if unknown", bd.defaultValue) | ||
} | ||
|
||
func (bd stringDefault) MarkdownDescription(ctx context.Context) string { | ||
return bd.Description(ctx) | ||
} |