Skip to content

Commit

Permalink
Merge pull request GoogleCloudPlatform#142 from okazu-dm/add_aws_impo…
Browse files Browse the repository at this point in the history
…rt_firehose

aws: support firehose
  • Loading branch information
sergeylanzman authored Jul 20, 2019
2 parents abca7f9 + 8a51713 commit a592301
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,8 @@ List of supported AWS services:
* `aws_cloudfront_distribution`
* `ec2_instance`
* `aws_instance`
* `firehose`
* `aws_kinesis_firehose_delivery_stream`

### Use with OpenStack

Expand Down
1 change: 1 addition & 0 deletions providers/aws/aws_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,5 +131,6 @@ func (p *AWSProvider) GetSupportedService() map[string]terraform_utils.ServiceGe
"acm": &ACMGenerator{},
"cloudfront": &CloudFrontGenerator{},
"ec2_instance": &Ec2Generator{},
"firehose": &FirehoseGenerator{},
}
}
66 changes: 66 additions & 0 deletions providers/aws/firehose.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
// Copyright 2018 The Terraformer Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package aws

import (
"github.com/GoogleCloudPlatform/terraformer/terraform_utils"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/firehose"
)

type FirehoseGenerator struct {
AWSService
}

func (g FirehoseGenerator) createResources(sess *session.Session, streamNames []*string) []terraform_utils.Resource {
var resources []terraform_utils.Resource
for _, streamName := range streamNames {
resourceName := aws.StringValue(streamName)

resources = append(resources, terraform_utils.NewResource(
resourceName,
resourceName,
"aws_kinesis_firehose_delivery_stream",
"aws",
map[string]string{"name": resourceName},
[]string{".tags"},
map[string]string{}))
}
return resources
}

// Generate TerraformResources from AWS API,
// Need deliver stream name for terraform resource
func (g *FirehoseGenerator) InitResources() error {
sess := g.generateSession()
svc := firehose.New(sess)
var streamNames []*string
for {
output, err := svc.ListDeliveryStreams(&firehose.ListDeliveryStreamsInput{})
if err != nil {
return err
}
streamNames = append(streamNames, output.DeliveryStreamNames...)
if *output.HasMoreDeliveryStreams == false {
break
}
}

g.Resources = g.createResources(sess, streamNames)

g.PopulateIgnoreKeys()
return nil
}

0 comments on commit a592301

Please sign in to comment.