github.com/GoogleCloudPlatform/terraformer@v0.8.18/providers/azure/app_service.go (about) 1 package azure 2 3 import ( 4 "context" 5 "log" 6 7 "github.com/Azure/go-autorest/autorest" 8 "github.com/hashicorp/go-azure-helpers/authentication" 9 10 "github.com/Azure/azure-sdk-for-go/services/web/mgmt/2019-08-01/web" 11 "github.com/GoogleCloudPlatform/terraformer/terraformutils" 12 ) 13 14 type AppServiceGenerator struct { 15 AzureService 16 } 17 18 func (g AppServiceGenerator) listApps() ([]terraformutils.Resource, error) { 19 var resources []terraformutils.Resource 20 ctx := context.Background() 21 22 appServiceClient := web.NewAppsClient(g.Args["config"].(authentication.Config).SubscriptionID) 23 appServiceClient.Authorizer = g.Args["authorizer"].(autorest.Authorizer) 24 var ( 25 appsIterator web.AppCollectionIterator 26 err error 27 ) 28 if rg := g.Args["resource_group"].(string); rg != "" { 29 appsIterator, err = appServiceClient.ListByResourceGroupComplete(ctx, rg, nil) 30 } else { 31 appsIterator, err = appServiceClient.ListComplete(ctx) 32 } 33 if err != nil { 34 return nil, err 35 } 36 for appsIterator.NotDone() { 37 site := appsIterator.Value() 38 resources = append(resources, terraformutils.NewSimpleResource( 39 *site.ID, 40 *site.Name, 41 "azurerm_app_service", 42 g.ProviderName, 43 []string{})) 44 45 if err := appsIterator.NextWithContext(ctx); err != nil { 46 log.Println(err) 47 return resources, err 48 } 49 } 50 51 return resources, nil 52 } 53 54 func (g *AppServiceGenerator) InitResources() error { 55 resources, err := g.listApps() 56 if err != nil { 57 return err 58 } 59 60 g.Resources = append(g.Resources, resources...) 61 62 return nil 63 }