Skip to content

Commit

Permalink
Merge pull request #4331 from terraform-providers/f/compute-api-upgrade
Browse files Browse the repository at this point in the history
compute: upgrading the API Version to 2019-07-01
  • Loading branch information
tombuildsstuff authored Sep 18, 2019
2 parents 2f19692 + 94911fd commit d2a4f22
Show file tree
Hide file tree
Showing 53 changed files with 2,576 additions and 449 deletions.
2 changes: 1 addition & 1 deletion azurerm/data_source_image.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"regexp"
"sort"

"github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2018-10-01/compute"
"github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2019-07-01/compute"
"github.com/hashicorp/terraform/helper/schema"
"github.com/hashicorp/terraform/helper/validation"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure"
Expand Down
2 changes: 1 addition & 1 deletion azurerm/data_source_shared_image.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package azurerm
import (
"fmt"

"github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2018-10-01/compute"
"github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2019-07-01/compute"
"github.com/hashicorp/terraform/helper/schema"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/validate"
Expand Down
8 changes: 4 additions & 4 deletions azurerm/data_source_shared_image_version.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"
"log"

"github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2018-10-01/compute"
"github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2019-07-01/compute"
"github.com/hashicorp/terraform/helper/schema"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/validate"
Expand Down Expand Up @@ -110,11 +110,11 @@ func dataSourceArmSharedImageVersionRead(d *schema.ResourceData, meta interface{
if err := d.Set("target_region", flattenedRegions); err != nil {
return fmt.Errorf("Error setting `target_region`: %+v", err)
}
}

if profile := props.StorageProfile; profile != nil {
if source := profile.Source; source != nil {
if image := source.ManagedImage; image != nil {
d.Set("managed_image_id", image.ID)
}
d.Set("managed_image_id", source.ID)
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions azurerm/data_source_snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ func dataSourceArmSnapshotRead(d *schema.ResourceData, meta interface{}) error {
d.Set("disk_size_gb", int(*props.DiskSizeGB))
}

if props.EncryptionSettings != nil {
d.Set("encryption_settings", flattenManagedDiskEncryptionSettings(props.EncryptionSettings))
if err := d.Set("encryption_settings", flattenManagedDiskEncryptionSettings(props.EncryptionSettingsCollection)); err != nil {
return fmt.Errorf("Error setting `encryption_settings`: %+v", err)
}
}

Expand Down
64 changes: 41 additions & 23 deletions azurerm/encryption_settings.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package azurerm

import (
"github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2018-10-01/compute"
"github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2019-07-01/compute"
"github.com/hashicorp/terraform/helper/schema"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils"
)
Expand Down Expand Up @@ -63,18 +63,21 @@ func encryptionSettingsSchema() *schema.Schema {
}
}

func expandManagedDiskEncryptionSettings(settings map[string]interface{}) *compute.EncryptionSettings {
func expandManagedDiskEncryptionSettings(settings map[string]interface{}) *compute.EncryptionSettingsCollection {
enabled := settings["enabled"].(bool)
config := &compute.EncryptionSettings{
config := &compute.EncryptionSettingsCollection{
Enabled: utils.Bool(enabled),
}

var diskEncryptionKey *compute.KeyVaultAndSecretReference
var keyEncryptionKey *compute.KeyVaultAndKeyReference

if v := settings["disk_encryption_key"].([]interface{}); len(v) > 0 {
dek := v[0].(map[string]interface{})

secretURL := dek["secret_url"].(string)
sourceVaultId := dek["source_vault_id"].(string)
config.DiskEncryptionKey = &compute.KeyVaultAndSecretReference{
diskEncryptionKey = &compute.KeyVaultAndSecretReference{
SecretURL: utils.String(secretURL),
SourceVault: &compute.SourceVault{
ID: utils.String(sourceVaultId),
Expand All @@ -87,46 +90,61 @@ func expandManagedDiskEncryptionSettings(settings map[string]interface{}) *compu

secretURL := kek["key_url"].(string)
sourceVaultId := kek["source_vault_id"].(string)
config.KeyEncryptionKey = &compute.KeyVaultAndKeyReference{
keyEncryptionKey = &compute.KeyVaultAndKeyReference{
KeyURL: utils.String(secretURL),
SourceVault: &compute.SourceVault{
ID: utils.String(sourceVaultId),
},
}
}

// at this time we only support a single element
config.EncryptionSettings = &[]compute.EncryptionSettingsElement{
{
DiskEncryptionKey: diskEncryptionKey,
KeyEncryptionKey: keyEncryptionKey,
},
}
return config
}

func flattenManagedDiskEncryptionSettings(encryptionSettings *compute.EncryptionSettings) []interface{} {
func flattenManagedDiskEncryptionSettings(encryptionSettings *compute.EncryptionSettingsCollection) []interface{} {
if encryptionSettings == nil {
return []interface{}{}
}

value := map[string]interface{}{
"enabled": *encryptionSettings.Enabled,
}

if key := encryptionSettings.DiskEncryptionKey; key != nil {
keys := make(map[string]interface{})
if encryptionSettings.EncryptionSettings != nil && len(*encryptionSettings.EncryptionSettings) > 0 {
// at this time we only support a single element
settings := (*encryptionSettings.EncryptionSettings)[0]
if key := settings.DiskEncryptionKey; key != nil {
keys := make(map[string]interface{})

keys["secret_url"] = *key.SecretURL
if vault := key.SourceVault; vault != nil {
keys["source_vault_id"] = *vault.ID
keys["secret_url"] = *key.SecretURL
if vault := key.SourceVault; vault != nil {
keys["source_vault_id"] = *vault.ID
}

value["disk_encryption_key"] = []interface{}{keys}
}

value["disk_encryption_key"] = []interface{}{keys}
}
if key := settings.KeyEncryptionKey; key != nil {
keys := make(map[string]interface{})

if key := encryptionSettings.KeyEncryptionKey; key != nil {
keys := make(map[string]interface{})
keys["key_url"] = *key.KeyURL

keys["key_url"] = *key.KeyURL
if vault := key.SourceVault; vault != nil {
keys["source_vault_id"] = *vault.ID
}

if vault := key.SourceVault; vault != nil {
keys["source_vault_id"] = *vault.ID
value["key_encryption_key"] = []interface{}{keys}
}

value["key_encryption_key"] = []interface{}{keys}
}

output := make([]interface{}, 0)
output = append(output, value)
return output
return []interface{}{
value,
}
}
2 changes: 1 addition & 1 deletion azurerm/internal/clients/compute.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package clients

import (
"github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2018-10-01/compute"
"github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2019-07-01/compute"
"github.com/Azure/azure-sdk-for-go/services/marketplaceordering/mgmt/2015-06-01/marketplaceordering"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/common"
)
Expand Down
2 changes: 1 addition & 1 deletion azurerm/resource_arm_availability_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"log"
"strings"

"github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2018-10-01/compute"
"github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2019-07-01/compute"
"github.com/hashicorp/terraform/helper/schema"
"github.com/hashicorp/terraform/helper/validation"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure"
Expand Down
2 changes: 1 addition & 1 deletion azurerm/resource_arm_image.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"
"log"

"github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2018-10-01/compute"
"github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2019-07-01/compute"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/suppress"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features"
Expand Down
12 changes: 5 additions & 7 deletions azurerm/resource_arm_managed_disk.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"log"
"strings"

"github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2018-10-01/compute"
"github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2019-07-01/compute"
"github.com/hashicorp/terraform/helper/schema"
"github.com/hashicorp/terraform/helper/validation"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure"
Expand Down Expand Up @@ -235,7 +235,7 @@ func resourceArmManagedDiskCreateUpdate(d *schema.ResourceData, meta interface{}
if v, ok := d.GetOk("encryption_settings"); ok {
encryptionSettings := v.([]interface{})
settings := encryptionSettings[0].(map[string]interface{})
createDisk.EncryptionSettings = expandManagedDiskEncryptionSettings(settings)
createDisk.EncryptionSettingsCollection = expandManagedDiskEncryptionSettings(settings)
}

future, err := client.CreateOrUpdate(ctx, resGroup, name, createDisk)
Expand Down Expand Up @@ -303,11 +303,9 @@ func resourceArmManagedDiskRead(d *schema.ResourceData, meta interface{}) error
flattenAzureRmManagedDiskCreationData(d, resp.CreationData)
}

if settings := resp.EncryptionSettings; settings != nil {
flattened := flattenManagedDiskEncryptionSettings(settings)
if err := d.Set("encryption_settings", flattened); err != nil {
return fmt.Errorf("Error setting encryption settings: %+v", err)
}
flattened := flattenManagedDiskEncryptionSettings(resp.EncryptionSettingsCollection)
if err := d.Set("encryption_settings", flattened); err != nil {
return fmt.Errorf("Error setting encryption settings: %+v", err)
}

return tags.FlattenAndSet(d, resp.Tags)
Expand Down
2 changes: 1 addition & 1 deletion azurerm/resource_arm_managed_disk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"net/http"
"testing"

"github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2018-10-01/compute"
"github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2019-07-01/compute"
"github.com/hashicorp/terraform/helper/acctest"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform"
Expand Down
2 changes: 1 addition & 1 deletion azurerm/resource_arm_proximity_placement_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"
"log"

"github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2018-10-01/compute"
"github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2019-07-01/compute"
"github.com/hashicorp/terraform/helper/schema"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf"
Expand Down
2 changes: 1 addition & 1 deletion azurerm/resource_arm_recovery_services_replicated_vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features"

"github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2018-10-01/compute"
"github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2019-07-01/compute"
"github.com/Azure/azure-sdk-for-go/services/recoveryservices/mgmt/2018-01-10/siterecovery"
"github.com/hashicorp/terraform/helper/hashcode"
"github.com/hashicorp/terraform/helper/schema"
Expand Down
2 changes: 1 addition & 1 deletion azurerm/resource_arm_shared_image.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"
"log"

"github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2018-10-01/compute"
"github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2019-07-01/compute"
"github.com/hashicorp/terraform/helper/schema"
"github.com/hashicorp/terraform/helper/validation"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure"
Expand Down
2 changes: 1 addition & 1 deletion azurerm/resource_arm_shared_image_gallery.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"
"log"

"github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2018-10-01/compute"
"github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2019-07-01/compute"
"github.com/hashicorp/terraform/helper/schema"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/response"
Expand Down
18 changes: 8 additions & 10 deletions azurerm/resource_arm_shared_image_version.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"
"log"

"github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2018-10-01/compute"
"github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2019-07-01/compute"
"github.com/hashicorp/terraform/helper/schema"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/response"
Expand Down Expand Up @@ -122,10 +122,10 @@ func resourceArmSharedImageVersionCreateUpdate(d *schema.ResourceData, meta inte
PublishingProfile: &compute.GalleryImageVersionPublishingProfile{
ExcludeFromLatest: utils.Bool(excludeFromLatest),
TargetRegions: targetRegions,
Source: &compute.GalleryArtifactSource{
ManagedImage: &compute.ManagedArtifact{
ID: utils.String(managedImageId),
},
},
StorageProfile: &compute.GalleryImageVersionStorageProfile{
Source: &compute.GalleryArtifactVersionSource{
ID: utils.String(managedImageId),
},
},
},
Expand All @@ -141,8 +141,6 @@ func resourceArmSharedImageVersionCreateUpdate(d *schema.ResourceData, meta inte
return fmt.Errorf("Error waiting for the creation of Shared Image Version %q (Image %q / Gallery %q / Resource Group %q): %+v", imageVersion, imageName, galleryName, resourceGroup, err)
}

// TODO: poll?

read, err := client.Get(ctx, resourceGroup, galleryName, imageName, imageVersion, "")
if err != nil {
return fmt.Errorf("Error retrieving Shared Image Version %q (Image %q / Gallery %q / Resource Group %q): %+v", imageVersion, imageName, galleryName, resourceGroup, err)
Expand Down Expand Up @@ -194,11 +192,11 @@ func resourceArmSharedImageVersionRead(d *schema.ResourceData, meta interface{})
if err := d.Set("target_region", flattenedRegions); err != nil {
return fmt.Errorf("Error setting `target_region`: %+v", err)
}
}

if profile := props.StorageProfile; profile != nil {
if source := profile.Source; source != nil {
if image := source.ManagedImage; image != nil {
d.Set("managed_image_id", image.ID)
}
d.Set("managed_image_id", source.ID)
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions azurerm/resource_arm_snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"log"
"regexp"

"github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2018-10-01/compute"
"github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2019-07-01/compute"
"github.com/hashicorp/terraform/helper/schema"
"github.com/hashicorp/terraform/helper/validation"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure"
Expand Down Expand Up @@ -132,7 +132,7 @@ func resourceArmSnapshotCreateUpdate(d *schema.ResourceData, meta interface{}) e
if v, ok := d.GetOk("encryption_settings"); ok {
encryptionSettings := v.([]interface{})
settings := encryptionSettings[0].(map[string]interface{})
properties.EncryptionSettings = expandManagedDiskEncryptionSettings(settings)
properties.EncryptionSettingsCollection = expandManagedDiskEncryptionSettings(settings)
}

future, err := client.CreateOrUpdate(ctx, resourceGroup, name, properties)
Expand Down Expand Up @@ -197,8 +197,8 @@ func resourceArmSnapshotRead(d *schema.ResourceData, meta interface{}) error {
d.Set("disk_size_gb", int(*props.DiskSizeGB))
}

if props.EncryptionSettings != nil {
d.Set("encryption_settings", flattenManagedDiskEncryptionSettings(props.EncryptionSettings))
if err := d.Set("encryption_settings", flattenManagedDiskEncryptionSettings(props.EncryptionSettingsCollection)); err != nil {
return fmt.Errorf("Error setting `encryption_settings`: %+v", err)
}
}

Expand Down
2 changes: 1 addition & 1 deletion azurerm/resource_arm_virtual_machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"log"
"strings"

"github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2018-10-01/compute"
"github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2019-07-01/compute"
"github.com/Azure/azure-sdk-for-go/services/network/mgmt/2019-06-01/network"
"github.com/hashicorp/terraform/helper/hashcode"
"github.com/hashicorp/terraform/helper/schema"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"
"log"

"github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2018-10-01/compute"
"github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2019-07-01/compute"
"github.com/hashicorp/terraform/helper/schema"
"github.com/hashicorp/terraform/helper/validation"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure"
Expand Down
2 changes: 1 addition & 1 deletion azurerm/resource_arm_virtual_machine_extension.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package azurerm
import (
"fmt"

"github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2018-10-01/compute"
"github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2019-07-01/compute"
"github.com/hashicorp/terraform/helper/schema"
"github.com/hashicorp/terraform/helper/structure"
"github.com/hashicorp/terraform/helper/validation"
Expand Down
2 changes: 1 addition & 1 deletion azurerm/resource_arm_virtual_machine_managed_disks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"strings"
"testing"

"github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2018-10-01/compute"
"github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2019-07-01/compute"
"github.com/hashicorp/terraform/helper/acctest"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform"
Expand Down
2 changes: 1 addition & 1 deletion azurerm/resource_arm_virtual_machine_scale_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"log"
"strings"

"github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2018-10-01/compute"
"github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2019-07-01/compute"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tags"

Expand Down
Loading

0 comments on commit d2a4f22

Please sign in to comment.