github.com/GoogleCloudPlatform/terraformer@v0.8.18/providers/aws/sqs.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 "fmt" 20 "os" 21 "strings" 22 23 "github.com/GoogleCloudPlatform/terraformer/terraformutils" 24 "github.com/aws/aws-sdk-go-v2/aws" 25 26 "github.com/aws/aws-sdk-go-v2/service/sqs" 27 ) 28 29 var sqsAllowEmptyValues = []string{"tags."} 30 31 type SqsGenerator struct { 32 AWSService 33 } 34 35 func (g *SqsGenerator) InitResources() error { 36 config, e := g.generateConfig() 37 if e != nil { 38 return e 39 } 40 svc := sqs.NewFromConfig(config) 41 42 listQueuesInput := sqs.ListQueuesInput{} 43 44 sqsPrefix, hasPrefix := os.LookupEnv("SQS_PREFIX") 45 if hasPrefix { 46 listQueuesInput.QueueNamePrefix = aws.String(sqsPrefix) 47 } 48 49 queuesList, err := svc.ListQueues(context.TODO(), &listQueuesInput) 50 51 if err != nil { 52 return err 53 } 54 55 for _, queueURL := range queuesList.QueueUrls { 56 urlParts := strings.Split(queueURL, "/") 57 queueName := urlParts[len(urlParts)-1] 58 59 g.Resources = append(g.Resources, terraformutils.NewSimpleResource( 60 queueURL, 61 queueName, 62 "aws_sqs_queue", 63 "aws", 64 sqsAllowEmptyValues, 65 )) 66 } 67 68 return nil 69 } 70 71 // PostConvertHook for add policy json as heredoc 72 func (g *SqsGenerator) PostConvertHook() error { 73 for i, resource := range g.Resources { 74 if resource.InstanceInfo.Type == "aws_sqs_queue" { 75 if val, ok := g.Resources[i].Item["policy"]; ok { 76 policy := g.escapeAwsInterpolation(val.(string)) 77 g.Resources[i].Item["policy"] = fmt.Sprintf(`<<POLICY 78 %s 79 POLICY`, policy) 80 } 81 } 82 } 83 return nil 84 }