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

     1  // Copyright 2018 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  	"github.com/aws/aws-sdk-go-v2/aws"
    20  
    21  	"github.com/GoogleCloudPlatform/terraformer/terraformutils"
    22  	"github.com/aws/aws-sdk-go-v2/service/firehose"
    23  )
    24  
    25  type FirehoseGenerator struct {
    26  	AWSService
    27  }
    28  
    29  func (g *FirehoseGenerator) createResources(streamNames []string) []terraformutils.Resource {
    30  	var resources []terraformutils.Resource
    31  	for _, resourceName := range streamNames {
    32  		resources = append(resources, terraformutils.NewResource(
    33  			resourceName,
    34  			resourceName,
    35  			"aws_kinesis_firehose_delivery_stream",
    36  			"aws",
    37  			map[string]string{"name": resourceName},
    38  			[]string{".tags"},
    39  			map[string]interface{}{}))
    40  	}
    41  	return resources
    42  }
    43  
    44  // Generate TerraformResources from AWS API,
    45  // Need deliver stream name for terraform resource
    46  func (g *FirehoseGenerator) InitResources() error {
    47  	config, e := g.generateConfig()
    48  	if e != nil {
    49  		return e
    50  	}
    51  	svc := firehose.NewFromConfig(config)
    52  	var streamNames []string
    53  	var lastStreamName *string
    54  	for {
    55  		output, err := svc.ListDeliveryStreams(context.TODO(), &firehose.ListDeliveryStreamsInput{
    56  			ExclusiveStartDeliveryStreamName: lastStreamName,
    57  			Limit:                            aws.Int32(100),
    58  		})
    59  		if err != nil {
    60  			return err
    61  		}
    62  		streamNames = append(streamNames, output.DeliveryStreamNames...)
    63  		if !*output.HasMoreDeliveryStreams {
    64  			break
    65  		}
    66  
    67  		lastStreamName = aws.String(streamNames[len(streamNames)-1])
    68  	}
    69  
    70  	g.Resources = g.createResources(streamNames)
    71  
    72  	return nil
    73  }
    74  
    75  func (g *FirehoseGenerator) PostConvertHook() error {
    76  	for _, resource := range g.Resources {
    77  		_, hasExtendedS3Configuration := resource.Item["extended_s3_configuration"]
    78  		_, hasS3Configuration := resource.Item["s3_configuration"]
    79  		if hasExtendedS3Configuration && hasS3Configuration {
    80  			delete(resource.Item, "s3_configuration")
    81  		}
    82  	}
    83  	return nil
    84  }