diff --git a/.changelog/32234.txt b/.changelog/32234.txt new file mode 100644 index 00000000000..8aeaaa9c525 --- /dev/null +++ b/.changelog/32234.txt @@ -0,0 +1,7 @@ +```release-note:enhancement +resource/aws_opensearch_domain: Add `software_update_options` attribute +``` + +```release-note:enhancement +data-source/aws_opensearch_domain: Add `software_update_options` attribute +``` diff --git a/internal/service/opensearch/domain.go b/internal/service/opensearch/domain.go index ba0d57a71ae..7349d9161d4 100644 --- a/internal/service/opensearch/domain.go +++ b/internal/service/opensearch/domain.go @@ -559,6 +559,22 @@ func ResourceDomain() *schema.Resource { }, }, }, + "software_update_options": { + Type: schema.TypeList, + Optional: true, + Computed: true, + MaxItems: 1, + DiffSuppressFunc: verify.SuppressMissingOptionalConfigurationBlock, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "auto_software_update_enabled": { + Type: schema.TypeBool, + Optional: true, + Computed: true, + }, + }, + }, + }, names.AttrTags: tftags.TagsSchema(), names.AttrTagsAll: tftags.TagsSchemaComputed(), "vpc_options": { @@ -706,6 +722,10 @@ func resourceDomainCreate(ctx context.Context, d *schema.ResourceData, meta inte } } + if v, ok := d.GetOk("software_update_options"); ok { + input.SoftwareUpdateOptions = expandSoftwareUpdateOptions(v.([]interface{})) + } + if v, ok := d.GetOk("vpc_options"); ok { options := v.([]interface{}) if options[0] == nil { @@ -899,6 +919,10 @@ func resourceDomainRead(ctx context.Context, d *schema.ResourceData, meta interf return sdkdiag.AppendErrorf(diags, "setting snapshot_options: %s", err) } + if err := d.Set("software_update_options", flattenSoftwareUpdateOptions(ds.SoftwareUpdateOptions)); err != nil { + return sdkdiag.AppendErrorf(diags, "setting software_update_options: %s", err) + } + if ds.VPCOptions != nil { if err := d.Set("vpc_options", []interface{}{flattenVPCDerivedInfo(ds.VPCOptions)}); err != nil { return sdkdiag.AppendErrorf(diags, "setting vpc_options: %s", err) @@ -1057,6 +1081,10 @@ func resourceDomainUpdate(ctx context.Context, d *schema.ResourceData, meta inte } } + if d.HasChange("software_update_options") { + input.SoftwareUpdateOptions = expandSoftwareUpdateOptions(d.Get("software_update_options").([]interface{})) + } + if d.HasChange("vpc_options") { options := d.Get("vpc_options").([]interface{}) s := options[0].(map[string]interface{}) diff --git a/internal/service/opensearch/domain_data_source.go b/internal/service/opensearch/domain_data_source.go index 9789e1d15a3..b75684f1c45 100644 --- a/internal/service/opensearch/domain_data_source.go +++ b/internal/service/opensearch/domain_data_source.go @@ -362,6 +362,18 @@ func DataSourceDomain() *schema.Resource { }, }, }, + "software_update_options": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "auto_software_update_enabled": { + Type: schema.TypeBool, + Computed: true, + }, + }, + }, + }, "tags": tftags.TagsSchemaComputed(), "vpc_options": { Type: schema.TypeList, @@ -469,6 +481,10 @@ func dataSourceDomainRead(ctx context.Context, d *schema.ResourceData, meta inte return sdkdiag.AppendErrorf(diags, "setting snapshot_options: %s", err) } + if err := d.Set("software_update_options", flattenSoftwareUpdateOptions(ds.SoftwareUpdateOptions)); err != nil { + return sdkdiag.AppendErrorf(diags, "setting software_update_options: %s", err) + } + if ds.VPCOptions != nil { if err := d.Set("vpc_options", []interface{}{flattenVPCDerivedInfo(ds.VPCOptions)}); err != nil { return sdkdiag.AppendErrorf(diags, "setting vpc_options: %s", err) diff --git a/internal/service/opensearch/domain_data_source_test.go b/internal/service/opensearch/domain_data_source_test.go index e08ac54cc58..513c8193301 100644 --- a/internal/service/opensearch/domain_data_source_test.go +++ b/internal/service/opensearch/domain_data_source_test.go @@ -51,6 +51,8 @@ func TestAccOpenSearchDomainDataSource_Data_basic(t *testing.T) { resource.TestCheckResourceAttrPair(datasourceName, "off_peak_window_options.#", resourceName, "off_peak_window_options.#"), resource.TestCheckResourceAttrPair(datasourceName, "snapshot_options.#", resourceName, "snapshot_options.#"), resource.TestCheckResourceAttrPair(datasourceName, "snapshot_options.0.automated_snapshot_start_hour", resourceName, "snapshot_options.0.automated_snapshot_start_hour"), + resource.TestCheckResourceAttrPair(datasourceName, "software_update_options.#", resourceName, "software_update_options.#"), + resource.TestCheckResourceAttrPair(datasourceName, "software_update_options.0.auto_software_update_enabled", resourceName, "software_update_options.0.auto_software_update_enabled"), ), }, }, @@ -179,6 +181,10 @@ POLICY snapshot_options { automated_snapshot_start_hour = 23 } + + software_update_options { + auto_software_update_enabled = true + } } data "aws_opensearch_domain" "test" { diff --git a/internal/service/opensearch/domain_test.go b/internal/service/opensearch/domain_test.go index dd35eefb52c..d8f3ca23833 100644 --- a/internal/service/opensearch/domain_test.go +++ b/internal/service/opensearch/domain_test.go @@ -1817,6 +1817,39 @@ func TestAccOpenSearchDomain_versionUpdate(t *testing.T) { }}) } +func TestAccOpenSearchDomain_softwareUpdateOptions(t *testing.T) { + ctx := acctest.Context(t) + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + + var domain opensearchservice.DomainStatus + rName := testAccRandomDomainName() + resourceName := "aws_opensearch_domain.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acctest.PreCheck(ctx, t); testAccPreCheckIAMServiceLinkedRole(ctx, t) }, + ErrorCheck: acctest.ErrorCheck(t, opensearchservice.EndpointsID), + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + CheckDestroy: testAccCheckDomainDestroy(ctx), + Steps: []resource.TestStep{ + { + Config: testAccDomainConfig_softwareUpdateOptions(rName, false), + Check: resource.ComposeTestCheckFunc( + testAccCheckDomainExists(ctx, resourceName, &domain), + resource.TestCheckResourceAttr(resourceName, "software_update_options.0.auto_software_update_enabled", "false"), + ), + }, + { + Config: testAccDomainConfig_softwareUpdateOptions(rName, true), + Check: resource.ComposeTestCheckFunc( + testAccCheckDomainExists(ctx, resourceName, &domain), + resource.TestCheckResourceAttr(resourceName, "software_update_options.0.auto_software_update_enabled", "true"), + ), + }, + }, + }) +} func TestAccOpenSearchDomain_disappears(t *testing.T) { ctx := acctest.Context(t) if testing.Short() { @@ -3503,3 +3536,20 @@ resource "aws_opensearch_domain" "test" { } `, rName, h, m) } + +func testAccDomainConfig_softwareUpdateOptions(rName string, option bool) string { + return fmt.Sprintf(` +resource "aws_opensearch_domain" "test" { + domain_name = %[1]q + + ebs_options { + ebs_enabled = true + volume_size = 10 + } + + software_update_options { + auto_software_update_enabled = %[2]t + } +} +`, rName, option) +} diff --git a/internal/service/opensearch/flex.go b/internal/service/opensearch/flex.go index e9d3ecbede9..5615066ec13 100644 --- a/internal/service/opensearch/flex.go +++ b/internal/service/opensearch/flex.go @@ -203,6 +203,33 @@ func flattenSnapshotOptions(snapshotOptions *opensearchservice.SnapshotOptions) return []map[string]interface{}{m} } +func expandSoftwareUpdateOptions(in []interface{}) *opensearchservice.SoftwareUpdateOptions { + if len(in) == 0 { + return nil + } + + m := in[0].(map[string]interface{}) + + var out opensearchservice.SoftwareUpdateOptions + if v, ok := m["auto_software_update_enabled"].(bool); ok { + out.AutoSoftwareUpdateEnabled = aws.Bool(v) + } + + return &out +} + +func flattenSoftwareUpdateOptions(softwareUpdateOptions *opensearchservice.SoftwareUpdateOptions) []interface{} { + if softwareUpdateOptions == nil { + return nil + } + + m := map[string]interface{}{ + "auto_software_update_enabled": aws.BoolValue(softwareUpdateOptions.AutoSoftwareUpdateEnabled), + } + + return []interface{}{m} +} + func expandVPCOptions(tfMap map[string]interface{}) *opensearchservice.VPCOptions { if tfMap == nil { return nil diff --git a/website/docs/d/opensearch_domain.html.markdown b/website/docs/d/opensearch_domain.html.markdown index 7502d5e8cc0..daaeca17f44 100644 --- a/website/docs/d/opensearch_domain.html.markdown +++ b/website/docs/d/opensearch_domain.html.markdown @@ -93,6 +93,8 @@ This data source exports the following attributes in addition to the arguments a * `processing` – Status of a configuration change in the domain. * `snapshot_options` – Domain snapshot related options. * `automated_snapshot_start_hour` - Hour during which the service takes an automated daily snapshot of the indices in the domain. +* `software_update_options` - Software update options for the domain + * `auto_software_update_enabled` - Enabled or disabled. * `tags` - Tags assigned to the domain. * `vpc_options` - VPC Options for private OpenSearch domains. * `availability_zones` - Availability zones used by the domain. diff --git a/website/docs/r/opensearch_domain.html.markdown b/website/docs/r/opensearch_domain.html.markdown index 8020e8b8e71..71daeb03f7f 100644 --- a/website/docs/r/opensearch_domain.html.markdown +++ b/website/docs/r/opensearch_domain.html.markdown @@ -335,6 +335,7 @@ The following arguments are optional: * `log_publishing_options` - (Optional) Configuration block for publishing slow and application logs to CloudWatch Logs. This block can be declared multiple times, for each log_type, within the same resource. Detailed below. * `node_to_node_encryption` - (Optional) Configuration block for node-to-node encryption options. Detailed below. * `snapshot_options` - (Optional) Configuration block for snapshot related options. Detailed below. DEPRECATED. For domains running OpenSearch 5.3 and later, Amazon OpenSearch takes hourly automated snapshots, making this setting irrelevant. For domains running earlier versions, OpenSearch takes daily automated snapshots. +* `software_update_options` - (Optional) Software update options for the domain. Detailed below. * `tags` - (Optional) Map of tags to assign to the resource. 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. * `vpc_options` - (Optional) Configuration block for VPC related options. Adding or removing this configuration forces a new resource ([documentation](https://docs.aws.amazon.com/opensearch-service/latest/developerguide/vpc.html)). Detailed below. * `off_peak_window_options` - (Optional) Configuration to add Off Peak update options. ([documentation](https://docs.aws.amazon.com/opensearch-service/latest/developerguide/off-peak.html)). Detailed below. @@ -439,6 +440,10 @@ AWS documentation: [Amazon Cognito Authentication for Dashboard](https://docs.aw * `automated_snapshot_start_hour` - (Required) Hour during which the service takes an automated daily snapshot of the indices in the domain. +### software_update_options + +* `auto_software_update_enabled` - (Optional) Whether automatic service software updates are enabled for the domain. Defaults to `false`. + ### vpc_options AWS documentation: [VPC Support for Amazon OpenSearch Service Domains](https://docs.aws.amazon.com/opensearch-service/latest/developerguide/es-vpc.html)