Skip to content

Commit

Permalink
aws_opensearchserverless_lifecycle_policy: make test more nondetermin…
Browse files Browse the repository at this point in the history
…istic
  • Loading branch information
johnsonaj committed Nov 1, 2023
1 parent 4cc9878 commit a3be0d7
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 36 deletions.
8 changes: 5 additions & 3 deletions internal/service/opensearchserverless/lifecycle_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import (
"github.com/hashicorp/terraform-provider-aws/names"
)

// Function annotations are used for resource registration to the Provider. DO NOT EDIT.
// @FrameworkResource(name="Lifecycle Policy")
func newResourceLifecyclePolicy(_ context.Context) (resource.ResourceWithConfigure, error) {
return &resourceLifecyclePolicy{}, nil
Expand All @@ -45,11 +44,11 @@ type resourceLifecyclePolicy struct {
framework.WithTimeouts
}

func (r *resourceLifecyclePolicy) Metadata(_ context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) {
func (r *resourceLifecyclePolicy) Metadata(_ context.Context, _ resource.MetadataRequest, resp *resource.MetadataResponse) {
resp.TypeName = "aws_opensearchserverless_lifecycle_policy"
}

func (r *resourceLifecyclePolicy) Schema(ctx context.Context, req resource.SchemaRequest, resp *resource.SchemaResponse) {
func (r *resourceLifecyclePolicy) Schema(_ context.Context, _ resource.SchemaRequest, resp *resource.SchemaResponse) {
resp.Schema = schema.Schema{
Attributes: map[string]schema.Attribute{
"description": schema.StringAttribute{
Expand All @@ -76,6 +75,9 @@ func (r *resourceLifecyclePolicy) Schema(ctx context.Context, req resource.Schem
},
"policy_version": schema.StringAttribute{
Computed: true,
PlanModifiers: []planmodifier.String{
stringplanmodifier.UseStateForUnknown(),
},
},
"type": schema.StringAttribute{
Required: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"github.com/hashicorp/terraform-provider-aws/names"
)

// Function annotations are used for datasource registration to the Provider. DO NOT EDIT.
// @FrameworkDataSource(name="Lifecycle Policy")
func newDataSourceLifecyclePolicy(context.Context) (datasource.DataSourceWithConfigure, error) {
return &dataSourceLifecyclePolicy{}, nil
Expand All @@ -35,11 +34,11 @@ type dataSourceLifecyclePolicy struct {
framework.DataSourceWithConfigure
}

func (d *dataSourceLifecyclePolicy) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) { // nosemgrep:ci.meta-in-func-name
func (d *dataSourceLifecyclePolicy) Metadata(_ context.Context, _ datasource.MetadataRequest, resp *datasource.MetadataResponse) { // nosemgrep:ci.meta-in-func-name
resp.TypeName = "aws_opensearchserverless_lifecycle_policy"
}

func (d *dataSourceLifecyclePolicy) Schema(ctx context.Context, req datasource.SchemaRequest, resp *datasource.SchemaResponse) {
func (d *dataSourceLifecyclePolicy) Schema(_ context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) {
resp.Schema = schema.Schema{
Attributes: map[string]schema.Attribute{
"created_date": schema.StringAttribute{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,12 @@ resource "aws_opensearchserverless_lifecycle_policy" "test" {
"Rules" : [
{
"ResourceType" : "index",
"Resource" : ["index/autoparts-inventory/*"],
"Resource" : ["index/%[1]sy/*"],
"MinIndexRetention" : "81d"
},
{
"ResourceType" : "index",
"Resource" : ["index/sales/orders*"],
"Resource" : ["index/local-sales/%[1]s*"],
"NoMinIndexRetention" : true
}
]
Expand Down
33 changes: 5 additions & 28 deletions internal/service/opensearchserverless/lifecycle_policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func TestAccOpenSearchServerlessLifecyclePolicy_disappears(t *testing.T) {
CheckDestroy: testAccCheckLifecyclePolicyDestroy(ctx),
Steps: []resource.TestStep{
{
Config: testAccLifecyclePolicyConfig_disappears(rName),
Config: testAccLifecyclePolicyConfig_basic(rName),
Check: resource.ComposeTestCheckFunc(
testAccCheckLifecyclePolicyExists(ctx, resourceName, &lifecyclepolicy),
acctest.CheckFrameworkResourceDisappears(ctx, acctest.Provider, tfopensearchserverless.ResourceLifecyclePolicy, resourceName),
Expand Down Expand Up @@ -206,35 +206,12 @@ resource "aws_opensearchserverless_lifecycle_policy" "test" {
"Rules" : [
{
"ResourceType" : "index",
"Resource" : ["index/autoparts-inventory/*"],
"MinIndexRetention" : "81d"
},
{
"ResourceType" : "index",
"Resource" : ["index/sales/orders*"],
"NoMinIndexRetention" : true
}
]
})
}
`, rName)
}

func testAccLifecyclePolicyConfig_disappears(rName string) string {
return fmt.Sprintf(`
resource "aws_opensearchserverless_lifecycle_policy" "test" {
name = %[1]q
type = "retention"
policy = jsonencode({
"Rules" : [
{
"ResourceType" : "index",
"Resource" : ["index/computer-inventory/*"],
"Resource" : ["index/%[1]s/*"],
"MinIndexRetention" : "81d"
},
{
"ResourceType" : "index",
"Resource" : ["index/national-sales/orders*"],
"Resource" : ["index/sales/%[1]s*"],
"NoMinIndexRetention" : true
}
]
Expand All @@ -253,12 +230,12 @@ resource "aws_opensearchserverless_lifecycle_policy" "test" {
"Rules" : [
{
"ResourceType" : "index",
"Resource" : ["index/toy-inventory/*"],
"Resource" : ["index/%[1]s/*"],
"MinIndexRetention" : "81d"
},
{
"ResourceType" : "index",
"Resource" : ["index/holiday-sales/orders*"],
"Resource" : ["index/holiday-sales/%[1]s*"],
"NoMinIndexRetention" : true
}
]
Expand Down

0 comments on commit a3be0d7

Please sign in to comment.