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