-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #399 from terraform-providers/disks
`azurerm_managed_disk` additions
- Loading branch information
Showing
4 changed files
with
373 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
package azurerm | ||
|
||
import ( | ||
"github.com/Azure/azure-sdk-for-go/arm/disk" | ||
"github.com/hashicorp/terraform/helper/schema" | ||
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" | ||
) | ||
|
||
func encryptionSettingsSchema() *schema.Schema { | ||
return &schema.Schema{ | ||
Type: schema.TypeList, | ||
Optional: true, | ||
MaxItems: 1, | ||
Elem: &schema.Resource{ | ||
Schema: map[string]*schema.Schema{ | ||
"enabled": { | ||
Type: schema.TypeBool, | ||
Required: true, | ||
|
||
// Azure can change enabled from false to true, but not the other way around, so | ||
// to keep idempotency, we'll conservatively set this to ForceNew=true | ||
ForceNew: true, | ||
}, | ||
|
||
"disk_encryption_key": { | ||
Type: schema.TypeList, | ||
Optional: true, | ||
MaxItems: 1, | ||
Elem: &schema.Resource{ | ||
Schema: map[string]*schema.Schema{ | ||
"secret_url": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
}, | ||
|
||
"source_vault_id": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
}, | ||
}, | ||
}, | ||
}, | ||
"key_encryption_key": { | ||
Type: schema.TypeList, | ||
Optional: true, | ||
MaxItems: 1, | ||
Elem: &schema.Resource{ | ||
Schema: map[string]*schema.Schema{ | ||
"key_url": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
}, | ||
|
||
"source_vault_id": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func expandManagedDiskEncryptionSettings(settings map[string]interface{}) *disk.EncryptionSettings { | ||
enabled := settings["enabled"].(bool) | ||
config := &disk.EncryptionSettings{ | ||
Enabled: utils.Bool(enabled), | ||
} | ||
|
||
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 = &disk.KeyVaultAndSecretReference{ | ||
SecretURL: utils.String(secretURL), | ||
SourceVault: &disk.SourceVault{ | ||
ID: utils.String(sourceVaultId), | ||
}, | ||
} | ||
} | ||
|
||
if v := settings["key_encryption_key"].([]interface{}); len(v) > 0 { | ||
kek := v[0].(map[string]interface{}) | ||
|
||
secretURL := kek["key_url"].(string) | ||
sourceVaultId := kek["source_vault_id"].(string) | ||
config.KeyEncryptionKey = &disk.KeyVaultAndKeyReference{ | ||
KeyURL: utils.String(secretURL), | ||
SourceVault: &disk.SourceVault{ | ||
ID: utils.String(sourceVaultId), | ||
}, | ||
} | ||
} | ||
|
||
return config | ||
} | ||
|
||
func flattenManagedDiskEncryptionSettings(encryptionSettings *disk.EncryptionSettings) []interface{} { | ||
value := map[string]interface{}{ | ||
"enabled": *encryptionSettings.Enabled, | ||
} | ||
|
||
if key := encryptionSettings.DiskEncryptionKey; key != nil { | ||
keys := make(map[string]interface{}, 0) | ||
|
||
keys["secret_url"] = *key.SecretURL | ||
if vault := key.SourceVault; vault != nil { | ||
keys["source_vault_id"] = *vault.ID | ||
} | ||
|
||
value["disk_encryption_key"] = []interface{}{keys} | ||
} | ||
|
||
if key := encryptionSettings.KeyEncryptionKey; key != nil { | ||
keys := make(map[string]interface{}, 0) | ||
|
||
keys["key_url"] = *key.KeyURL | ||
|
||
if vault := key.SourceVault; key != nil { | ||
keys["source_vault_id"] = *vault.ID | ||
} | ||
|
||
value["key_encryption_key"] = []interface{}{keys} | ||
} | ||
|
||
output := make([]interface{}, 0) | ||
output = append(output, value) | ||
return output | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.