github.com/GoogleCloudPlatform/terraformer@v0.8.18/providers/azure/azure_service.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  	"strings"
    19  
    20  	"github.com/Azure/go-autorest/autorest"
    21  	"github.com/hashicorp/go-azure-helpers/authentication"
    22  
    23  	"github.com/GoogleCloudPlatform/terraformer/terraformutils"
    24  )
    25  
    26  type AzureService struct { //nolint
    27  	terraformutils.Service
    28  }
    29  
    30  func (az *AzureService) getClientArgs() (subscriptionID string, resourceGroup string, authorizer autorest.Authorizer) {
    31  	subs := az.Args["config"].(authentication.Config).SubscriptionID
    32  	auth := az.Args["authorizer"].(autorest.Authorizer)
    33  	resg := az.Args["resource_group"].(string)
    34  	return subs, resg, auth
    35  }
    36  
    37  func (az *AzureService) AppendSimpleResource(id string, resourceName string, resourceType string) {
    38  	newResource := terraformutils.NewSimpleResource(id, resourceName, resourceType, az.ProviderName, []string{})
    39  	az.Resources = append(az.Resources, newResource)
    40  }
    41  
    42  func (az *AzureService) appendSimpleAssociation(id string, linkedResourceName string, resourceName *string, resourceType string, attributes map[string]string) {
    43  	var resourceName2 string
    44  	if resourceName != nil {
    45  		resourceName2 = *resourceName
    46  	} else {
    47  		resourceName0 := strings.ReplaceAll(resourceType, "azurerm_", "")
    48  		resourceName1 := resourceName0[strings.IndexByte(resourceName0, '_'):]
    49  		resourceName2 = linkedResourceName + resourceName1
    50  	}
    51  	newResource := terraformutils.NewResource(
    52  		id, resourceName2, resourceType, az.ProviderName, attributes,
    53  		[]string{"name"},
    54  		map[string]interface{}{},
    55  	)
    56  	az.Resources = append(az.Resources, newResource)
    57  }