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

Support for OpenSearch SoftwareUpdateOptions #32234

Merged
merged 7 commits into from
Sep 7, 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/32234.txt
Original file line number Diff line number Diff line change
@@ -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
```
28 changes: 28 additions & 0 deletions internal/service/opensearch/domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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{})
Expand Down
16 changes: 16 additions & 0 deletions internal/service/opensearch/domain_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions internal/service/opensearch/domain_data_source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
),
},
},
Expand Down Expand Up @@ -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" {
Expand Down
50 changes: 50 additions & 0 deletions internal/service/opensearch/domain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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)
}
27 changes: 27 additions & 0 deletions internal/service/opensearch/flex.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions website/docs/d/opensearch_domain.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
5 changes: 5 additions & 0 deletions website/docs/r/opensearch_domain.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)
Expand Down
Loading