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 1 commit
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
51 changes: 51 additions & 0 deletions internal/service/opensearch/domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,21 @@ func ResourceDomain() *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,
},
},
},
},
names.AttrTags: tftags.TagsSchema(),
names.AttrTagsAll: tftags.TagsSchemaComputed(),
"vpc_options": {
Expand Down Expand Up @@ -699,6 +714,24 @@ func resourceDomainCreate(ctx context.Context, d *schema.ResourceData, meta inte
}
}

if v, ok := d.GetOk("software_update_options"); ok {
options := v.([]interface{})

if len(options) == 1 {
if options[0] == nil {
return sdkdiag.AppendErrorf(diags, "At least one field is expected inside software_update_options")
}

o := options[0].(map[string]interface{})

softwareUpdateOptions := opensearchservice.SoftwareUpdateOptions{
AutoSoftwareUpdateEnabled: aws.Bool(o["auto_software_update_enabled"].(bool)),
}

input.SoftwareUpdateOptions = &softwareUpdateOptions
}
}

if v, ok := d.GetOk("vpc_options"); ok {
options := v.([]interface{})
if options[0] == nil {
Expand Down Expand Up @@ -892,6 +925,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", flattenVPCDerivedInfo(ds.VPCOptions)); err != nil {
return sdkdiag.AppendErrorf(diags, "setting vpc_options: %s", err)
Expand Down Expand Up @@ -1050,6 +1087,20 @@ func resourceDomainUpdate(ctx context.Context, d *schema.ResourceData, meta inte
}
}

if d.HasChange("software_update_options") {
options := d.Get("software_update_options").([]interface{})

if len(options) == 1 {
o := options[0].(map[string]interface{})

softwareUpdateOptions := opensearchservice.SoftwareUpdateOptions{
AutoSoftwareUpdateEnabled: aws.Bool(o["auto_software_update_enabled"].(bool)),
}

input.SoftwareUpdateOptions = &softwareUpdateOptions
}
}

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 @@ -2,6 +2,7 @@ package opensearch

import (
"context"
"github.com/hashicorp/terraform-provider-aws/internal/verify"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/opensearchservice"
Expand Down Expand Up @@ -355,6 +356,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 @@ -462,6 +478,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", flattenVPCDerivedInfo(ds.VPCOptions)); err != nil {
return sdkdiag.AppendErrorf(diags, "setting vpc_options: %s", err)
Expand Down
10 changes: 10 additions & 0 deletions internal/service/opensearch/flex.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,16 @@ func flattenSnapshotOptions(snapshotOptions *opensearchservice.SnapshotOptions)
return []map[string]interface{}{m}
}

func flattenSoftwareUpdateOptions(softwareUpdateOptions *opensearchservice.SoftwareUpdateOptions) map[string]interface{} {
if softwareUpdateOptions == nil {
return map[string]interface{}{}
}

m := map[string]interface{}{}

return m
}

func flattenVPCDerivedInfo(o *opensearchservice.VPCDerivedInfo) []map[string]interface{} {
m := map[string]interface{}{}

Expand Down