github.com/mponton/terratest@v0.44.0/modules/azure/common.go (about) 1 package azure 2 3 import ( 4 "os" 5 ) 6 7 const ( 8 // AzureSubscriptionID is an optional env variable supported by the `azurerm` Terraform provider to 9 // designate a target Azure subscription ID 10 AzureSubscriptionID = "ARM_SUBSCRIPTION_ID" 11 12 // AzureResGroupName is an optional env variable custom to Terratest to designate a target Azure resource group 13 AzureResGroupName = "AZURE_RES_GROUP_NAME" 14 ) 15 16 // GetTargetAzureSubscription is a helper function to find the correct target Azure Subscription ID, 17 // with provided arguments taking precedence over environment variables 18 func GetTargetAzureSubscription(subscriptionID string) (string, error) { 19 return getTargetAzureSubscription(subscriptionID) 20 } 21 22 func getTargetAzureSubscription(subscriptionID string) (string, error) { 23 if subscriptionID == "" { 24 if id, exists := os.LookupEnv(AzureSubscriptionID); exists { 25 return id, nil 26 } 27 28 return "", SubscriptionIDNotFound{} 29 } 30 31 return subscriptionID, nil 32 } 33 34 // GetTargetAzureResourceGroupName is a helper function to find the correct target Azure Resource Group name, 35 // with provided arguments taking precedence over environment variables 36 func GetTargetAzureResourceGroupName(resourceGroupName string) (string, error) { 37 return getTargetAzureResourceGroupName(resourceGroupName) 38 } 39 40 func getTargetAzureResourceGroupName(resourceGroupName string) (string, error) { 41 if resourceGroupName == "" { 42 if name, exists := os.LookupEnv(AzureResGroupName); exists { 43 return name, nil 44 } 45 46 return "", ResourceGroupNameNotFound{} 47 } 48 49 return resourceGroupName, nil 50 } 51 52 // safePtrToString converts a string pointer to a non-pointer string value, or to "" if the pointer is nil. 53 func safePtrToString(raw *string) string { 54 if raw == nil { 55 return "" 56 } 57 return *raw 58 } 59 60 // safePtrToInt32 converts a int32 pointer to a non-pointer int32 value, or to 0 if the pointer is nil. 61 func safePtrToInt32(raw *int32) int32 { 62 if raw == nil { 63 return 0 64 } 65 return *raw 66 }