-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* set up muxing to prepare for migration * update dependencies * Simplify muxing * Setting up muxing for tests * Start migrating time offset resource to framework * Implement remaining offset attributes in import function * refactor tests * Remove unneeded test function * add schema validators to offset_days field * Implement update function * tidy the go mod * add pointer receiver to functions implementing framework interfaces * add helper method to convert offset to Int64 type * refactor time offset multiplication * add tests to check updated offset values * Add 'AtLeastOneOf' validators to offset attributes * Create setOffsetValues helper method * Begin migrating time_rotating resource to framework * Implement AtLeastOneOf and int64 AtLeast validators and Create function * add Plan Modifiers to offset resource * add Return statements after offset parsing error handling * Replace !=0 with >0 for offset import checks * Implement import function * Add description to offset and rotating schemas * Add check to ensure that plan modifier is only run when at least one of the offset_* fields has been updated (#51) * Add test to verify behavior of time_offset resource is not altered by migrating from SDKv2 to the Framework (#51) * Update error message * Implement update and partially implement read * Refactor ModifyPlan and Import functions to use setOffsetValues helper function * Partially implement modifyPlan function * Implement IsRFC3339Time validator * Start implementation of time_sleep resource * Implement schema for time_sleep resource * Implement replaceIfOutdated plan modifier * Finish read implementation for time_rotating * fix bug to remove resource after time expiration in time_rotating resource * implement newResource and CRUD operations for time_sleep resource * Remove unneeded code in delete method * add Update implementation to pass values from plan to the state * Start time_static resource migration * Implement schema for time_static resource * Implement importState function for time_static resource * Implement CRUD operations for time_static resource * Update importState implementation to populate schema fields * Refactor time_rotating tests * Refactor time_sleep tests * Refactor time_static tests * Remove SDKv2 versions of provider and resources and move tests to provider directory * Remove provider muxer * Address linter warnings * Upgrade terraform-plugin-framework version to 0.13.0 * Refactor ineffectual assignments * Add markdown description for static resource * Move Metadata and GetSchema functions to the top of each resource * Refactor provider name in order to remove of import alias * Refactor hardcoded value for attribute path * Add checks to return early if diagnostics has error * Refactor setOffsetValues to mutate the plan * Refactor helper functions to return errors * Clean up syntax * Add tests to check if resource has/hasn't been recreated * Set unparam linter to ignore test function * add Terraform version 1.3.* testing * Adding a code comment * Add defensive check for a null Plan in modifyPlan functions * Move offset attribute validators to a ConfigValidators method * Refactor tests to fix typos and add back previously removed test coverage * Refactor upgrade tests to be acceptance tests instead of unit tests * Move rotating config validations outside of attribute validation to configValidators method * Refactor to check for null and unknown values by checking attr.Value directly * Update comment for clarity * Update regex for validator test * Update CHANGELOG.md Co-authored-by: Benjamin Bennett <[email protected]>
- Loading branch information
1 parent
1dc6bcb
commit ea34431
Showing
23 changed files
with
2,482 additions
and
1,445 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -69,6 +69,7 @@ jobs: | |
- '1.0.*' | ||
- '1.1.*' | ||
- '1.2.*' | ||
- '1.3.*' | ||
|
||
steps: | ||
|
||
|
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,70 @@ | ||
package timemodifier | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"time" | ||
|
||
"github.com/hashicorp/terraform-plugin-framework/tfsdk" | ||
"github.com/hashicorp/terraform-plugin-framework/types" | ||
) | ||
|
||
func ReplaceIfOutdated() tfsdk.AttributePlanModifier { | ||
return RequiresReplaceModifier{} | ||
} | ||
|
||
// RequiresReplaceModifier is an AttributePlanModifier that sets RequiresReplace | ||
// on the attribute if the current time is past the stored timestamp. | ||
// | ||
// This custom modifier is necessary because the resource.RequiresReplaceIf | ||
// function uses special logic for Computed attributes which is not applicable | ||
// this use case. | ||
type RequiresReplaceModifier struct{} | ||
|
||
func (r RequiresReplaceModifier) Description(ctx context.Context) string { | ||
return "value must be a string in RFC3339 format" | ||
} | ||
|
||
func (r RequiresReplaceModifier) MarkdownDescription(ctx context.Context) string { | ||
return r.Description(ctx) | ||
} | ||
|
||
func (r RequiresReplaceModifier) Modify(ctx context.Context, req tfsdk.ModifyAttributePlanRequest, resp *tfsdk.ModifyAttributePlanResponse) { | ||
if req.AttributeConfig == nil || req.AttributePlan == nil || req.AttributeState == nil { | ||
// shouldn't happen, but let's not panic if it does | ||
return | ||
} | ||
|
||
if req.State.Raw.IsNull() { | ||
// if we're creating the resource, no need to delete and | ||
// recreate it | ||
return | ||
} | ||
|
||
if req.Plan.Raw.IsNull() { | ||
// if we're deleting the resource, no need to delete and | ||
// recreate it | ||
return | ||
} | ||
|
||
var rotationRFC3339 types.String | ||
diags := tfsdk.ValueAs(ctx, req.AttributeState, &rotationRFC3339) | ||
if diags.HasError() { | ||
resp.Diagnostics.Append(diags...) | ||
return | ||
} | ||
|
||
rotationTimestamp, err := time.Parse(time.RFC3339, rotationRFC3339.Value) | ||
if err != nil { | ||
resp.Diagnostics.AddError( | ||
"replaceIfOutdated plan modifier error", | ||
"The rotation rfc3339 timestamp that was supplied could not be parsed as RFC3339.\n\n+"+ | ||
fmt.Sprintf("Original Error: %s", err), | ||
) | ||
return | ||
} | ||
|
||
now := time.Now().UTC() | ||
|
||
resp.RequiresReplace = now.After(rotationTimestamp) | ||
} |
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,47 @@ | ||
package provider | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/hashicorp/terraform-plugin-framework/datasource" | ||
"github.com/hashicorp/terraform-plugin-framework/diag" | ||
"github.com/hashicorp/terraform-plugin-framework/provider" | ||
"github.com/hashicorp/terraform-plugin-framework/resource" | ||
"github.com/hashicorp/terraform-plugin-framework/tfsdk" | ||
) | ||
|
||
func New() provider.Provider { | ||
return &timeProvider{} | ||
} | ||
|
||
var ( | ||
_ provider.Provider = (*timeProvider)(nil) | ||
_ provider.ProviderWithMetadata = (*timeProvider)(nil) | ||
) | ||
|
||
type timeProvider struct{} | ||
|
||
func (p *timeProvider) Metadata(ctx context.Context, req provider.MetadataRequest, resp *provider.MetadataResponse) { | ||
resp.TypeName = "time" | ||
} | ||
|
||
func (p *timeProvider) Configure(ctx context.Context, req provider.ConfigureRequest, resp *provider.ConfigureResponse) { | ||
|
||
} | ||
|
||
func (p *timeProvider) DataSources(ctx context.Context) []func() datasource.DataSource { | ||
return nil | ||
} | ||
|
||
func (p *timeProvider) Resources(ctx context.Context) []func() resource.Resource { | ||
return []func() resource.Resource{ | ||
NewTimeOffsetResource, | ||
NewTimeRotatingResource, | ||
NewTimeSleepResource, | ||
NewTimeStaticResource, | ||
} | ||
} | ||
|
||
func (p *timeProvider) GetSchema(ctx context.Context) (tfsdk.Schema, diag.Diagnostics) { | ||
return tfsdk.Schema{}, nil | ||
} |
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
Oops, something went wrong.