refactored flatten methods to also set values

This commit is contained in:
Brandon Tosch 2017-03-14 11:50:37 -07:00
parent dbb4daa72f
commit 8f2d2ed954
1 changed files with 9 additions and 27 deletions

View File

@ -191,23 +191,11 @@ func resourceArmManagedDiskRead(d *schema.ResourceData, meta interface{}) error
d.Set("location", resp.Location) d.Set("location", resp.Location)
if resp.Properties != nil { if resp.Properties != nil {
m := flattenAzureRmManagedDiskProperties(resp.Properties) flattenAzureRmManagedDiskProperties(d, resp.Properties)
d.Set("storage_account_type", m["storage_account_type"])
d.Set("disk_size_gb", m["disk_size_gb"])
if m["os_type"] != nil {
d.Set("os_type", m["os_type"])
}
} }
if resp.CreationData != nil { if resp.CreationData != nil {
m := flattenAzureRmManagedDiskCreationData(resp.CreationData) flattenAzureRmManagedDiskCreationData(d, resp.CreationData)
d.Set("create_option", m["create_option"])
if m["source_uri"] != nil {
d.Set("source_uri", m["source_uri"])
}
if m["source_resource_id"] != nil {
d.Set("source_resource_id", m["source_resource_id"])
}
} }
flattenAndSetTags(d, resp.Tags) flattenAndSetTags(d, resp.Tags)
@ -232,25 +220,19 @@ func resourceArmManagedDiskDelete(d *schema.ResourceData, meta interface{}) erro
return nil return nil
} }
func flattenAzureRmManagedDiskProperties(properties *disk.Properties) map[string]interface{} { func flattenAzureRmManagedDiskProperties(d *schema.ResourceData, properties *disk.Properties) {
result := make(map[string]interface{}) d.Set("storage_account_type", string(properties.AccountType))
result["storage_account_type"] = string(properties.AccountType)
if properties.DiskSizeGB != nil { if properties.DiskSizeGB != nil {
result["disk_size_gb"] = *properties.DiskSizeGB d.Set("disk_size_gb", *properties.DiskSizeGB)
} }
if properties.OsType != "" { if properties.OsType != "" {
result["os_type"] = string(properties.OsType) d.Set("os_type", string(properties.OsType))
} }
return result
} }
func flattenAzureRmManagedDiskCreationData(creationData *disk.CreationData) map[string]interface{} { func flattenAzureRmManagedDiskCreationData(d *schema.ResourceData, creationData *disk.CreationData) {
result := make(map[string]interface{}) d.Set("create_option", string(creationData.CreateOption))
result["create_option"] = string(creationData.CreateOption)
if creationData.SourceURI != nil { if creationData.SourceURI != nil {
result["source_uri"] = *creationData.SourceURI d.Set("source_uri", *creationData.SourceURI)
} }
return result
} }