Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add standby_replicas attribute on the aws_opensearchserverless_collection resource #34677

Merged
merged 8 commits into from
Dec 11, 2023
Merged
18 changes: 18 additions & 0 deletions internal/service/opensearchserverless/collection.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ type resourceCollectionData struct {
ID types.String `tfsdk:"id"`
KmsKeyARN types.String `tfsdk:"kms_key_arn"`
Name types.String `tfsdk:"name"`
StandbyReplicas types.String `tfsdk:"standby_replicas"`
Tags types.Map `tfsdk:"tags"`
TagsAll types.Map `tfsdk:"tags_all"`
Timeouts timeouts.Value `tfsdk:"timeouts"`
Expand Down Expand Up @@ -112,6 +113,17 @@ func (r *resourceCollection) Schema(ctx context.Context, req resource.SchemaRequ
},
names.AttrTags: tftags.TagsAttribute(),
names.AttrTagsAll: tftags.TagsAttributeComputedOnly(),
"standby_replicas": schema.StringAttribute{
Optional: true,
Computed: true,
PlanModifiers: []planmodifier.String{
stringplanmodifier.RequiresReplace(),
stringplanmodifier.UseStateForUnknown(),
},
Validators: []validator.String{
enum.FrameworkValidate[awstypes.StandbyReplicas](),
},
},
"type": schema.StringAttribute{
Optional: true,
Computed: true,
Expand Down Expand Up @@ -158,6 +170,10 @@ func (r *resourceCollection) Create(ctx context.Context, req resource.CreateRequ
in.Type = awstypes.CollectionType(plan.Type.ValueString())
}

if !plan.StandbyReplicas.IsNull() {
in.StandbyReplicas = awstypes.StandbyReplicas(plan.StandbyReplicas.ValueString())
}

out, err := conn.CreateCollection(ctx, in)
if err != nil {
resp.Diagnostics.AddError(
Expand Down Expand Up @@ -187,6 +203,7 @@ func (r *resourceCollection) Create(ctx context.Context, req resource.CreateRequ
state.Description = flex.StringToFramework(ctx, waitOut.Description)
state.KmsKeyARN = flex.StringToFramework(ctx, waitOut.KmsKeyArn)
state.Name = flex.StringToFramework(ctx, waitOut.Name)
state.StandbyReplicas = flex.StringValueToFramework(ctx, waitOut.StandbyReplicas)
state.Type = flex.StringValueToFramework(ctx, waitOut.Type)

resp.Diagnostics.Append(resp.State.Set(ctx, &state)...)
Expand Down Expand Up @@ -223,6 +240,7 @@ func (r *resourceCollection) Read(ctx context.Context, req resource.ReadRequest,
state.ID = flex.StringToFramework(ctx, out.Id)
state.KmsKeyARN = flex.StringToFramework(ctx, out.KmsKeyArn)
state.Name = flex.StringToFramework(ctx, out.Name)
state.StandbyReplicas = flex.StringValueToFramework(ctx, out.StandbyReplicas)
state.Type = flex.StringValueToFramework(ctx, out.Type)

resp.Diagnostics.Append(resp.State.Set(ctx, &state)...)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ func (d *dataSourceCollection) Schema(_ context.Context, _ datasource.SchemaRequ
},
},
names.AttrTags: tftags.TagsAttributeComputedOnly(),
"standby_replicas": schema.StringAttribute{
Computed: true,
},
"type": schema.StringAttribute{
Computed: true,
},
Expand Down Expand Up @@ -133,6 +136,7 @@ func (d *dataSourceCollection) Read(ctx context.Context, req datasource.ReadRequ
data.ID = flex.StringToFramework(ctx, out.Id)
data.KmsKeyARN = flex.StringToFramework(ctx, out.KmsKeyArn)
data.Name = flex.StringToFramework(ctx, out.Name)
data.StandbyReplicas = flex.StringValueToFramework(ctx, out.StandbyReplicas)
data.Type = flex.StringValueToFramework(ctx, out.Type)

createdDate := time.UnixMilli(aws.ToInt64(out.CreatedDate))
Expand Down Expand Up @@ -168,6 +172,7 @@ type dataSourceCollectionData struct {
KmsKeyARN types.String `tfsdk:"kms_key_arn"`
LastModifiedDate types.String `tfsdk:"last_modified_date"`
Name types.String `tfsdk:"name"`
StandbyReplicas types.String `tfsdk:"standby_replicas"`
Tags types.Map `tfsdk:"tags"`
Type types.String `tfsdk:"type"`
}
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ func TestAccOpenSearchServerlessCollectionDataSource_name(t *testing.T) {
resource.TestCheckResourceAttrPair(dataSourceName, "dashboard_endpoint", resourceName, "dashboard_endpoint"),
resource.TestCheckResourceAttrPair(dataSourceName, "description", resourceName, "description"),
resource.TestCheckResourceAttrPair(dataSourceName, "kms_key_arn", resourceName, "kms_key_arn"),
resource.TestCheckResourceAttrPair(dataSourceName, "standby_replicas", resourceName, "standby_replicas"),
resource.TestCheckResourceAttrPair(dataSourceName, "type", resourceName, "type"),
),
},
Expand Down
52 changes: 52 additions & 0 deletions internal/service/opensearchserverless/collection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,44 @@ func TestAccOpenSearchServerlessCollection_basic(t *testing.T) {
})
}

func TestAccOpenSearchServerlessCollection_standbyReplicas(t *testing.T) {
ctx := acctest.Context(t)
var collection types.CollectionDetail
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
rStandbyReplicas := "DISABLED"
resourceName := "aws_opensearchserverless_collection.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() {
acctest.PreCheck(ctx, t)
acctest.PreCheckPartitionHasService(t, names.OpenSearchServerlessEndpointID)
testAccPreCheckCollection(ctx, t)
},
ErrorCheck: acctest.ErrorCheck(t, names.OpenSearchServerlessEndpointID),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
CheckDestroy: testAccCheckCollectionDestroy(ctx),
Steps: []resource.TestStep{
{
Config: testAccCollectionConfig_standbyReplicas(rName, rStandbyReplicas),
Check: resource.ComposeTestCheckFunc(
testAccCheckCollectionExists(ctx, resourceName, &collection),
resource.TestCheckResourceAttrSet(resourceName, "type"),
resource.TestCheckResourceAttrSet(resourceName, "collection_endpoint"),
resource.TestCheckResourceAttrSet(resourceName, "dashboard_endpoint"),
resource.TestCheckResourceAttrSet(resourceName, "kms_key_arn"),
resource.TestCheckResourceAttrSet(resourceName, "standby_replicas"),
resource.TestCheckResourceAttr(resourceName, "standby_replicas", rStandbyReplicas),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func TestAccOpenSearchServerlessCollection_tags(t *testing.T) {
ctx := acctest.Context(t)
var collection types.CollectionDetail
Expand Down Expand Up @@ -265,6 +303,20 @@ resource "aws_opensearchserverless_collection" "test" {
)
}

func testAccCollectionConfig_standbyReplicas(rName string, rStandbyReplicas string) string {
return acctest.ConfigCompose(
testAccCollectionBaseConfig(rName),
fmt.Sprintf(`
resource "aws_opensearchserverless_collection" "test" {
name = %[1]q
standby_replicas = %2q

depends_on = [aws_opensearchserverless_security_policy.test]
}
`, rName, rStandbyReplicas),
)
}

func testAccCollectionConfig_update(rName, description string) string {
return acctest.ConfigCompose(
testAccCollectionBaseConfig(rName),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,4 @@ This data source exports the following attributes in addition to the arguments a
* `last_modified_date` - Date the Collection was last modified.
* `tags` - A map of tags to assign to the collection.
* `type` - Type of collection.
* `standby_replicas` - Indicates whether standby replicas should be used for a collection.
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ The following arguments are optional:
* `description` - (Optional) Description of the collection.
* `tags` - (Optional) A map of tags to assign to the collection. If configured with a provider [`default_tags` configuration block](https://registry.terraform.io/providers/hashicorp/aws/latest/docs#default_tags-configuration-block) present, tags with matching keys will overwrite those defined at the provider-level.
* `type` - (Optional) Type of collection. One of `SEARCH`, `TIMESERIES`, or `VECTORSEARCH`. Defaults to `TIMESERIES`.
* `standby_replicas - (optional)` Indicates whether standby replicas should be used for a collection. One of `ENABLED` or `DISABLED`. Defaults to `ENABLED`.

## Attribute Reference

Expand Down