github.com/GoogleCloudPlatform/terraformer@v0.8.18/providers/azure/analysis.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 azure 16 17 import ( 18 "context" 19 "log" 20 21 "github.com/Azure/azure-sdk-for-go/services/analysisservices/mgmt/2017-08-01/analysisservices" 22 "github.com/Azure/go-autorest/autorest" 23 "github.com/GoogleCloudPlatform/terraformer/terraformutils" 24 "github.com/hashicorp/go-azure-helpers/authentication" 25 ) 26 27 type AnalysisGenerator struct { 28 AzureService 29 } 30 31 func (g *AnalysisGenerator) listServiceServers() ([]terraformutils.Resource, error) { 32 log.Println("\tImporting Service Servers") 33 var resources []terraformutils.Resource 34 ctx := context.Background() 35 AnalysisClient := analysisservices.NewServersClient(g.Args["config"].(authentication.Config).SubscriptionID) 36 AnalysisClient.Authorizer = g.Args["authorizer"].(autorest.Authorizer) 37 38 var ( 39 servers analysisservices.Servers 40 err error 41 ) 42 43 if rg := g.Args["resource_group"].(string); rg != "" { 44 servers, err = AnalysisClient.ListByResourceGroup(ctx, rg) 45 } else { 46 servers, err = AnalysisClient.List(ctx) 47 } 48 if err != nil { 49 return nil, err 50 } 51 for _, svr := range *servers.Value { 52 resources = append(resources, terraformutils.NewSimpleResource( 53 *svr.ID, 54 *svr.Name, 55 "azurerm_analysis_services_server", 56 g.ProviderName, 57 []string{})) 58 } 59 60 return resources, nil 61 } 62 63 func (g *AnalysisGenerator) InitResources() error { 64 functions := []func() ([]terraformutils.Resource, error){ 65 g.listServiceServers, 66 } 67 68 for _, f := range functions { 69 resources, err := f() 70 if err != nil { 71 return err 72 } 73 g.Resources = append(g.Resources, resources...) 74 } 75 76 return nil 77 }