Skip to content

Commit

Permalink
Upgrading to v15 of the Azure SDK for Go (#1077)
Browse files Browse the repository at this point in the history
* Vendoring v15.0.0 of the Azure SDK for Go

* Upgrading to v10.6.0 of Azure/go-autorest

* Downgrading the Automation SDK to v12.5.0-beta of the Azure SDK for Go

* Fixing the Storage SDK

* Upgrading to support SDKv15

* Fixing a race condition in the Role Assignment tests

```
$ acctests azurerm TestAccAzureRMRoleAssignment
=== RUN   TestAccAzureRMRoleAssignment
=== RUN   TestAccAzureRMRoleAssignment/basic
=== RUN   TestAccAzureRMRoleAssignment/basic/roleName
=== RUN   TestAccAzureRMRoleAssignment/basic/builtin
=== RUN   TestAccAzureRMRoleAssignment/basic/custom
=== RUN   TestAccAzureRMRoleAssignment/basic/emptyName
=== RUN   TestAccAzureRMRoleAssignment/import
=== RUN   TestAccAzureRMRoleAssignment/import/basic
=== RUN   TestAccAzureRMRoleAssignment/import/custom
--- PASS: TestAccAzureRMRoleAssignment (446.84s)
    --- PASS: TestAccAzureRMRoleAssignment/basic (113.85s)
        --- PASS: TestAccAzureRMRoleAssignment/basic/roleName (32.06s)
        --- PASS: TestAccAzureRMRoleAssignment/basic/builtin (24.82s)
        --- PASS: TestAccAzureRMRoleAssignment/basic/custom (26.03s)
        --- PASS: TestAccAzureRMRoleAssignment/basic/emptyName (30.94s)
    --- PASS: TestAccAzureRMRoleAssignment/import (332.99s)
        --- PASS: TestAccAzureRMRoleAssignment/import/basic (30.90s)
        --- PASS: TestAccAzureRMRoleAssignment/import/custom (302.09s)
PASS
ok  	github.com/terraform-providers/terraform-provider-azurerm/azurerm	446.872s
```

* Fixing the Template Deployment tests

```
$ acctests azurerm TestAccAzureRMTemplateDeployment_withOutputs
=== RUN   TestAccAzureRMTemplateDeployment_withOutputs
--- PASS: TestAccAzureRMTemplateDeployment_withOutputs (226.89s)
PASS
ok  	github.com/terraform-providers/terraform-provider-azurerm/azurerm	226.921s
```
  • Loading branch information
tombuildsstuff authored Apr 6, 2018
1 parent bfa9ad6 commit ce7631a
Show file tree
Hide file tree
Showing 365 changed files with 47,798 additions and 24,444 deletions.
22 changes: 11 additions & 11 deletions azurerm/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ func (c *ArmClient) registerCDNClients(endpoint, subscriptionId string, auth aut
}

func (c *ArmClient) registerCosmosDBClients(endpoint, subscriptionId string, auth autorest.Authorizer, sender autorest.Sender) {
cdb := documentdb.NewDatabaseAccountsClientWithBaseURI(endpoint, subscriptionId, "", "", "", "", "")
cdb := documentdb.NewDatabaseAccountsClientWithBaseURI(endpoint, subscriptionId)
c.configureClient(&cdb.Client, auth)
c.cosmosDBClient = cdb
}
Expand Down Expand Up @@ -905,7 +905,7 @@ var (
storageKeyCache = make(map[string]string)
)

func (armClient *ArmClient) getKeyForStorageAccount(resourceGroupName, storageAccountName string) (string, bool, error) {
func (armClient *ArmClient) getKeyForStorageAccount(ctx context.Context, resourceGroupName, storageAccountName string) (string, bool, error) {
cacheIndex := resourceGroupName + "/" + storageAccountName
storageKeyCacheMu.RLock()
key, ok := storageKeyCache[cacheIndex]
Expand All @@ -919,7 +919,7 @@ func (armClient *ArmClient) getKeyForStorageAccount(resourceGroupName, storageAc
defer storageKeyCacheMu.Unlock()
key, ok = storageKeyCache[cacheIndex]
if !ok {
accountKeys, err := armClient.storageServiceClient.ListKeys(resourceGroupName, storageAccountName)
accountKeys, err := armClient.storageServiceClient.ListKeys(ctx, resourceGroupName, storageAccountName)
if utils.ResponseWasNotFound(accountKeys.Response) {
return "", false, nil
}
Expand Down Expand Up @@ -950,8 +950,8 @@ func (armClient *ArmClient) getKeyForStorageAccount(resourceGroupName, storageAc
return key, true, nil
}

func (armClient *ArmClient) getBlobStorageClientForStorageAccount(resourceGroupName, storageAccountName string) (*mainStorage.BlobStorageClient, bool, error) {
key, accountExists, err := armClient.getKeyForStorageAccount(resourceGroupName, storageAccountName)
func (armClient *ArmClient) getBlobStorageClientForStorageAccount(ctx context.Context, resourceGroupName, storageAccountName string) (*mainStorage.BlobStorageClient, bool, error) {
key, accountExists, err := armClient.getKeyForStorageAccount(ctx, resourceGroupName, storageAccountName)
if err != nil {
return nil, accountExists, err
}
Expand All @@ -969,8 +969,8 @@ func (armClient *ArmClient) getBlobStorageClientForStorageAccount(resourceGroupN
return &blobClient, true, nil
}

func (armClient *ArmClient) getFileServiceClientForStorageAccount(resourceGroupName, storageAccountName string) (*mainStorage.FileServiceClient, bool, error) {
key, accountExists, err := armClient.getKeyForStorageAccount(resourceGroupName, storageAccountName)
func (armClient *ArmClient) getFileServiceClientForStorageAccount(ctx context.Context, resourceGroupName, storageAccountName string) (*mainStorage.FileServiceClient, bool, error) {
key, accountExists, err := armClient.getKeyForStorageAccount(ctx, resourceGroupName, storageAccountName)
if err != nil {
return nil, accountExists, err
}
Expand All @@ -988,8 +988,8 @@ func (armClient *ArmClient) getFileServiceClientForStorageAccount(resourceGroupN
return &fileClient, true, nil
}

func (armClient *ArmClient) getTableServiceClientForStorageAccount(resourceGroupName, storageAccountName string) (*mainStorage.TableServiceClient, bool, error) {
key, accountExists, err := armClient.getKeyForStorageAccount(resourceGroupName, storageAccountName)
func (armClient *ArmClient) getTableServiceClientForStorageAccount(ctx context.Context, resourceGroupName, storageAccountName string) (*mainStorage.TableServiceClient, bool, error) {
key, accountExists, err := armClient.getKeyForStorageAccount(ctx, resourceGroupName, storageAccountName)
if err != nil {
return nil, accountExists, err
}
Expand All @@ -1007,8 +1007,8 @@ func (armClient *ArmClient) getTableServiceClientForStorageAccount(resourceGroup
return &tableClient, true, nil
}

func (armClient *ArmClient) getQueueServiceClientForStorageAccount(resourceGroupName, storageAccountName string) (*mainStorage.QueueServiceClient, bool, error) {
key, accountExists, err := armClient.getKeyForStorageAccount(resourceGroupName, storageAccountName)
func (armClient *ArmClient) getQueueServiceClientForStorageAccount(ctx context.Context, resourceGroupName, storageAccountName string) (*mainStorage.QueueServiceClient, bool, error) {
key, accountExists, err := armClient.getKeyForStorageAccount(ctx, resourceGroupName, storageAccountName)
if err != nil {
return nil, accountExists, err
}
Expand Down
5 changes: 3 additions & 2 deletions azurerm/data_source_storage_account.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,13 +159,14 @@ func dataSourceArmStorageAccount() *schema.Resource {
}

func dataSourceArmStorageAccountRead(d *schema.ResourceData, meta interface{}) error {
ctx := meta.(*ArmClient).StopContext
client := meta.(*ArmClient).storageServiceClient
endpointSuffix := meta.(*ArmClient).environment.StorageEndpointSuffix

name := d.Get("name").(string)
resourceGroup := d.Get("resource_group_name").(string)

resp, err := client.GetProperties(resourceGroup, name)
resp, err := client.GetProperties(ctx, resourceGroup, name)
if err != nil {
if utils.ResponseWasNotFound(resp.Response) {
d.SetId("")
Expand All @@ -176,7 +177,7 @@ func dataSourceArmStorageAccountRead(d *schema.ResourceData, meta interface{}) e

d.SetId(*resp.ID)

keys, err := client.ListKeys(resourceGroup, name)
keys, err := client.ListKeys(ctx, resourceGroup, name)
if err != nil {
return err
}
Expand Down
8 changes: 4 additions & 4 deletions azurerm/import_arm_role_assignment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ import (
"github.com/hashicorp/terraform/helper/resource"
)

func TestAccAzureRMRoleAssignment_importBasic(t *testing.T) {
func testAccAzureRMRoleAssignment_importBasic(t *testing.T) {
resourceName := "azurerm_role_assignment.test"

roleDefinitionId := uuid.New().String()
roleAssignmentId := uuid.New().String()
ri := acctest.RandInt()
config := testAccAzureRMRoleAssignment_custom(roleDefinitionId, roleAssignmentId, ri)
config := testAccAzureRMRoleAssignment_customConfig(roleDefinitionId, roleAssignmentId, ri)

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Expand All @@ -33,13 +33,13 @@ func TestAccAzureRMRoleAssignment_importBasic(t *testing.T) {
})
}

func TestAccAzureRMRoleAssignment_importCustom(t *testing.T) {
func testAccAzureRMRoleAssignment_importCustom(t *testing.T) {
resourceName := "azurerm_role_assignment.test"

roleDefinitionId := uuid.New().String()
roleAssignmentId := uuid.New().String()
ri := acctest.RandInt()
config := testAccAzureRMRoleAssignment_custom(roleDefinitionId, roleAssignmentId, ri)
config := testAccAzureRMRoleAssignment_customConfig(roleDefinitionId, roleAssignmentId, ri)

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Expand Down
37 changes: 11 additions & 26 deletions azurerm/resource_arm_app_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -329,12 +329,7 @@ func resourceArmAppServiceCreate(d *schema.ResourceData, meta interface{}) error
siteEnvelope.SiteProperties.ClientAffinityEnabled = utils.Bool(enabled)
}

// NOTE: these seem like sensible defaults, in lieu of any better documentation.
skipDNSRegistration := false
forceDNSRegistration := false
skipCustomDomainVerification := true
ttlInSeconds := "60"
createFuture, err := client.CreateOrUpdate(ctx, resGroup, name, siteEnvelope, &skipDNSRegistration, &skipCustomDomainVerification, &forceDNSRegistration, ttlInSeconds)
createFuture, err := client.CreateOrUpdate(ctx, resGroup, name, siteEnvelope)
if err != nil {
return err
}
Expand Down Expand Up @@ -392,16 +387,7 @@ func resourceArmAppServiceUpdate(d *schema.ResourceData, meta interface{}) error
},
}

_, err := client.Update(
ctx,
resGroup,
name,
sitePatchResource,
nil,
nil,
nil,
"")

_, err := client.Update(ctx, resGroup, name, sitePatchResource)
if err != nil {
return fmt.Errorf("Error updating App Service ARR Affinity setting %q: %+v", name, err)
}
Expand Down Expand Up @@ -546,9 +532,8 @@ func resourceArmAppServiceDelete(d *schema.ResourceData, meta interface{}) error

deleteMetrics := true
deleteEmptyServerFarm := false
skipDNSRegistration := true
ctx := meta.(*ArmClient).StopContext
resp, err := client.Delete(ctx, resGroup, name, &deleteMetrics, &deleteEmptyServerFarm, &skipDNSRegistration)
resp, err := client.Delete(ctx, resGroup, name, &deleteMetrics, &deleteEmptyServerFarm)
if err != nil {
if !utils.ResponseWasNotFound(resp) {
return err
Expand Down Expand Up @@ -732,18 +717,18 @@ func flattenAppServiceSourceControl(input *web.SiteSourceControlProperties) []in
return append(results, result)
}

func expandAppServiceAppSettings(d *schema.ResourceData) *map[string]*string {
func expandAppServiceAppSettings(d *schema.ResourceData) map[string]*string {
input := d.Get("app_settings").(map[string]interface{})
output := make(map[string]*string, len(input))

for k, v := range input {
output[k] = utils.String(v.(string))
}

return &output
return output
}

func expandAppServiceConnectionStrings(d *schema.ResourceData) *map[string]*web.ConnStringValueTypePair {
func expandAppServiceConnectionStrings(d *schema.ResourceData) map[string]*web.ConnStringValueTypePair {
input := d.Get("connection_string").([]interface{})
output := make(map[string]*web.ConnStringValueTypePair, len(input))

Expand All @@ -760,13 +745,13 @@ func expandAppServiceConnectionStrings(d *schema.ResourceData) *map[string]*web.
}
}

return &output
return output
}

func flattenAppServiceConnectionStrings(input *map[string]*web.ConnStringValueTypePair) interface{} {
func flattenAppServiceConnectionStrings(input map[string]*web.ConnStringValueTypePair) interface{} {
results := make([]interface{}, 0)

for k, v := range *input {
for k, v := range input {
result := make(map[string]interface{}, 0)
result["name"] = k
result["type"] = string(v.Type)
Expand All @@ -777,9 +762,9 @@ func flattenAppServiceConnectionStrings(input *map[string]*web.ConnStringValueTy
return results
}

func flattenAppServiceAppSettings(input *map[string]*string) map[string]string {
func flattenAppServiceAppSettings(input map[string]*string) map[string]string {
output := make(map[string]string, 0)
for k, v := range *input {
for k, v := range input {
output[k] = *v
}

Expand Down
15 changes: 9 additions & 6 deletions azurerm/resource_arm_automation_account.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,16 +64,17 @@ func resourceArmAutomationAccountCreateUpdate(d *schema.ResourceData, meta inter
location := azureRMNormalizeLocation(d.Get("location").(string))
resGroup := d.Get("resource_group_name").(string)
tags := d.Get("tags").(map[string]interface{})
expandedTags := expandTags(tags)

sku := expandSku(d)
sku := expandAutomationAccountSku(d)

parameters := automation.AccountCreateOrUpdateParameters{
AccountCreateOrUpdateProperties: &automation.AccountCreateOrUpdateProperties{
Sku: &sku,
},

Location: &location,
Tags: expandTags(tags),
Tags: &expandedTags,
}

_, err := client.CreateOrUpdate(ctx, resGroup, name, parameters)
Expand Down Expand Up @@ -121,9 +122,11 @@ func resourceArmAutomationAccountRead(d *schema.ResourceData, meta interface{})
d.Set("location", azureRMNormalizeLocation(*location))
}

flattenAndSetSku(d, resp.Sku)
flattenAndSetAutomationAccountSku(d, resp.Sku)

flattenAndSetTags(d, resp.Tags)
if tags := resp.Tags; tags != nil {
flattenAndSetTags(d, *tags)
}

return nil
}
Expand Down Expand Up @@ -152,7 +155,7 @@ func resourceArmAutomationAccountDelete(d *schema.ResourceData, meta interface{}
return nil
}

func flattenAndSetSku(d *schema.ResourceData, sku *automation.Sku) {
func flattenAndSetAutomationAccountSku(d *schema.ResourceData, sku *automation.Sku) {
results := make([]interface{}, 1)

result := map[string]interface{}{}
Expand All @@ -162,7 +165,7 @@ func flattenAndSetSku(d *schema.ResourceData, sku *automation.Sku) {
d.Set("sku", &results)
}

func expandSku(d *schema.ResourceData) automation.Sku {
func expandAutomationAccountSku(d *schema.ResourceData) automation.Sku {
inputs := d.Get("sku").([]interface{})
input := inputs[0].(map[string]interface{})
name := automation.SkuNameEnum(input["name"].(string))
Expand Down
7 changes: 5 additions & 2 deletions azurerm/resource_arm_automation_runbook.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ func resourceArmAutomationRunbookCreateUpdate(d *schema.ResourceData, meta inter
resGroup := d.Get("resource_group_name").(string)
client.ResourceGroupName = resGroup
tags := d.Get("tags").(map[string]interface{})
expandedTags := expandTags(tags)

accName := d.Get("account_name").(string)
runbookType := automation.RunbookTypeEnum(d.Get("runbook_type").(string))
Expand All @@ -137,7 +138,7 @@ func resourceArmAutomationRunbookCreateUpdate(d *schema.ResourceData, meta inter
},

Location: &location,
Tags: expandTags(tags),
Tags: &expandedTags,
}

_, err := client.CreateOrUpdate(ctx, accName, name, parameters)
Expand Down Expand Up @@ -195,7 +196,9 @@ func resourceArmAutomationRunbookRead(d *schema.ResourceData, meta interface{})
d.Set("description", props.Description)
}

flattenAndSetTags(d, resp.Tags)
if tags := resp.Tags; tags != nil {
flattenAndSetTags(d, *tags)
}

return nil
}
Expand Down
3 changes: 2 additions & 1 deletion azurerm/resource_arm_container_registry_migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,9 @@ func updateV1ToV2StorageAccountName(is *terraform.InstanceState, meta interface{
}

func findAzureStorageAccountIdFromName(name string, meta interface{}) (string, error) {
ctx := meta.(*ArmClient).StopContext
client := meta.(*ArmClient).storageServiceClient
accounts, err := client.List()
accounts, err := client.List(ctx)
if err != nil {
return "", err
}
Expand Down
22 changes: 15 additions & 7 deletions azurerm/resource_arm_container_registry_migrate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,18 +119,26 @@ func createStorageAccount(client *ArmClient, resourceGroupName, storageAccountNa
},
}
ctx := client.StopContext
createFuture, createErr := storageClient.Create(resourceGroupName, storageAccountName, createParams, ctx.Done())

select {
case err := <-createErr:
future, err := storageClient.Create(ctx, resourceGroupName, storageAccountName, createParams)
if err != nil {
return nil, fmt.Errorf("Error creating Storage Account %q: %+v", resourceGroupName, err)
case account := <-createFuture:
return &account, nil
}

err = future.WaitForCompletion(ctx, storageClient.Client)
if err != nil {
return nil, fmt.Errorf("Error waiting for creation of Storage Account %q: %+v", resourceGroupName, err)
}

account, err := storageClient.GetProperties(ctx, resourceGroupName, storageAccountName)
if err != nil {
return nil, fmt.Errorf("Error retrieving Storage Account %q: %+v", resourceGroupName, err)
}

return &account, nil
}

func destroyStorageAccountAndResourceGroup(client *ArmClient, resourceGroupName, storageAccountName string) {
ctx := client.StopContext
client.storageServiceClient.Delete(resourceGroupName, storageAccountName)
client.storageServiceClient.Delete(ctx, resourceGroupName, storageAccountName)
client.resourceGroupsClient.Delete(ctx, resourceGroupName)
}
Loading

0 comments on commit ce7631a

Please sign in to comment.