Skip to content

Commit

Permalink
Merge pull request #33925 from mikekinlock/f-elasticsearch-adding-vpc…
Browse files Browse the repository at this point in the history
…-endpoint

Elasticsearch adding vpc endpoint resource
  • Loading branch information
ewbankkit authored Oct 16, 2023
2 parents 3168fff + c56e224 commit b4947bb
Show file tree
Hide file tree
Showing 9 changed files with 783 additions and 8 deletions.
4 changes: 4 additions & 0 deletions .changelog/33925.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

```release-note:new-resource
aws_elasticsearch_vpc_endpoint
```
2 changes: 1 addition & 1 deletion internal/service/elasticsearch/domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -807,7 +807,7 @@ func resourceDomainRead(ctx context.Context, d *schema.ResourceData, meta interf
}

if ds.VPCOptions != nil {
if err := d.Set("vpc_options", flattenVPCDerivedInfo(ds.VPCOptions)); err != nil {
if err := d.Set("vpc_options", []interface{}{flattenVPCDerivedInfo(ds.VPCOptions)}); err != nil {
return sdkdiag.AppendErrorf(diags, "setting vpc_options: %s", err)
}

Expand Down
2 changes: 1 addition & 1 deletion internal/service/elasticsearch/domain_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ func dataSourceDomainRead(ctx context.Context, d *schema.ResourceData, meta inte
}

if ds.VPCOptions != nil {
if err := d.Set("vpc_options", flattenVPCDerivedInfo(ds.VPCOptions)); err != nil {
if err := d.Set("vpc_options", []interface{}{flattenVPCDerivedInfo(ds.VPCOptions)}); err != nil {
return sdkdiag.AppendErrorf(diags, "setting vpc_options: %s", err)
}

Expand Down
9 changes: 9 additions & 0 deletions internal/service/elasticsearch/exports_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
package elasticsearch

// Exports for use in tests only.
var (
FindVPCEndpointByID = findVPCEndpointByID
VPCEndpointsError = vpcEndpointsError
)
20 changes: 14 additions & 6 deletions internal/service/elasticsearch/flex.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,17 @@ func expandEncryptAtRestOptions(m map[string]interface{}) *elasticsearch.Encrypt
}

func expandVPCOptions(m map[string]interface{}) *elasticsearch.VPCOptions {
if m == nil {
return nil
}

options := elasticsearch.VPCOptions{}

if v, ok := m["security_group_ids"]; ok {
options.SecurityGroupIds = flex.ExpandStringSet(v.(*schema.Set))
if v, ok := m["security_group_ids"].(*schema.Set); ok && v.Len() > 0 {
options.SecurityGroupIds = flex.ExpandStringSet(v)
}
if v, ok := m["subnet_ids"]; ok {
options.SubnetIds = flex.ExpandStringSet(v.(*schema.Set))
if v, ok := m["subnet_ids"].(*schema.Set); ok && v.Len() > 0 {
options.SubnetIds = flex.ExpandStringSet(v)
}

return &options
Expand Down Expand Up @@ -215,7 +219,11 @@ func flattenSnapshotOptions(snapshotOptions *elasticsearch.SnapshotOptions) []ma
return []map[string]interface{}{m}
}

func flattenVPCDerivedInfo(o *elasticsearch.VPCDerivedInfo) []map[string]interface{} {
func flattenVPCDerivedInfo(o *elasticsearch.VPCDerivedInfo) map[string]interface{} {
if o == nil {
return nil
}

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

if o.AvailabilityZones != nil {
Expand All @@ -231,5 +239,5 @@ func flattenVPCDerivedInfo(o *elasticsearch.VPCDerivedInfo) []map[string]interfa
m["vpc_id"] = aws.StringValue(o.VPCId)
}

return []map[string]interface{}{m}
return m
}
4 changes: 4 additions & 0 deletions internal/service/elasticsearch/service_package_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit b4947bb

Please sign in to comment.