Skip to content

Commit

Permalink
GoogleCloudPlatform#549 refactored another batch of services
Browse files Browse the repository at this point in the history
  • Loading branch information
meshuga committed Feb 21, 2021
1 parent 91b7453 commit d1a60f1
Show file tree
Hide file tree
Showing 30 changed files with 484 additions and 345 deletions.
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ github.com/aws/aws-sdk-go v1.15.78/go.mod h1:E3/ieXAlvM0XWO57iftYVDLLvQ824smPP3A
github.com/aws/aws-sdk-go v1.19.39/go.mod h1:KmX6BPdI08NWTb3/sm4ZGu5ShLoqVDhKgpiN924inxo=
github.com/aws/aws-sdk-go v1.25.3/go.mod h1:KmX6BPdI08NWTb3/sm4ZGu5ShLoqVDhKgpiN924inxo=
github.com/aws/aws-sdk-go v1.30.12/go.mod h1:5zCpMtNQVjRREroY7sYe8lOMRSxkhG6MZveU8YkpAk0=
github.com/aws/aws-sdk-go v1.34.28 h1:sscPpn/Ns3i0F4HPEWAVcwdIRaZZCuL7llJ2/60yPIk=
github.com/aws/aws-sdk-go v1.34.28/go.mod h1:H7NKnBqNVzoTJpGfLrQkkD+ytBA93eiDYi/+8rV9s48=
github.com/aws/aws-sdk-go v1.36.19 h1:zbJZKkxeDiYxUYFjymjWxPye+qa1G2gRVyhIzZrB9zA=
github.com/aws/aws-sdk-go v1.36.19/go.mod h1:hcU610XS61/+aQV88ixoOzUoG7v3b31pl2zKMmprdro=
Expand Down
20 changes: 10 additions & 10 deletions providers/aws/cloudwatch.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func (g *CloudWatchGenerator) InitResources() error {
return e
}

cloudwatchSvc := cloudwatch.New(config)
cloudwatchSvc := cloudwatch.NewFromConfig(config)
err := g.createMetricAlarms(cloudwatchSvc)
if err != nil {
return err
Expand All @@ -44,7 +44,7 @@ func (g *CloudWatchGenerator) InitResources() error {
return err
}

cloudwatcheventsSvc := cloudwatchevents.New(config)
cloudwatcheventsSvc := cloudwatchevents.NewFromConfig(config)
err = g.createRules(cloudwatcheventsSvc)
if err != nil {
return err
Expand All @@ -56,9 +56,9 @@ func (g *CloudWatchGenerator) InitResources() error {
func (g *CloudWatchGenerator) createMetricAlarms(cloudwatchSvc *cloudwatch.Client) error {
var nextToken *string
for {
output, err := cloudwatchSvc.DescribeAlarmsRequest(&cloudwatch.DescribeAlarmsInput{
output, err := cloudwatchSvc.DescribeAlarms(context.TODO(), &cloudwatch.DescribeAlarmsInput{
NextToken: nextToken,
}).Send(context.Background())
})
if err != nil {
return err
}
Expand All @@ -81,9 +81,9 @@ func (g *CloudWatchGenerator) createMetricAlarms(cloudwatchSvc *cloudwatch.Clien
func (g *CloudWatchGenerator) createDashboards(cloudwatchSvc *cloudwatch.Client) error {
var nextToken *string
for {
output, err := cloudwatchSvc.ListDashboardsRequest(&cloudwatch.ListDashboardsInput{
output, err := cloudwatchSvc.ListDashboards(context.TODO(), &cloudwatch.ListDashboardsInput{
NextToken: nextToken,
}).Send(context.Background())
})
if err != nil {
return err
}
Expand All @@ -106,9 +106,9 @@ func (g *CloudWatchGenerator) createDashboards(cloudwatchSvc *cloudwatch.Client)
func (g *CloudWatchGenerator) createRules(cloudwatcheventsSvc *cloudwatchevents.Client) error {
var listRulesNextToken *string
for {
output, err := cloudwatcheventsSvc.ListRulesRequest(&cloudwatchevents.ListRulesInput{
output, err := cloudwatcheventsSvc.ListRules(context.TODO(), &cloudwatchevents.ListRulesInput{
NextToken: listRulesNextToken,
}).Send(context.Background())
})
if err != nil {
return err
}
Expand All @@ -122,10 +122,10 @@ func (g *CloudWatchGenerator) createRules(cloudwatcheventsSvc *cloudwatchevents.

var listTargetsNextToken *string
for {
targetResponse, err := cloudwatcheventsSvc.ListTargetsByRuleRequest(&cloudwatchevents.ListTargetsByRuleInput{
targetResponse, err := cloudwatcheventsSvc.ListTargetsByRule(context.TODO(), &cloudwatchevents.ListTargetsByRuleInput{
Rule: rule.Name,
NextToken: listTargetsNextToken,
}).Send(context.Background())
})
if err != nil {
return err
}
Expand Down
13 changes: 8 additions & 5 deletions providers/aws/codebuild.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,14 @@ func (g *CodeBuildGenerator) InitResources() error {
if e != nil {
return e
}
svc := codebuild.New(config)
output, err := svc.ListProjectsRequest(&codebuild.ListProjectsInput{}).Send(context.Background())
if err != nil {
return err
svc := codebuild.NewFromConfig(config)
p := codebuild.NewListProjectsPaginator(svc, &codebuild.ListProjectsInput{})
for p.HasMorePages() {
page, e := p.NextPage(context.TODO())
if e != nil {
return e
}
g.Resources = g.createResources(page.Projects)
}
g.Resources = g.createResources(output.Projects)
return nil
}
17 changes: 10 additions & 7 deletions providers/aws/codecommit.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"context"

"github.com/GoogleCloudPlatform/terraformer/terraformutils"
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/service/codecommit"
)

Expand All @@ -33,12 +32,16 @@ func (g *CodeCommitGenerator) InitResources() error {
if e != nil {
return e
}
svc := codecommit.New(config)
p := codecommit.NewListRepositoriesPaginator(svc.ListRepositoriesRequest(&codecommit.ListRepositoriesInput{}))
svc := codecommit.NewFromConfig(config)
p := codecommit.NewListRepositoriesPaginator(svc, &codecommit.ListRepositoriesInput{})
var resources []terraformutils.Resource
for p.Next(context.Background()) {
for _, repository := range p.CurrentPage().Repositories {
resourceName := aws.StringValue(repository.RepositoryName)
for p.HasMorePages() {
page, e := p.NextPage(context.TODO())
if e != nil {
return e
}
for _, repository := range page.Repositories {
resourceName := StringValue(repository.RepositoryName)
resources = append(resources, terraformutils.NewSimpleResource(
resourceName,
resourceName,
Expand All @@ -48,5 +51,5 @@ func (g *CodeCommitGenerator) InitResources() error {
}
}
g.Resources = resources
return p.Err()
return nil
}
14 changes: 9 additions & 5 deletions providers/aws/codedeploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,15 @@ func (g *CodeDeployGenerator) InitResources() error {
if e != nil {
return e
}
svc := codedeploy.New(config)
p := codedeploy.NewListApplicationsPaginator(svc.ListApplicationsRequest(&codedeploy.ListApplicationsInput{}))
svc := codedeploy.NewFromConfig(config)
p := codedeploy.NewListApplicationsPaginator(svc, &codedeploy.ListApplicationsInput{})
var resources []terraformutils.Resource
for p.Next(context.Background()) {
for _, application := range p.CurrentPage().Applications {
for p.HasMorePages() {
page, e := p.NextPage(context.TODO())
if e != nil {
return e
}
for _, application := range page.Applications {
resources = append(resources, terraformutils.NewSimpleResource(
fmt.Sprintf(":%s", application),
application,
Expand All @@ -47,5 +51,5 @@ func (g *CodeDeployGenerator) InitResources() error {
}
}
g.Resources = resources
return p.Err()
return nil
}
31 changes: 19 additions & 12 deletions providers/aws/codepipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"context"

"github.com/GoogleCloudPlatform/terraformer/terraformutils"
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/service/codepipeline"
)

Expand All @@ -29,10 +28,14 @@ type CodePipelineGenerator struct {
}

func (g *CodePipelineGenerator) loadPipelines(svc *codepipeline.Client) error {
p := codepipeline.NewListPipelinesPaginator(svc.ListPipelinesRequest(&codepipeline.ListPipelinesInput{}))
for p.Next(context.Background()) {
for _, pipeline := range p.CurrentPage().Pipelines {
resourceName := aws.StringValue(pipeline.Name)
p := codepipeline.NewListPipelinesPaginator(svc, &codepipeline.ListPipelinesInput{})
for p.HasMorePages() {
page, err := p.NextPage(context.TODO())
if err != nil {
return err
}
for _, pipeline := range page.Pipelines {
resourceName := StringValue(pipeline.Name)
g.Resources = append(g.Resources, terraformutils.NewSimpleResource(
resourceName,
resourceName,
Expand All @@ -41,14 +44,18 @@ func (g *CodePipelineGenerator) loadPipelines(svc *codepipeline.Client) error {
codepipelineAllowEmptyValues))
}
}
return p.Err()
return nil
}

func (g *CodePipelineGenerator) loadWebhooks(svc *codepipeline.Client) error {
p := codepipeline.NewListWebhooksPaginator(svc.ListWebhooksRequest(&codepipeline.ListWebhooksInput{}))
for p.Next(context.Background()) {
for _, webhook := range p.CurrentPage().Webhooks {
resourceArn := aws.StringValue(webhook.Arn)
p := codepipeline.NewListWebhooksPaginator(svc, &codepipeline.ListWebhooksInput{})
for p.HasMorePages() {
page, err := p.NextPage(context.TODO())
if err != nil {
return err
}
for _, webhook := range page.Webhooks {
resourceArn := StringValue(webhook.Arn)
g.Resources = append(g.Resources, terraformutils.NewSimpleResource(
resourceArn,
resourceArn,
Expand All @@ -57,15 +64,15 @@ func (g *CodePipelineGenerator) loadWebhooks(svc *codepipeline.Client) error {
codepipelineAllowEmptyValues))
}
}
return p.Err()
return nil
}

func (g *CodePipelineGenerator) InitResources() error {
config, e := g.generateConfig()
if e != nil {
return e
}
svc := codepipeline.New(config)
svc := codepipeline.NewFromConfig(config)

if err := g.loadPipelines(svc); err != nil {
return err
Expand Down
39 changes: 16 additions & 23 deletions providers/aws/cognito.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,15 @@ type CognitoGenerator struct {
const CognitoMaxResults = 60 // Required field for Cognito API

func (g *CognitoGenerator) loadIdentityPools(svc *cognitoidentity.Client) error {
var nextToken *string
for {
pools, err := svc.ListIdentityPoolsRequest(&cognitoidentity.ListIdentityPoolsInput{
NextToken: nextToken,
MaxResults: aws.Int64(CognitoMaxResults),
}).Send(context.Background())
p := cognitoidentity.NewListIdentityPoolsPaginator(svc, &cognitoidentity.ListIdentityPoolsInput{
MaxResults: *aws.Int32(CognitoMaxResults),
})
for p.HasMorePages() {
page, err := p.NextPage(context.TODO())
if err != nil {
return err
}

for _, pool := range pools.IdentityPools {
for _, pool := range page.IdentityPools {
var id = *pool.IdentityPoolId
var resourceName = *pool.IdentityPoolName
g.Resources = append(g.Resources, terraformutils.NewSimpleResource(
Expand All @@ -36,22 +34,21 @@ func (g *CognitoGenerator) loadIdentityPools(svc *cognitoidentity.Client) error
"aws",
[]string{}))
}

nextToken = pools.NextToken
if nextToken == nil {
break
}
}

return nil
}

func (g *CognitoGenerator) loadUserPools(svc *cognitoidentityprovider.Client) error {
req := svc.ListUserPoolsRequest(&cognitoidentityprovider.ListUserPoolsInput{MaxResults: aws.Int64(CognitoMaxResults)})
p := cognitoidentityprovider.NewListUserPoolsPaginator(req)
p := cognitoidentityprovider.NewListUserPoolsPaginator(svc, &cognitoidentityprovider.ListUserPoolsInput{
MaxResults: *aws.Int32(CognitoMaxResults),
})

for p.Next(context.Background()) {
page := p.CurrentPage()
for p.HasMorePages() {
page, err := p.NextPage(context.TODO())
if err != nil {
return err
}
for _, pool := range page.UserPools {
id := *pool.Id
resourceName := *pool.Name
Expand All @@ -63,10 +60,6 @@ func (g *CognitoGenerator) loadUserPools(svc *cognitoidentityprovider.Client) er
[]string{}))
}
}

if err := p.Err(); err != nil {
return err
}
return nil
}

Expand All @@ -76,11 +69,11 @@ func (g *CognitoGenerator) InitResources() error {
return e
}

svcCognitoIdentity := cognitoidentity.New(config)
svcCognitoIdentity := cognitoidentity.NewFromConfig(config)
if err := g.loadIdentityPools(svcCognitoIdentity); err != nil {
return err
}
svcCognitoIdentityProvider := cognitoidentityprovider.New(config)
svcCognitoIdentityProvider := cognitoidentityprovider.NewFromConfig(config)
if err := g.loadUserPools(svcCognitoIdentityProvider); err != nil {
return err
}
Expand Down
15 changes: 8 additions & 7 deletions providers/aws/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func (g *ConfigGenerator) InitResources() error {
if e != nil {
return e
}
client := configservice.New(config)
client := configservice.NewFromConfig(config)

configurationRecorderRefs, err := g.addConfigurationRecorders(client)
if err != nil {
Expand All @@ -47,8 +47,8 @@ func (g *ConfigGenerator) InitResources() error {
}

func (g *ConfigGenerator) addConfigurationRecorders(svc *configservice.Client) ([]string, error) {
configurationRecorders, err := svc.DescribeConfigurationRecordersRequest(
&configservice.DescribeConfigurationRecordersInput{}).Send(context.Background())
configurationRecorders, err := svc.DescribeConfigurationRecorders(context.TODO(),
&configservice.DescribeConfigurationRecordersInput{})

if err != nil {
return nil, err
Expand All @@ -73,10 +73,11 @@ func (g *ConfigGenerator) addConfigRules(svc *configservice.Client, configuratio
var nextToken *string

for {
configRules, err := svc.DescribeConfigRulesRequest(
configRules, err := svc.DescribeConfigRules(
context.TODO(),
&configservice.DescribeConfigRulesInput{
NextToken: nextToken,
}).Send(context.Background())
})

if err != nil {
return err
Expand Down Expand Up @@ -104,8 +105,8 @@ func (g *ConfigGenerator) addConfigRules(svc *configservice.Client, configuratio
}

func (g *ConfigGenerator) addDeliveryChannels(svc *configservice.Client, configurationRecorderRefs []string) error {
deliveryChannels, err := svc.DescribeDeliveryChannelsRequest(
&configservice.DescribeDeliveryChannelsInput{}).Send(context.Background())
deliveryChannels, err := svc.DescribeDeliveryChannels(context.TODO(),
&configservice.DescribeDeliveryChannelsInput{})

if err != nil {
return err
Expand Down
11 changes: 5 additions & 6 deletions providers/aws/customer_gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (

"github.com/GoogleCloudPlatform/terraformer/terraformutils"

"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/service/ec2"
)

Expand All @@ -29,12 +28,12 @@ type CustomerGatewayGenerator struct {
AWSService
}

func (CustomerGatewayGenerator) createResources(cgws *ec2.DescribeCustomerGatewaysResponse) []terraformutils.Resource {
func (CustomerGatewayGenerator) createResources(cgws *ec2.DescribeCustomerGatewaysOutput) []terraformutils.Resource {
resources := []terraformutils.Resource{}
for _, cgws := range cgws.CustomerGateways {
resources = append(resources, terraformutils.NewSimpleResource(
aws.StringValue(cgws.CustomerGatewayId),
aws.StringValue(cgws.CustomerGatewayId),
StringValue(cgws.CustomerGatewayId),
StringValue(cgws.CustomerGatewayId),
"aws_customer_gateway",
"aws",
customerGatewayAllowEmptyValues,
Expand All @@ -51,8 +50,8 @@ func (g *CustomerGatewayGenerator) InitResources() error {
if e != nil {
return e
}
svc := ec2.New(config)
cgws, err := svc.DescribeCustomerGatewaysRequest(&ec2.DescribeCustomerGatewaysInput{}).Send(context.Background())
svc := ec2.NewFromConfig(config)
cgws, err := svc.DescribeCustomerGateways(context.TODO(), &ec2.DescribeCustomerGatewaysInput{})
if err != nil {
return err
}
Expand Down
Loading

0 comments on commit d1a60f1

Please sign in to comment.