github.com/GoogleCloudPlatform/terraformer@v0.8.18/providers/azure/purview.go (about) 1 // Copyright 2021 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/purview/mgmt/2021-07-01/purview" 22 ) 23 24 type PurviewGenerator struct { 25 AzureService 26 } 27 28 func (az *PurviewGenerator) listAccounts() ([]purview.Account, error) { 29 subscriptionID, resourceGroup, authorizer := az.getClientArgs() 30 client := purview.NewAccountsClient(subscriptionID) 31 client.Authorizer = authorizer 32 var ( 33 iterator purview.AccountListIterator 34 err error 35 ) 36 ctx := context.Background() 37 if resourceGroup != "" { 38 iterator, err = client.ListByResourceGroupComplete(ctx, resourceGroup, "") 39 } else { 40 iterator, err = client.ListBySubscriptionComplete(ctx, "") 41 } 42 if err != nil { 43 return nil, err 44 } 45 var resources []purview.Account 46 for iterator.NotDone() { 47 item := iterator.Value() 48 resources = append(resources, item) 49 if err := iterator.NextWithContext(ctx); err != nil { 50 log.Println(err) 51 return resources, err 52 } 53 } 54 return resources, nil 55 } 56 57 func (az *PurviewGenerator) AppendAccount(account *purview.Account) { 58 az.AppendSimpleResource(*account.ID, *account.Name, "azurerm_purview_account") 59 } 60 61 func (az *PurviewGenerator) InitResources() error { 62 63 accounts, err := az.listAccounts() 64 if err != nil { 65 return err 66 } 67 for _, account := range accounts { 68 az.AppendAccount(&account) 69 } 70 return nil 71 }