github.com/GoogleCloudPlatform/terraformer@v0.8.18/providers/aws/kinesis.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 20 "github.com/GoogleCloudPlatform/terraformer/terraformutils" 21 "github.com/aws/aws-sdk-go-v2/service/kinesis" 22 ) 23 24 var kinesisAllowEmptyValues = []string{"tags."} 25 26 type KinesisGenerator struct { 27 AWSService 28 } 29 30 func (g *KinesisGenerator) createResources(streamNames []string) []terraformutils.Resource { 31 var resources []terraformutils.Resource 32 for _, resourceName := range streamNames { 33 resources = append(resources, terraformutils.NewResource( 34 resourceName, 35 resourceName, 36 "aws_kinesis_stream", 37 "aws", 38 map[string]string{"name": resourceName}, 39 kinesisAllowEmptyValues, 40 map[string]interface{}{})) 41 } 42 return resources 43 } 44 45 func (g *KinesisGenerator) InitResources() error { 46 config, e := g.generateConfig() 47 if e != nil { 48 return e 49 } 50 svc := kinesis.NewFromConfig(config) 51 52 var results *kinesis.ListStreamsOutput 53 var request = kinesis.ListStreamsInput{} 54 var err error 55 56 for results == nil || *results.HasMoreStreams { 57 results, err = svc.ListStreams(context.TODO(), &request) 58 if err != nil { 59 return err 60 } 61 62 g.Resources = append(g.Resources, g.createResources(results.StreamNames)...) 63 64 if len(results.StreamNames) > 0 { 65 request = kinesis.ListStreamsInput{ 66 ExclusiveStartStreamName: &results.StreamNames[len(results.StreamNames)-1], 67 } 68 } 69 } 70 return nil 71 }