diff --git a/azurerm/resource_arm_iothub.go b/azurerm/resource_arm_iothub.go index 4a6bbd7d0849f..13e8e61cfb143 100755 --- a/azurerm/resource_arm_iothub.go +++ b/azurerm/resource_arm_iothub.go @@ -21,6 +21,23 @@ import ( "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" ) +func suppressIfTypeIsNot(t string) schema.SchemaDiffSuppressFunc { + return func(k, old, new string, d *schema.ResourceData) bool { + return d.Get("type").(string) != t + } +} + +func supressWhenAll(fs ...schema.SchemaDiffSuppressFunc) schema.SchemaDiffSuppressFunc { + return func(k, old, new string, d *schema.ResourceData) bool { + for _, f := range fs { + if !f(k, old, new, d) { + return false + } + } + return true + } +} + func resourceArmIotHub() *schema.Resource { return &schema.Resource{ Create: resourceArmIotHubCreateUpdate, @@ -158,13 +175,14 @@ func resourceArmIotHub() *schema.Resource { Type: schema.TypeString, Required: true, DiffSuppressFunc: func(k, old, new string, d *schema.ResourceData) bool { - // As Azure API masks the connection string key suppress diff for this property - if old != "" && strings.HasSuffix(old, "****") { - return true - } + secretKeyRegex := regexp.MustCompile("(SharedAccessKey|AccountKey)=[^;]+") + sbProtocolRegex := regexp.MustCompile("sb://([^:]+)(:5671)?/;") - return false + betterNew := sbProtocolRegex.ReplaceAllString(new, "sb://$1:5671/;") + betterNew = secretKeyRegex.ReplaceAllString(betterNew, "$1=****") + return old == betterNew }, + Sensitive: true, }, "name": { Type: schema.TypeString, @@ -172,25 +190,30 @@ func resourceArmIotHub() *schema.Resource { ValidateFunc: validateIoTHubEndpointName, }, "batch_frequency_in_seconds": { - Type: schema.TypeInt, - Optional: true, - Default: 300, - ValidateFunc: validation.IntBetween(60, 720), + Type: schema.TypeInt, + Optional: true, + Default: 300, + DiffSuppressFunc: suppressIfTypeIsNot("AzureIotHub.StorageContainer"), + ValidateFunc: validation.IntBetween(60, 720), }, "max_chunk_size_in_bytes": { - Type: schema.TypeInt, - Optional: true, - Default: 314572800, - ValidateFunc: validation.IntBetween(10485760, 524288000), + Type: schema.TypeInt, + Optional: true, + Default: 314572800, + DiffSuppressFunc: suppressIfTypeIsNot("AzureIotHub.StorageContainer"), + ValidateFunc: validation.IntBetween(10485760, 524288000), }, "container_name": { - Type: schema.TypeString, - Optional: true, - }, - "encoding": { Type: schema.TypeString, Optional: true, - DiffSuppressFunc: suppress.CaseDifference, + DiffSuppressFunc: suppressIfTypeIsNot("AzureIotHub.StorageContainer"), + }, + "encoding": { + Type: schema.TypeString, + Optional: true, + DiffSuppressFunc: supressWhenAll( + suppressIfTypeIsNot("AzureIotHub.StorageContainer"), + suppress.CaseDifference), ValidateFunc: validation.StringInSlice([]string{ string(devices.Avro), string(devices.AvroDeflate), @@ -745,6 +768,8 @@ func flattenIoTHubEndpoint(input *devices.RoutingProperties) []interface{} { output["name"] = *name } + output["type"] = "AzureIotHub.ServiceBusQueue" + results = append(results, output) } } @@ -760,6 +785,8 @@ func flattenIoTHubEndpoint(input *devices.RoutingProperties) []interface{} { output["name"] = *name } + output["type"] = "AzureIotHub.ServiceBusTopic" + results = append(results, output) } } @@ -775,6 +802,8 @@ func flattenIoTHubEndpoint(input *devices.RoutingProperties) []interface{} { output["name"] = *name } + output["type"] = "AzureIotHub.EventHub" + results = append(results, output) } }