Skip to content

Commit

Permalink
fix sku validation
Browse files Browse the repository at this point in the history
  • Loading branch information
jcorioland committed Nov 27, 2018
1 parent 0511763 commit 62cefde
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions azurerm/resource_arm_container_registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,16 +115,6 @@ func resourceArmContainerRegistry() *schema.Resource {

CustomizeDiff: func(d *schema.ResourceDiff, v interface{}) error {
sku := d.Get("sku").(string)
if _, ok := d.GetOk("storage_account_id"); ok {
if strings.ToLower(sku) != strings.ToLower(string(containerregistry.Classic)) {
return fmt.Errorf("`storage_account_id` can only be specified for a Classic (unmanaged) Sku.")
}
} else {
if strings.ToLower(sku) == strings.ToLower(string(containerregistry.Classic)) {
return fmt.Errorf("`storage_account_id` must be specified for a Classic (unmanaged) Sku.")
}
}

geoReplicationLocations := d.Get("georeplication_locations").(*schema.Set)
// if locations have been specified for geo-replication then, the SKU has to be Premium
if geoReplicationLocations != nil && geoReplicationLocations.Len() > 0 && !strings.EqualFold(sku, string(containerregistry.Premium)) {
Expand Down Expand Up @@ -162,9 +152,17 @@ func resourceArmContainerRegistryCreate(d *schema.ResourceData, meta interface{}
}

if v, ok := d.GetOk("storage_account_id"); ok {
if strings.ToLower(sku) != strings.ToLower(string(containerregistry.Classic)) {
return fmt.Errorf("`storage_account_id` can only be specified for a Classic (unmanaged) Sku.")
}

parameters.StorageAccount = &containerregistry.StorageAccountProperties{
ID: utils.String(v.(string)),
}
} else {
if strings.ToLower(sku) == strings.ToLower(string(containerregistry.Classic)) {
return fmt.Errorf("`storage_account_id` must be specified for a Classic (unmanaged) Sku.")
}
}

future, err := client.Create(ctx, resourceGroup, name, parameters)
Expand Down

0 comments on commit 62cefde

Please sign in to comment.