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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changelog/34677.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
```release-note:enhancement
resource/aws_opensearchserverless_collection: Add `standby_replicas` attribute
```

```release-note:enhancement
data-source/aws_opensearchserverless_collection: Add `standby_replicas` attribute
```
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 @@ -110,6 +111,17 @@ func (r *resourceCollection) Schema(ctx context.Context, req resource.SchemaRequ
`must start with any lower case letter and can can include any lower case letter, number, or "-"`),
},
},
"standby_replicas": schema.StringAttribute{
Optional: true,
Computed: true,
PlanModifiers: []planmodifier.String{
stringplanmodifier.RequiresReplace(),
stringplanmodifier.UseStateForUnknown(),
},
Validators: []validator.String{
enum.FrameworkValidate[awstypes.StandbyReplicas](),
},
},
names.AttrTags: tftags.TagsAttribute(),
names.AttrTagsAll: tftags.TagsAttributeComputedOnly(),
"type": schema.StringAttribute{
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 @@ -82,6 +82,9 @@ func (d *dataSourceCollection) Schema(_ context.Context, _ datasource.SchemaRequ
),
},
},
"standby_replicas": schema.StringAttribute{
Computed: true,
},
names.AttrTags: tftags.TagsAttributeComputedOnly(),
"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 @@ -46,6 +46,7 @@ func TestAccOpenSearchServerlessCollectionDataSource_basic(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
51 changes: 51 additions & 0 deletions internal/service/opensearchserverless/collection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,43 @@ 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)
standbyReplicas := "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, standbyReplicas),
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.TestCheckResourceAttr(resourceName, "standby_replicas", standbyReplicas),
),
},
{
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 +302,20 @@ resource "aws_opensearchserverless_collection" "test" {
)
}

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

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

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 @@ -38,5 +38,6 @@ This data source exports the following attributes in addition to the arguments a
* `description` - Description of the collection.
* `kms_key_arn` - The ARN of the Amazon Web Services KMS key used to encrypt the collection.
* `last_modified_date` - Date the Collection was last modified.
* `standby_replicas` - Indicates whether standby replicas should be used for a collection.
* `tags` - A map of tags to assign to the collection.
* `type` - Type of collection.
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ The following arguments are required:
The following arguments are optional:

* `description` - (Optional) Description of the collection.
* `standby_replicas` - (Optional) Indicates whether standby replicas should be used for a collection. One of `ENABLED` or `DISABLED`. Defaults to `ENABLED`.
* `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`.

Expand Down
Loading