Skip to content

Commit

Permalink
* removed sku from additional_location schema
Browse files Browse the repository at this point in the history
* in-lined sku schema
* do not return error if key is not found in terraform state
  • Loading branch information
torresdal committed Jul 14, 2018
1 parent 5d58d0d commit 3b1397d
Showing 1 changed file with 17 additions and 36 deletions.
53 changes: 17 additions & 36 deletions azurerm/data_source_api_management.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,22 @@ func dataSourceApiManagementService() *schema.Resource {
Computed: true,
},

"sku": apiManagementDataSourceSkuSchema(),
"sku": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Computed: true,
},
"capacity": {
Type: schema.TypeInt,
Computed: true,
},
},
},
},

"notification_sender_email": {
Type: schema.TypeString,
Expand Down Expand Up @@ -77,8 +92,6 @@ func dataSourceApiManagementService() *schema.Resource {
Schema: map[string]*schema.Schema{
"location": locationForDataSourceSchema(),

"sku": apiManagementDataSourceSkuSchema(),

"gateway_regional_url": {
Type: schema.TypeString,
Computed: true,
Expand Down Expand Up @@ -224,25 +237,6 @@ func dataSourceApiManagementRead(d *schema.ResourceData, meta interface{}) error
return nil
}

func apiManagementDataSourceSkuSchema() *schema.Schema {
return &schema.Schema{
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Computed: true,
},
"capacity": {
Type: schema.TypeInt,
Computed: true,
},
},
},
}
}

func apiManagementDataSourceCertificateInfoSchema() *schema.Schema {
return &schema.Schema{
Type: schema.TypeList,
Expand Down Expand Up @@ -298,17 +292,13 @@ func flattenDataSourceApiManagementHostnameConfigurations(d *schema.ResourceData
if v, ok := d.GetOk(passKey); ok {
password := v.(string)
host_config["certificate_password"] = password
} else {
return nil, fmt.Errorf("Error getting `certificate_password` from key %s", passKey)
}

// encoded certificate isn't returned, so let's look it up
certKey := fmt.Sprintf("hostname_configuration.%d.certificate", i)
if v, ok := d.GetOk(certKey); ok {
cert := v.(string)
host_config["certificate"] = cert
} else {
return nil, fmt.Errorf("Error getting `certificate` from key %s", certKey)
}

host_configs = append(host_configs, host_config)
Expand Down Expand Up @@ -355,12 +345,6 @@ func flattenDataSourceApiManagementAdditionalLocations(props *[]apimanagement.Ad
additional_location["gateway_regional_url"] = *prop.GatewayRegionalURL
}

if prop.Sku != nil {
if sku := flattenDataSourceApiManagementServiceSku(prop.Sku); sku != nil {
additional_location["sku"] = sku
}
}

additional_locations = append(additional_locations, additional_location)
}
}
Expand Down Expand Up @@ -388,16 +372,13 @@ func flattenDataSourceApiManagementCertificates(d *schema.ResourceData, props *[
if v, ok := d.GetOk(passwKey); ok {
password := v.(string)
certificate["certificate_password"] = password
} else {
return nil, fmt.Errorf("Error getting `certificate_password` from key %s", passwKey)
}

// encoded certificate isn't returned, so let's look it up
certKey := fmt.Sprintf("certificate.%d.encoded_certificate", i)
if v, ok := d.GetOk(certKey); ok {
cert := v.(string)
certificate["encoded_certificate"] = cert
} else {
return nil, fmt.Errorf("Error getting `encoded_certificate` from key %s", certKey)
}

certificates = append(certificates, certificate)
Expand Down

0 comments on commit 3b1397d

Please sign in to comment.