github.com/GoogleCloudPlatform/terraformer@v0.8.18/providers/aws/es.go (about) 1 // Copyright 2019 The Terraformer Authors. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package aws 16 17 import ( 18 "context" 19 20 "github.com/GoogleCloudPlatform/terraformer/terraformutils" 21 es "github.com/aws/aws-sdk-go-v2/service/elasticsearchservice" 22 ) 23 24 var esAllowEmptyValues = []string{"tags."} 25 26 type EsGenerator struct { 27 AWSService 28 } 29 30 func (g *EsGenerator) InitResources() error { 31 config, e := g.generateConfig() 32 if e != nil { 33 return e 34 } 35 svc := es.NewFromConfig(config) 36 37 domainNames, err := svc.ListDomainNames(context.TODO(), &es.ListDomainNamesInput{}) 38 if err != nil { 39 return err 40 } 41 42 for _, domainName := range domainNames.DomainNames { 43 g.Resources = append(g.Resources, terraformutils.NewResource( 44 StringValue(domainName.DomainName), 45 StringValue(domainName.DomainName), 46 "aws_elasticsearch_domain", 47 "aws", 48 map[string]string{ 49 "domain_name": StringValue(domainName.DomainName), 50 }, 51 esAllowEmptyValues, 52 map[string]interface{}{}, 53 )) 54 } 55 56 return nil 57 } 58 59 func (g *EsGenerator) PostConvertHook() error { 60 for _, r := range g.Resources { 61 if r.InstanceInfo.Type != "aws_elasticsearch_domain" { 62 continue 63 } 64 if r.InstanceState.Attributes["cognito_options.0.enabled"] == "false" { 65 delete(r.Item, "cognito_options") 66 } 67 if r.InstanceState.Attributes["cluster_config.0.warm_count"] == "0" { 68 delete(r.Item["cluster_config"].([]interface{})[0].(map[string]interface{}), "warm_count") 69 } 70 } 71 return nil 72 }