Skip to content

Commit

Permalink
iothub_endpoint_storage_container
Browse files Browse the repository at this point in the history
  • Loading branch information
Maksymilian Boguń committed Jun 14, 2019
1 parent 4320131 commit b1872b8
Show file tree
Hide file tree
Showing 10 changed files with 690 additions and 52 deletions.
19 changes: 19 additions & 0 deletions azurerm/helpers/validate/iothub.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,22 @@ func IoTHubConsumerGroupName(v interface{}, k string) (warnings []string, errors

return warnings, errors
}

func IoTHubEndpointName(v interface{}, _ string) (warnings []string, errors []error) {
value := v.(string)

reservedNames := []string{
"events",
"operationsMonitoringEvents",
"fileNotifications",
"$default",
}

for _, name := range reservedNames {
if name == value {
errors = append(errors, fmt.Errorf("The reserved endpoint name %s could not be used as a name for a custom endpoint", name))
}
}

return warnings, errors
}
24 changes: 24 additions & 0 deletions azurerm/helpers/validate/storage_container.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package validate

import (
"fmt"
"regexp"
)

func StorageContainerName(v interface{}, k string) (warnings []string, errors []error) {
value := v.(string)
if !regexp.MustCompile(`^\$root$|^[0-9a-z-]+$`).MatchString(value) {
errors = append(errors, fmt.Errorf(
"only lowercase alphanumeric characters and hyphens allowed in %q: %q",
k, value))
}
if len(value) < 3 || len(value) > 63 {
errors = append(errors, fmt.Errorf(
"%q must be between 3 and 63 characters: %q", k, value))
}
if regexp.MustCompile(`^-`).MatchString(value) {
errors = append(errors, fmt.Errorf(
"%q cannot begin with a hyphen: %q", k, value))
}
return warnings, errors
}
1 change: 1 addition & 0 deletions azurerm/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,7 @@ func Provider() terraform.ResourceProvider {
"azurerm_iot_dps": resourceArmIotDPS(),
"azurerm_iothub_consumer_group": resourceArmIotHubConsumerGroup(),
"azurerm_iothub": resourceArmIotHub(),
"azurerm_iothub_endpoint_storage_container": resourceArmIotHubEndpointStorageContainer(),
"azurerm_iothub_shared_access_policy": resourceArmIotHubSharedAccessPolicy(),
"azurerm_key_vault_access_policy": resourceArmKeyVaultAccessPolicy(),
"azurerm_key_vault_certificate": resourceArmKeyVaultCertificate(),
Expand Down
45 changes: 16 additions & 29 deletions azurerm/resource_arm_iothub.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ func resourceArmIotHub() *schema.Resource {
"endpoint": {
Type: schema.TypeList,
Optional: true,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"type": {
Expand Down Expand Up @@ -194,7 +195,7 @@ func resourceArmIotHub() *schema.Resource {
"name": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validateIoTHubEndpointName,
ValidateFunc: validate.IoTHubEndpointName,
},
"batch_frequency_in_seconds": {
Type: schema.TypeInt,
Expand Down Expand Up @@ -400,14 +401,23 @@ func resourceArmIotHubCreateUpdate(d *schema.ResourceData, meta interface{}) err
location := azure.NormalizeLocation(d.Get("location").(string))
skuInfo := expandIoTHubSku(d)
tags := d.Get("tags").(map[string]interface{})

fallbackRoute := expandIoTHubFallbackRoute(d)
routes := expandIoTHubRoutes(d)

endpoints, err := expandIoTHubEndpoints(d, subscriptionID)
if err != nil {
return fmt.Errorf("Error expanding `endpoint`: %+v", err)
routingProperties := devices.RoutingProperties{
Routes: routes,
FallbackRoute: fallbackRoute,
}

if _, ok := d.GetOk("endpoint"); ok {
endpoints, err := expandIoTHubEndpoints(d, subscriptionID)
if err != nil {
return fmt.Errorf("Error expanding `endpoint`: %+v", err)
}
routingProperties.Endpoints = endpoints
}

routes := expandIoTHubRoutes(d)
ipFilterRules := expandIPFilterRules(d)

properties := devices.IotHubDescription{
Expand All @@ -416,11 +426,7 @@ func resourceArmIotHubCreateUpdate(d *schema.ResourceData, meta interface{}) err
Sku: skuInfo,
Properties: &devices.IotHubProperties{
IPFilterRules: ipFilterRules,
Routing: &devices.RoutingProperties{
Endpoints: endpoints,
Routes: routes,
FallbackRoute: fallbackRoute,
},
Routing: &routingProperties,
},
Tags: expandTags(tags),
}
Expand Down Expand Up @@ -911,25 +917,6 @@ func flattenIoTHubFallbackRoute(input *devices.RoutingProperties) []interface{}
return []interface{}{output}
}

func validateIoTHubEndpointName(v interface{}, _ string) (warnings []string, errors []error) {
value := v.(string)

reservedNames := []string{
"events",
"operationsMonitoringEvents",
"fileNotifications",
"$default",
}

for _, name := range reservedNames {
if name == value {
errors = append(errors, fmt.Errorf("The reserved endpoint name %s could not be used as a name for a custom endpoint", name))
}
}

return warnings, errors
}

func validateIoTHubFileNameFormat(v interface{}, k string) (warnings []string, errors []error) {
value := v.(string)

Expand Down
Loading

0 comments on commit b1872b8

Please sign in to comment.