From 521af207c1c1dba1d7a28c2b2c21ae8d5c1379b2 Mon Sep 17 00:00:00 2001 From: tombuildsstuff Date: Sun, 4 Nov 2018 20:20:13 +0000 Subject: [PATCH 1/4] iothub: refactoring --- azurerm/resource_arm_iothub.go | 58 ++++++++++++----------------- website/azurerm.erb | 2 +- website/docs/r/iothub.html.markdown | 6 +-- 3 files changed, 28 insertions(+), 38 deletions(-) diff --git a/azurerm/resource_arm_iothub.go b/azurerm/resource_arm_iothub.go index 15e791c6f04a..a9d8ce7658c1 100755 --- a/azurerm/resource_arm_iothub.go +++ b/azurerm/resource_arm_iothub.go @@ -15,14 +15,15 @@ import ( "github.com/hashicorp/terraform/helper/schema" "github.com/hashicorp/terraform/helper/validation" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/response" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/suppress" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" ) func resourceArmIotHub() *schema.Resource { return &schema.Resource{ - Create: resourceArmIotHubCreateAndUpdate, + Create: resourceArmIotHubCreateUpdate, Read: resourceArmIotHubRead, - Update: resourceArmIotHubCreateAndUpdate, + Update: resourceArmIotHubCreateUpdate, Delete: resourceArmIotHubDelete, Importer: &schema.ResourceImporter{ State: schema.ImportStatePassthrough, @@ -48,7 +49,7 @@ func resourceArmIotHub() *schema.Resource { "name": { Type: schema.TypeString, Required: true, - DiffSuppressFunc: ignoreCaseDiffSuppressFunc, + DiffSuppressFunc: suppress.CaseDifference, ValidateFunc: validation.StringInSlice([]string{ string(devices.B1), string(devices.B2), @@ -63,7 +64,7 @@ func resourceArmIotHub() *schema.Resource { "tier": { Type: schema.TypeString, Required: true, - DiffSuppressFunc: ignoreCaseDiffSuppressFunc, + DiffSuppressFunc: suppress.CaseDifference, ValidateFunc: validation.StringInSlice([]string{ string(devices.Basic), string(devices.Free), @@ -186,7 +187,7 @@ func resourceArmIotHub() *schema.Resource { "encoding": { Type: schema.TypeString, Optional: true, - DiffSuppressFunc: ignoreCaseDiffSuppressFunc, + DiffSuppressFunc: suppress.CaseDifference, ValidateFunc: validation.StringInSlice([]string{ string(eventhub.Avro), string(eventhub.AvroDeflate), @@ -250,7 +251,7 @@ func resourceArmIotHub() *schema.Resource { } -func resourceArmIotHubCreateAndUpdate(d *schema.ResourceData, meta interface{}) error { +func resourceArmIotHubCreateUpdate(d *schema.ResourceData, meta interface{}) error { client := meta.(*ArmClient).iothubResourceClient ctx := meta.(*ArmClient).StopContext subscriptionID := meta.(*ArmClient).subscriptionId @@ -283,21 +284,17 @@ func resourceArmIotHubCreateAndUpdate(d *schema.ResourceData, meta interface{}) routes := expandIoTHubRoutes(d) - routingProperties := devices.RoutingProperties{ - Endpoints: endpoints, - Routes: routes, - } - - iotHubProperties := devices.IotHubProperties{ - Routing: &routingProperties, - } - properties := devices.IotHubDescription{ - Name: utils.String(name), - Location: utils.String(location), - Sku: &skuInfo, - Tags: expandTags(tags), - Properties: &iotHubProperties, + Name: utils.String(name), + Location: utils.String(location), + Sku: skuInfo, + Properties: &devices.IotHubProperties{ + Routing: &devices.RoutingProperties{ + Endpoints: endpoints, + Routes: routes, + }, + }, + Tags: expandTags(tags), } future, err := client.CreateOrUpdate(ctx, resourceGroup, name, properties, "") @@ -359,20 +356,13 @@ func resourceArmIotHubRead(d *schema.ResourceData, meta interface{}) error { if v == nil { continue } + if k == "events" { - if v.Endpoint != nil { - d.Set("event_hub_events_endpoint", *v.Endpoint) - } - if v.Path != nil { - d.Set("event_hub_events_path", *v.Path) - } + d.Set("event_hub_events_endpoint", v.Endpoint) + d.Set("event_hub_events_path", v.Path) } else if k == "operationsMonitoringEvents" { - if v.Endpoint != nil { - d.Set("event_hub_operations_endpoint", *v.Endpoint) - } - if v.Path != nil { - d.Set("event_hub_operations_path", *v.Path) - } + d.Set("event_hub_operations_endpoint", v.Endpoint) + d.Set("event_hub_operations_path", v.Path) } } @@ -568,7 +558,7 @@ func expandIoTHubEndpoints(d *schema.ResourceData, subscriptionId string) (*devi }, nil } -func expandIoTHubSku(d *schema.ResourceData) devices.IotHubSkuInfo { +func expandIoTHubSku(d *schema.ResourceData) *devices.IotHubSkuInfo { skuList := d.Get("sku").([]interface{}) skuMap := skuList[0].(map[string]interface{}) capacity := int64(skuMap["capacity"].(int)) @@ -576,7 +566,7 @@ func expandIoTHubSku(d *schema.ResourceData) devices.IotHubSkuInfo { name := skuMap["name"].(string) tier := skuMap["tier"].(string) - return devices.IotHubSkuInfo{ + return &devices.IotHubSkuInfo{ Name: devices.IotHubSku(name), Tier: devices.IotHubSkuTier(tier), Capacity: utils.Int64(capacity), diff --git a/website/azurerm.erb b/website/azurerm.erb index a2418b22da82..c9c9fa93ec54 100644 --- a/website/azurerm.erb +++ b/website/azurerm.erb @@ -778,7 +778,7 @@ azurerm_eventhub_namespace - > + > azurerm_iothub diff --git a/website/docs/r/iothub.html.markdown b/website/docs/r/iothub.html.markdown index aa843d92563a..42b49a322461 100644 --- a/website/docs/r/iothub.html.markdown +++ b/website/docs/r/iothub.html.markdown @@ -1,14 +1,14 @@ --- layout: "azurerm" page_title: "Azure Resource Manager: azurerm_iothub" -sidebar_current: "docs-azurerm-resource-messaging-iothub" +sidebar_current: "docs-azurerm-resource-messaging-iothub-x" description: |- - Manages a IotHub resource + Manages an IotHub --- # azurerm_iothub -Manages a IotHub +Manages an IotHub ## Example Usage From 6ba4fbc88e7affed0fa88616843084303248fb64 Mon Sep 17 00:00:00 2001 From: tombuildsstuff Date: Sun, 4 Nov 2018 23:28:22 +0000 Subject: [PATCH 2/4] New Resource: `azurerm_iothub_consumer_group` Tests pass: ``` $ acctests azurerm TestAccAzureRMIotHubConsumerGroup_ === RUN TestAccAzureRMIotHubConsumerGroup_events --- PASS: TestAccAzureRMIotHubConsumerGroup_events (280.43s) === RUN TestAccAzureRMIotHubConsumerGroup_operationsMonitoringEvents --- PASS: TestAccAzureRMIotHubConsumerGroup_operationsMonitoringEvents (211.24s) PASS ok github.com/terraform-providers/terraform-provider-azurerm/azurerm 493.476s ``` Fixes #2230 --- azurerm/provider.go | 1 + azurerm/resource_arm_iothub_consumer_group.go | 126 +++++++++++++++ ...resource_arm_iothub_consumer_group_test.go | 148 ++++++++++++++++++ website/azurerm.erb | 4 + .../r/iothub_consumer_group.html.markdown | 69 ++++++++ 5 files changed, 348 insertions(+) create mode 100644 azurerm/resource_arm_iothub_consumer_group.go create mode 100644 azurerm/resource_arm_iothub_consumer_group_test.go create mode 100644 website/docs/r/iothub_consumer_group.html.markdown diff --git a/azurerm/provider.go b/azurerm/provider.go index 8e7bb2f41e29..5d1a9632ae43 100644 --- a/azurerm/provider.go +++ b/azurerm/provider.go @@ -188,6 +188,7 @@ func Provider() terraform.ResourceProvider { "azurerm_function_app": resourceArmFunctionApp(), "azurerm_image": resourceArmImage(), "azurerm_iothub": resourceArmIotHub(), + "azurerm_iothub_consumer_group": resourceArmIotHubConsumerGroup(), "azurerm_key_vault": resourceArmKeyVault(), "azurerm_key_vault_access_policy": resourceArmKeyVaultAccessPolicy(), "azurerm_key_vault_certificate": resourceArmKeyVaultCertificate(), diff --git a/azurerm/resource_arm_iothub_consumer_group.go b/azurerm/resource_arm_iothub_consumer_group.go new file mode 100644 index 000000000000..02cab0eb2845 --- /dev/null +++ b/azurerm/resource_arm_iothub_consumer_group.go @@ -0,0 +1,126 @@ +package azurerm + +import ( + "fmt" + "log" + + "github.com/hashicorp/terraform/helper/schema" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" +) + +func resourceArmIotHubConsumerGroup() *schema.Resource { + return &schema.Resource{ + Create: resourceArmIotHubConsumerGroupCreate, + Read: resourceArmIotHubConsumerGroupRead, + Delete: resourceArmIotHubConsumerGroupDelete, + Importer: &schema.ResourceImporter{ + State: schema.ImportStatePassthrough, + }, + + Schema: map[string]*schema.Schema{ + // TODO: validation + "name": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + }, + + "iothub_name": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + }, + + "eventhub_endpoint_name": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + }, + + "resource_group_name": resourceGroupNameSchema(), + }, + } +} + +func resourceArmIotHubConsumerGroupCreate(d *schema.ResourceData, meta interface{}) error { + client := meta.(*ArmClient).iothubResourceClient + ctx := meta.(*ArmClient).StopContext + log.Printf("[INFO] preparing arguments for AzureRM IoTHub Consumer Group creation.") + + name := d.Get("name").(string) + iotHubName := d.Get("iothub_name").(string) + endpointName := d.Get("eventhub_endpoint_name").(string) + resourceGroup := d.Get("resource_group_name").(string) + + _, err := client.CreateEventHubConsumerGroup(ctx, resourceGroup, iotHubName, endpointName, name) + if err != nil { + return err + } + + read, err := client.GetEventHubConsumerGroup(ctx, resourceGroup, iotHubName, endpointName, name) + if err != nil { + return err + } + + if read.ID == nil { + return fmt.Errorf("Cannot read IoTHub Consumer Group %q (Resource Group %q) ID", name, resourceGroup) + } + + d.SetId(*read.ID) + + return resourceArmIotHubConsumerGroupRead(d, meta) +} + +func resourceArmIotHubConsumerGroupRead(d *schema.ResourceData, meta interface{}) error { + client := meta.(*ArmClient).iothubResourceClient + ctx := meta.(*ArmClient).StopContext + + id, err := parseAzureResourceID(d.Id()) + if err != nil { + return err + } + resourceGroup := id.ResourceGroup + iotHubName := id.Path["IotHubs"] + endpointName := id.Path["eventHubEndpoints"] + name := id.Path["ConsumerGroups"] + + resp, err := client.GetEventHubConsumerGroup(ctx, resourceGroup, iotHubName, endpointName, name) + if err != nil { + if utils.ResponseWasNotFound(resp.Response) { + d.SetId("") + return nil + } + return fmt.Errorf("Error making Read request on IoTHub Consumer Group %s: %+v", name, err) + } + + d.Set("name", name) + d.Set("iothub_name", iotHubName) + d.Set("eventhub_endpoint_name", endpointName) + d.Set("resource_group_name", resourceGroup) + + return nil +} + +func resourceArmIotHubConsumerGroupDelete(d *schema.ResourceData, meta interface{}) error { + client := meta.(*ArmClient).iothubResourceClient + ctx := meta.(*ArmClient).StopContext + + id, err := parseAzureResourceID(d.Id()) + if err != nil { + return err + } + resourceGroup := id.ResourceGroup + iotHubName := id.Path["IotHubs"] + endpointName := id.Path["eventHubEndpoints"] + name := id.Path["ConsumerGroups"] + + resp, err := client.DeleteEventHubConsumerGroup(ctx, resourceGroup, iotHubName, endpointName, name) + + if err != nil { + if !utils.ResponseWasNotFound(resp) { + return fmt.Errorf("Error issuing delete request for IoTHub Consumer Group %q (Resource Group %q): %+v", name, resourceGroup, err) + } + } + + return nil +} diff --git a/azurerm/resource_arm_iothub_consumer_group_test.go b/azurerm/resource_arm_iothub_consumer_group_test.go new file mode 100644 index 000000000000..21d81017e853 --- /dev/null +++ b/azurerm/resource_arm_iothub_consumer_group_test.go @@ -0,0 +1,148 @@ +package azurerm + +import ( + "fmt" + "net/http" + "testing" + + "github.com/hashicorp/terraform/helper/acctest" + "github.com/hashicorp/terraform/helper/resource" + "github.com/hashicorp/terraform/terraform" +) + +func TestAccAzureRMIotHubConsumerGroup_events(t *testing.T) { + resourceName := "azurerm_iothub_consumer_group.test" + rInt := acctest.RandInt() + location := testLocation() + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testCheckAzureRMIotHubConsumerGroupDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMIotHubConsumerGroup_basic(rInt, location, "events"), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMIotHubConsumerGroupExists(resourceName), + resource.TestCheckResourceAttr(resourceName, "eventhub_endpoint_name", "events"), + ), + }, { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func TestAccAzureRMIotHubConsumerGroup_operationsMonitoringEvents(t *testing.T) { + resourceName := "azurerm_iothub_consumer_group.test" + rInt := acctest.RandInt() + location := testLocation() + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testCheckAzureRMIotHubConsumerGroupDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMIotHubConsumerGroup_basic(rInt, location, "operationsMonitoringEvents"), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMIotHubConsumerGroupExists(resourceName), + resource.TestCheckResourceAttr(resourceName, "eventhub_endpoint_name", "operationsMonitoringEvents"), + ), + }, { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func testCheckAzureRMIotHubConsumerGroupDestroy(s *terraform.State) error { + client := testAccProvider.Meta().(*ArmClient).iothubResourceClient + ctx := testAccProvider.Meta().(*ArmClient).StopContext + + for _, rs := range s.RootModule().Resources { + if rs.Type != "azurerm_iothub_consumer_group" { + continue + } + + name := rs.Primary.Attributes["name"] + iotHubName := rs.Primary.Attributes["iothub_name"] + endpointName := rs.Primary.Attributes["eventhub_endpoint_name"] + resourceGroup := rs.Primary.Attributes["resource_group_name"] + + resp, err := client.GetEventHubConsumerGroup(ctx, resourceGroup, iotHubName, endpointName, name) + + if err != nil { + return nil + } + + if resp.StatusCode != http.StatusNotFound { + return fmt.Errorf("Consumer Group %q still exists in Endpoint %q / IotHub %q / Resource Group %q", name, endpointName, iotHubName, resourceGroup) + } + } + return nil +} + +func testCheckAzureRMIotHubConsumerGroupExists(name string) resource.TestCheckFunc { + return func(s *terraform.State) error { + ctx := testAccProvider.Meta().(*ArmClient).StopContext + + rs, ok := s.RootModule().Resources[name] + if !ok { + return fmt.Errorf("Not found: %s", name) + } + + name := rs.Primary.Attributes["name"] + iotHubName := rs.Primary.Attributes["iothub_name"] + endpointName := rs.Primary.Attributes["eventhub_endpoint_name"] + resourceGroup := rs.Primary.Attributes["resource_group_name"] + + client := testAccProvider.Meta().(*ArmClient).iothubResourceClient + resp, err := client.GetEventHubConsumerGroup(ctx, resourceGroup, iotHubName, endpointName, name) + if err != nil { + if resp.StatusCode == http.StatusNotFound { + return fmt.Errorf("Bad: Consumer Group %q (Endpoint %q / IotHub %q / Resource Group: %q) does not exist", name, endpointName, iotHubName, resourceGroup) + } + + return fmt.Errorf("Bad: Get on iothubResourceClient: %+v", err) + } + + return nil + + } +} + +func testAccAzureRMIotHubConsumerGroup_basic(rInt int, location, eventName string) string { + return fmt.Sprintf(` +resource "azurerm_resource_group" "foo" { + name = "acctestRG-%d" + location = "%s" +} + +resource "azurerm_iothub" "test" { + name = "acctestIoTHub-%d" + resource_group_name = "${azurerm_resource_group.foo.name}" + location = "${azurerm_resource_group.foo.location}" + sku { + name = "B1" + tier = "Basic" + capacity = "1" + } + + tags { + "purpose" = "testing" + } +} + +resource "azurerm_iothub_consumer_group" "test" { + name = "test" + iothub_name = "${azurerm_iothub.test.name}" + eventhub_endpoint_name = "%s" + resource_group_name = "${azurerm_resource_group.foo.name}" +} +`, rInt, location, rInt, eventName) +} diff --git a/website/azurerm.erb b/website/azurerm.erb index c9c9fa93ec54..3a05db519ef6 100644 --- a/website/azurerm.erb +++ b/website/azurerm.erb @@ -782,6 +782,10 @@ azurerm_iothub + > + azurerm_iothub_consumer_group + + > azurerm_notification_hub diff --git a/website/docs/r/iothub_consumer_group.html.markdown b/website/docs/r/iothub_consumer_group.html.markdown new file mode 100644 index 000000000000..dfb4fff52580 --- /dev/null +++ b/website/docs/r/iothub_consumer_group.html.markdown @@ -0,0 +1,69 @@ +--- +layout: "azurerm" +page_title: "Azure Resource Manager: azurerm_iothub_consumer_group" +sidebar_current: "docs-azurerm-resource-messaging-iothub-consumer-group" +description: |- + Manages a Consumer Group within an IotHub +--- + +# azurerm_iothub_consumer_group + +Manages a Consumer Group within an IotHub + +## Example Usage + +```hcl +resource "azurerm_resource_group" "test" { + name = "resourceGroup1" + location = "West US" +} + +resource "azurerm_iothub" "test" { + name = "test" + resource_group_name = "${azurerm_resource_group.test.name}" + location = "${azurerm_resource_group.test.location}" + + sku { + name = "S1" + tier = "Standard" + capacity = "1" + } + + tags { + "purpose" = "testing" + } +} + +resource "azurerm_iothub_consumer_group" "test" { + name = "terraform" + iothub_name = "${azurerm_iothub.test.name}" + eventhub_endpoint_name = "events" + resource_group_name = "${azurerm_resource_group.foo.name}" +} +``` + +## Argument Reference + +The following arguments are supported: + +* `name` - (Required) The name of this Consumer Group. Changing this forces a new resource to be created. + +* `iothub_name` - (Required) The name of the IoT Hub. Changing this forces a new resource to be created. + +* `eventhub_endpoint_name` - (Required) The name of the Event Hub-compatible endpoint in the IoT hub. Changing this forces a new resource to be created. + +* `resource_group_name` - (Required) The name of the resource group that contains the IoT hub. Changing this forces a new resource to be created. + +## Attributes Reference + +The following attributes are exported: + +* `id` - The ID of the IoTHub Consumer Group. + +## Import + +IoTHub Consumer Groups can be imported using the `resource id`, e.g. + +```shell +terraform import azurerm_iothub_consumer_group.group1 /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/mygroup1/providers/Microsoft.Devices/IotHubs/hub1/eventHubEndpoints/events/ConsumerGroups/group1 +``` From 393c13bad545fd984e41cf7e8d29752730c9534a Mon Sep 17 00:00:00 2001 From: tombuildsstuff Date: Mon, 5 Nov 2018 12:18:04 +0000 Subject: [PATCH 3/4] adding validation for iothub names Tests pass: ``` === RUN TestValidateIoTHubName --- PASS: TestValidateIoTHubName (0.00s) === RUN TestValidateIoTHubConsumerGroupName --- PASS: TestValidateIoTHubConsumerGroupName (0.00s) PASS ``` --- azurerm/helpers/validate/iothub.go | 28 +++++++++ azurerm/helpers/validate/iothub_test.go | 63 +++++++++++++++++++ azurerm/resource_arm_iothub.go | 8 ++- azurerm/resource_arm_iothub_consumer_group.go | 16 ++--- 4 files changed, 105 insertions(+), 10 deletions(-) create mode 100644 azurerm/helpers/validate/iothub.go create mode 100644 azurerm/helpers/validate/iothub_test.go diff --git a/azurerm/helpers/validate/iothub.go b/azurerm/helpers/validate/iothub.go new file mode 100644 index 000000000000..205717366348 --- /dev/null +++ b/azurerm/helpers/validate/iothub.go @@ -0,0 +1,28 @@ +package validate + +import ( + "fmt" + "regexp" +) + +func IoTHubName(v interface{}, k string) (ws []string, es []error) { + value := v.(string) + + // Portal: The value must contain only alphanumeric characters or the following: - + if matched := regexp.MustCompile(`^[0-9a-zA-Z-]{1,}$`).Match([]byte(value)); !matched { + es = append(es, fmt.Errorf("%q may only contain alphanumeric characters and dashes", k)) + } + + return +} + +func IoTHubConsumerGroupName(v interface{}, k string) (ws []string, es []error) { + value := v.(string) + + // Portal: The value must contain only alphanumeric characters or the following: - . _ + if matched := regexp.MustCompile(`^[0-9a-zA-Z-._]{1,}$`).Match([]byte(value)); !matched { + es = append(es, fmt.Errorf("%q may only contain alphanumeric characters and dashes, periods and underscores", k)) + } + + return +} diff --git a/azurerm/helpers/validate/iothub_test.go b/azurerm/helpers/validate/iothub_test.go new file mode 100644 index 000000000000..d94f92e985dc --- /dev/null +++ b/azurerm/helpers/validate/iothub_test.go @@ -0,0 +1,63 @@ +package validate + +import "testing" + +func TestValidateIoTHubName(t *testing.T) { + validNames := []string{ + "valid-name", + "valid02-name", + "validName1", + "-validname1", + "double-hyphen--valid", + } + for _, v := range validNames { + _, errors := IoTHubName(v, "example") + if len(errors) != 0 { + t.Fatalf("%q should be a valid IoT Hub Name: %q", v, errors) + } + } + + invalidNames := []string{ + "", + "invalid_name", + "invalid!", + "!@£", + "hello.world", + } + for _, v := range invalidNames { + _, errors := IoTHubName(v, "name") + if len(errors) == 0 { + t.Fatalf("%q should be an invalid IoT Hub Name", v) + } + } +} + +func TestValidateIoTHubConsumerGroupName(t *testing.T) { + validNames := []string{ + "valid-name", + "valid02-name", + "validName1", + "-validname1", + "valid_name", + "double-hyphen--valid", + "hello.world", + } + for _, v := range validNames { + _, errors := IoTHubConsumerGroupName(v, "example") + if len(errors) != 0 { + t.Fatalf("%q should be a valid IoT Hub Consumer Group Name: %q", v, errors) + } + } + + invalidNames := []string{ + "", + "invalid!", + "!@£", + } + for _, v := range invalidNames { + _, errors := IoTHubConsumerGroupName(v, "name") + if len(errors) == 0 { + t.Fatalf("%q should be an invalid IoT Hub Consumer Group Name", v) + } + } +} diff --git a/azurerm/resource_arm_iothub.go b/azurerm/resource_arm_iothub.go index a9d8ce7658c1..f0e2d8ea8069 100755 --- a/azurerm/resource_arm_iothub.go +++ b/azurerm/resource_arm_iothub.go @@ -16,6 +16,7 @@ import ( "github.com/hashicorp/terraform/helper/validation" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/response" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/suppress" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/validate" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" ) @@ -31,9 +32,10 @@ func resourceArmIotHub() *schema.Resource { Schema: map[string]*schema.Schema{ "name": { - Type: schema.TypeString, - Required: true, - ForceNew: true, + Type: schema.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: validate.IoTHubName, }, "location": locationSchema(), diff --git a/azurerm/resource_arm_iothub_consumer_group.go b/azurerm/resource_arm_iothub_consumer_group.go index 02cab0eb2845..f7ebaf1b7132 100644 --- a/azurerm/resource_arm_iothub_consumer_group.go +++ b/azurerm/resource_arm_iothub_consumer_group.go @@ -5,6 +5,7 @@ import ( "log" "github.com/hashicorp/terraform/helper/schema" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/validate" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" ) @@ -18,17 +19,18 @@ func resourceArmIotHubConsumerGroup() *schema.Resource { }, Schema: map[string]*schema.Schema{ - // TODO: validation "name": { - Type: schema.TypeString, - Required: true, - ForceNew: true, + Type: schema.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: validate.IoTHubConsumerGroupName, }, "iothub_name": { - Type: schema.TypeString, - Required: true, - ForceNew: true, + Type: schema.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: validate.IoTHubName, }, "eventhub_endpoint_name": { From 89443ab3cb6994484ad94d05466e13aa8fbcfb85 Mon Sep 17 00:00:00 2001 From: tombuildsstuff Date: Tue, 6 Nov 2018 11:37:13 +0000 Subject: [PATCH 4/4] fixing the alignment --- azurerm/resource_arm_iothub_consumer_group_test.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/azurerm/resource_arm_iothub_consumer_group_test.go b/azurerm/resource_arm_iothub_consumer_group_test.go index 21d81017e853..afd5b551b282 100644 --- a/azurerm/resource_arm_iothub_consumer_group_test.go +++ b/azurerm/resource_arm_iothub_consumer_group_test.go @@ -119,7 +119,7 @@ func testCheckAzureRMIotHubConsumerGroupExists(name string) resource.TestCheckFu func testAccAzureRMIotHubConsumerGroup_basic(rInt int, location, eventName string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "foo" { - name = "acctestRG-%d" + name = "acctestRG-%d" location = "%s" } @@ -127,9 +127,10 @@ resource "azurerm_iothub" "test" { name = "acctestIoTHub-%d" resource_group_name = "${azurerm_resource_group.foo.name}" location = "${azurerm_resource_group.foo.location}" + sku { - name = "B1" - tier = "Basic" + name = "B1" + tier = "Basic" capacity = "1" }