github.com/GoogleCloudPlatform/terraformer@v0.8.18/providers/azure/network_interface.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/network/mgmt/2019-08-01/network" 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 NetworkInterfaceGenerator struct { 28 AzureService 29 } 30 31 func (g NetworkInterfaceGenerator) createResources(interfaceListResult network.InterfaceListResultIterator) ([]terraformutils.Resource, error) { 32 var resources []terraformutils.Resource 33 for interfaceListResult.NotDone() { 34 networkInterface := interfaceListResult.Value() 35 resources = append(resources, terraformutils.NewSimpleResource( 36 *networkInterface.ID, 37 *networkInterface.Name, 38 "azurerm_network_interface", 39 "azurerm", 40 []string{})) 41 if err := interfaceListResult.Next(); err != nil { 42 log.Println(err) 43 return resources, err 44 } 45 } 46 return resources, nil 47 } 48 49 func (g *NetworkInterfaceGenerator) InitResources() error { 50 ctx := context.Background() 51 interfacesClient := network.NewInterfacesClient(g.Args["config"].(authentication.Config).SubscriptionID) 52 53 interfacesClient.Authorizer = g.Args["authorizer"].(autorest.Authorizer) 54 var ( 55 output network.InterfaceListResultIterator 56 err error 57 ) 58 if rg := g.Args["resource_group"].(string); rg != "" { 59 output, err = interfacesClient.ListComplete(ctx, rg) 60 } else { 61 output, err = interfacesClient.ListAllComplete(ctx) 62 } 63 if err != nil { 64 return err 65 } 66 g.Resources, err = g.createResources(output) 67 return err 68 }