github.com/GoogleCloudPlatform/terraformer@v0.8.18/providers/aws/elastic_beanstalk.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 22 "github.com/aws/aws-sdk-go-v2/service/elasticbeanstalk" 23 ) 24 25 var beanstalkAllowEmptyValues = []string{"tags."} 26 27 type BeanstalkGenerator struct { 28 AWSService 29 } 30 31 func (g *BeanstalkGenerator) InitResources() error { 32 config, e := g.generateConfig() 33 if e != nil { 34 return e 35 } 36 client := elasticbeanstalk.NewFromConfig(config) 37 38 err := g.addApplications(client) 39 if err != nil { 40 return err 41 } 42 err = g.addEnvironments(client) 43 return err 44 } 45 46 func (g *BeanstalkGenerator) addApplications(client *elasticbeanstalk.Client) error { 47 response, err := client.DescribeApplications(context.TODO(), &elasticbeanstalk.DescribeApplicationsInput{}) 48 if err != nil { 49 return err 50 } 51 for _, application := range response.Applications { 52 g.Resources = append(g.Resources, terraformutils.NewSimpleResource( 53 *application.ApplicationName, 54 *application.ApplicationName, 55 "aws_elastic_beanstalk_application", 56 "aws", 57 beanstalkAllowEmptyValues, 58 )) 59 } 60 return nil 61 } 62 63 func (g *BeanstalkGenerator) addEnvironments(client *elasticbeanstalk.Client) error { 64 response, err := client.DescribeEnvironments(context.TODO(), &elasticbeanstalk.DescribeEnvironmentsInput{}) 65 if err != nil { 66 return err 67 } 68 for _, environment := range response.Environments { 69 g.Resources = append(g.Resources, terraformutils.NewSimpleResource( 70 *environment.EnvironmentId, 71 *environment.EnvironmentName, 72 "aws_elastic_beanstalk_environment", 73 "aws", 74 beanstalkAllowEmptyValues, 75 )) 76 } 77 return nil 78 }