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 5 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
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
20 changes: 20 additions & 0 deletions internal/service/opensearch/domain_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag"
"github.com/hashicorp/terraform-provider-aws/internal/flex"
tftags "github.com/hashicorp/terraform-provider-aws/internal/tags"
"github.com/hashicorp/terraform-provider-aws/internal/verify"
)

// @SDKDataSource("aws_opensearch_domain")
Expand Down Expand Up @@ -362,6 +363,21 @@ func DataSourceDomain() *schema.Resource {
},
},
},
"software_update_options": {
Type: schema.TypeList,
Optional: true,
MaxItems: 1,
DiffSuppressFunc: verify.SuppressMissingOptionalConfigurationBlock,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"auto_software_update_enabled": {
Type: schema.TypeBool,
Optional: true,
Default: false,
},
},
},
},
"tags": tftags.TagsSchemaComputed(),
"vpc_options": {
Type: schema.TypeList,
Expand Down Expand Up @@ -469,6 +485,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