github.com/GoogleCloudPlatform/terraformer@v0.8.18/providers/aws/budgets.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 21 "github.com/GoogleCloudPlatform/terraformer/terraformutils" 22 "github.com/aws/aws-sdk-go-v2/service/budgets" 23 "github.com/aws/aws-sdk-go-v2/service/budgets/types" 24 ) 25 26 type BudgetsGenerator struct { 27 AWSService 28 } 29 30 func (g *BudgetsGenerator) createResources(budgets []types.Budget, account *string) []terraformutils.Resource { 31 var resources []terraformutils.Resource 32 for _, budget := range budgets { 33 resourceName := StringValue(budget.BudgetName) 34 resources = append(resources, terraformutils.NewSimpleResource( 35 fmt.Sprintf("%s:%s", *account, resourceName), 36 resourceName, 37 "aws_budgets_budget", 38 "aws", 39 []string{})) 40 } 41 return resources 42 } 43 44 func (g *BudgetsGenerator) InitResources() error { 45 config, e := g.generateConfig() 46 if e != nil { 47 return e 48 } 49 budgetsSvc := budgets.NewFromConfig(config) 50 51 account, err := g.getAccountNumber(config) 52 if err != nil { 53 return err 54 } 55 56 output, err := budgetsSvc.DescribeBudgets(context.TODO(), &budgets.DescribeBudgetsInput{AccountId: account}) 57 if err != nil { 58 return err 59 } 60 61 g.Resources = g.createResources(output.Budgets, account) 62 return nil 63 }