github.com/GoogleCloudPlatform/terraformer@v0.8.18/providers/azure/redis.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 azure 16 17 import ( 18 "context" 19 "log" 20 21 "github.com/Azure/azure-sdk-for-go/services/redis/mgmt/2018-03-01/redis" 22 "github.com/GoogleCloudPlatform/terraformer/terraformutils" 23 "github.com/hashicorp/go-azure-helpers/authentication" 24 ) 25 26 type RedisGenerator struct { 27 AzureService 28 } 29 30 func (g *RedisGenerator) listRedisServers() ([]terraformutils.Resource, error) { 31 var resources []terraformutils.Resource 32 ctx := context.Background() 33 subscriptionID := g.Args["config"].(authentication.Config).SubscriptionID 34 RedisClient := redis.NewClient(subscriptionID) 35 36 redisServersIterator, err := RedisClient.ListComplete(ctx) 37 if err != nil { 38 return nil, err 39 } 40 41 for redisServersIterator.NotDone() { 42 redisServer := redisServersIterator.Value() 43 resources = append(resources, terraformutils.NewSimpleResource( 44 *redisServer.ID, 45 *redisServer.Name, 46 "azurerm_redis_cache", 47 g.ProviderName, 48 []string{})) 49 50 if err := redisServersIterator.Next(); err != nil { 51 log.Println(err) 52 break 53 } 54 } 55 56 return resources, nil 57 } 58 59 func (g *RedisGenerator) InitResources() error { 60 functions := []func() ([]terraformutils.Resource, error){ 61 g.listRedisServers, 62 } 63 64 for _, f := range functions { 65 resources, err := f() 66 if err != nil { 67 return err 68 } 69 g.Resources = append(g.Resources, resources...) 70 } 71 72 return nil 73 }