github.com/GoogleCloudPlatform/terraformer@v0.8.18/providers/aws/codepipeline.go (about)

     1  // Copyright 2020 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  	"github.com/aws/aws-sdk-go-v2/service/codepipeline"
    22  )
    23  
    24  var codepipelineAllowEmptyValues = []string{"tags."}
    25  
    26  type CodePipelineGenerator struct {
    27  	AWSService
    28  }
    29  
    30  func (g *CodePipelineGenerator) loadPipelines(svc *codepipeline.Client) error {
    31  	p := codepipeline.NewListPipelinesPaginator(svc, &codepipeline.ListPipelinesInput{})
    32  	for p.HasMorePages() {
    33  		page, err := p.NextPage(context.TODO())
    34  		if err != nil {
    35  			return err
    36  		}
    37  		for _, pipeline := range page.Pipelines {
    38  			resourceName := StringValue(pipeline.Name)
    39  			g.Resources = append(g.Resources, terraformutils.NewSimpleResource(
    40  				resourceName,
    41  				resourceName,
    42  				"aws_codepipeline",
    43  				"aws",
    44  				codepipelineAllowEmptyValues))
    45  		}
    46  	}
    47  	return nil
    48  }
    49  
    50  func (g *CodePipelineGenerator) loadWebhooks(svc *codepipeline.Client) error {
    51  	p := codepipeline.NewListWebhooksPaginator(svc, &codepipeline.ListWebhooksInput{})
    52  	for p.HasMorePages() {
    53  		page, err := p.NextPage(context.TODO())
    54  		if err != nil {
    55  			return err
    56  		}
    57  		for _, webhook := range page.Webhooks {
    58  			resourceArn := StringValue(webhook.Arn)
    59  			g.Resources = append(g.Resources, terraformutils.NewSimpleResource(
    60  				resourceArn,
    61  				resourceArn,
    62  				"aws_codepipeline_webhook",
    63  				"aws",
    64  				codepipelineAllowEmptyValues))
    65  		}
    66  	}
    67  	return nil
    68  }
    69  
    70  func (g *CodePipelineGenerator) InitResources() error {
    71  	config, e := g.generateConfig()
    72  	if e != nil {
    73  		return e
    74  	}
    75  	svc := codepipeline.NewFromConfig(config)
    76  
    77  	if err := g.loadPipelines(svc); err != nil {
    78  		return err
    79  	}
    80  	if err := g.loadWebhooks(svc); err != nil {
    81  		return err
    82  	}
    83  
    84  	return nil
    85  }