Skip to content

Commit

Permalink
Update iothub to 2.0 (#5790)
Browse files Browse the repository at this point in the history
  • Loading branch information
mbfrahry authored Feb 19, 2020
1 parent 637fab5 commit b1d5967
Show file tree
Hide file tree
Showing 25 changed files with 41 additions and 110 deletions.
16 changes: 1 addition & 15 deletions azurerm/internal/services/iothub/resource_arm_iothub.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,20 +94,7 @@ func resourceArmIotHub() *schema.Resource {
string(devices.S1),
string(devices.S2),
string(devices.S3),
}, true), // todo 2.0 make this case sensitive (all constants?)
},

"tier": {
Type: schema.TypeString,
Optional: true,
Computed: true,
Deprecated: "This property is no longer required and will be removed in version 2.0 of the provider",
DiffSuppressFunc: suppress.CaseDifference,
ValidateFunc: validation.StringInSlice([]string{
string(devices.Basic),
string(devices.Free),
string(devices.Standard),
}, true),
}, false),
},

"capacity": {
Expand Down Expand Up @@ -880,7 +867,6 @@ func flattenIoTHubSku(input *devices.IotHubSkuInfo) []interface{} {
output := make(map[string]interface{})

output["name"] = string(input.Name)
output["tier"] = string(input.Tier)
if capacity := input.Capacity; capacity != nil {
output["capacity"] = int(*capacity)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func resourceArmIotHubConsumerGroupCreate(d *schema.ResourceData, meta interface
resourceGroup := d.Get("resource_group_name").(string)

if features.ShouldResourcesBeImported() && d.IsNewResource() {
existing, err := client.Get(ctx, resourceGroup, name)
existing, err := client.GetEventHubConsumerGroup(ctx, resourceGroup, iotHubName, endpointName, name)
if err != nil {
if !utils.ResponseWasNotFound(existing.Response) {
return fmt.Errorf("Error checking for presence of existing Consumer Group %q (Endpoint %q / IoTHub %q / Resource Group %q): %s", name, endpointName, iotHubName, resourceGroup, err)
Expand Down
15 changes: 1 addition & 14 deletions azurerm/internal/services/iothub/resource_arm_iothub_dps.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,19 +73,7 @@ func resourceArmIotHubDPS() *schema.Resource {
string(devices.S1),
string(devices.S2),
string(devices.S3),
}, true), // todo 2.0 make this case sensitive
},

"tier": {
Type: schema.TypeString,
Optional: true,
Computed: true,
Deprecated: "This property is no longer required and will be removed in version 2.0 of the provider",
ValidateFunc: validation.StringInSlice([]string{
string(devices.Basic),
string(devices.Free),
string(devices.Standard),
}, true),
}, false),
},

"capacity": {
Expand Down Expand Up @@ -354,7 +342,6 @@ func flattenIoTHubDPSSku(input *iothub.IotDpsSkuInfo) []interface{} {
output := make(map[string]interface{})

output["name"] = string(input.Name)
output["tier"] = input.Tier
if capacity := input.Capacity; capacity != nil {
output["capacity"] = int(*capacity)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@ import (
"github.com/Azure/azure-sdk-for-go/services/preview/iothub/mgmt/2018-12-01-preview/devices"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/validate"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/locks"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils"
Expand Down Expand Up @@ -90,17 +88,15 @@ func resourceArmIotHubFallbackRouteCreateUpdate(d *schema.ResourceData, meta int
return fmt.Errorf("Error loading IotHub %q (Resource Group %q): %+v", iothubName, resourceGroup, err)
}

// NOTE: this resource intentionally doesn't support Requires Import
// since a fallback route is created by default

routing := iothub.Properties.Routing

if routing == nil {
routing = &devices.RoutingProperties{}
}

resourceId := fmt.Sprintf("%s/FallbackRoute/defined", *iothub.ID)
if d.IsNewResource() && routing.FallbackRoute != nil && features.ShouldResourcesBeImported() {
return tf.ImportAsExistsError("azurerm_iothub_fallback_route", resourceId)
}

routing.FallbackRoute = &devices.FallbackRouteProperties{
Source: utils.String(string(devices.RoutingSourceDeviceMessages)),
Condition: utils.String(d.Get("condition").(string)),
Expand All @@ -117,6 +113,7 @@ func resourceArmIotHubFallbackRouteCreateUpdate(d *schema.ResourceData, meta int
return fmt.Errorf("Error waiting for the completion of the creating/updating of IotHub %q (Resource Group %q): %+v", iothubName, resourceGroup, err)
}

resourceId := fmt.Sprintf("%s/FallbackRoute/defined", *iothub.ID)
d.SetId(resourceId)

return resourceArmIotHubFallbackRouteRead(d, meta)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,6 @@ resource "azurerm_iothub" "test" {
sku {
name = "B1"
tier = "Basic"
capacity = "1"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func TestAccAzureRMIotHubDPSCertificate_requiresImport(t *testing.T) {
},
{
Config: testAccAzureRMIotHubDPSCertificate_requiresImport(data),
ExpectError: acceptance.RequiresImportError("azurerm_iothubdps"),
ExpectError: acceptance.RequiresImportError("azurerm_iothub_dps_certificate"),
},
},
})
Expand Down Expand Up @@ -169,11 +169,11 @@ resource "azurerm_iothub_dps_certificate" "test" {
}

func testAccAzureRMIotHubDPSCertificate_requiresImport(data acceptance.TestData) string {
template := testAccAzureRMIotHubDPS_basic(data)
template := testAccAzureRMIotHubDPSCertificate_basic(data)
return fmt.Sprintf(`
%s
resource "azurerm_iothub_dps_certificate" "test" {
resource "azurerm_iothub_dps_certificate" "import" {
name = "${azurerm_iothub_dps_certificate.test.name}"
resource_group_name = "${azurerm_resource_group.test.name}"
iot_dps_name = "${azurerm_iothub_dps.test.name}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ func testCheckAzureRMIotHubDpsSharedAccessPolicyDestroy(s *terraform.State) erro

for _, sharedAccessPolicy := range *resp.Properties.AuthorizationPolicies {
if *sharedAccessPolicy.KeyName == keyName {
return fmt.Errorf("Bad: Shared Access Policy %s still exists on IoTHb DPS %s", keyName, iothubDpsName)
return fmt.Errorf("Bad: Shared Access Policy %s still exists on IoTHub DPS %s", keyName, iothubDpsName)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func TestAccAzureRMIotHubDPS_requiresImport(t *testing.T) {
},
{
Config: testAccAzureRMIotHubDPS_requiresImport(data),
ExpectError: acceptance.RequiresImportError("azurerm_iothubdps"),
ExpectError: acceptance.RequiresImportError("azurerm_iothub_dps"),
},
},
})
Expand Down Expand Up @@ -119,7 +119,7 @@ func testCheckAzureRMIotHubDPSDestroy(s *terraform.State) error {
ctx := acceptance.AzureProvider.Meta().(*clients.Client).StopContext

for _, rs := range s.RootModule().Resources {
if rs.Type != "azurerm_iothubdps" {
if rs.Type != "azurerm_iothub_dps" {
continue
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ resource "azurerm_iothub" "test" {
sku {
name = "B1"
tier = "Basic"
capacity = "1"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ resource "azurerm_iothub" "test" {
sku {
name = "B1"
tier = "Basic"
capacity = "1"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ resource "azurerm_iothub" "test" {
sku {
name = "B1"
tier = "Basic"
capacity = "1"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ resource "azurerm_storage_account" "test" {
resource "azurerm_storage_container" "test" {
name = "acctestcont"
resource_group_name = "${azurerm_resource_group.test.name}"
storage_account_name = "${azurerm_storage_account.test.name}"
container_access_type = "private"
}
Expand All @@ -92,7 +91,6 @@ resource "azurerm_iothub" "test" {
sku {
name = "B1"
tier = "Basic"
capacity = "1"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ import (
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils"
)

// NOTE: this resource intentionally doesn't support Requires Import
// since a fallback route is created by default

func TestAccAzureRMIotHubFallbackRoute_basic(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_iothub_fallback_route", "test")

Expand All @@ -32,33 +34,6 @@ func TestAccAzureRMIotHubFallbackRoute_basic(t *testing.T) {
})
}

func TestAccAzureRMIotHubFallbackRoute_requiresImport(t *testing.T) {
if !features.ShouldResourcesBeImported() {
t.Skip("Skipping since resources aren't required to be imported")
return
}

data := acceptance.BuildTestData(t, "azurerm_iothub_fallback_route", "test")

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acceptance.PreCheck(t) },
Providers: acceptance.SupportedProviders,
CheckDestroy: testCheckAzureRMIotHubDestroy,
Steps: []resource.TestStep{
{
Config: testAccAzureRMIotHubFallbackRoute_basic(data),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMIotHubFallbackRouteExists(data.ResourceName),
),
},
{
Config: testAccAzureRMIotHubFallbackRoute_requiresImport(data),
ExpectError: acceptance.RequiresImportError("azurerm_iothub_fallback_route"),
},
},
})
}

func TestAccAzureRMIotHubFallbackRoute_update(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_iothub_fallback_route", "test")

Expand Down Expand Up @@ -148,23 +123,6 @@ func testCheckAzureRMIotHubFallbackRouteExists(resourceName string) resource.Tes
}
}

func testAccAzureRMIotHubFallbackRoute_requiresImport(data acceptance.TestData) string {
template := testAccAzureRMIotHub_basic(data)
return fmt.Sprintf(`
%s
resource "azurerm_iothub_fallback_route" "import" {
resource_group_name = "${azurerm_resource_group.test.name}"
iothub_name = "${azurerm_iothub.test.name}"
source = "DeviceMessages"
condition = "true"
endpoint_names = ["${azurerm_iothub_endpoint_storage_container.test.name}"]
enabled = true
}
`, template)
}

func testAccAzureRMIotHubFallbackRoute_basic(data acceptance.TestData) string {
return fmt.Sprintf(`
resource "azurerm_resource_group" "test" {
Expand All @@ -182,7 +140,6 @@ resource "azurerm_storage_account" "test" {
resource "azurerm_storage_container" "test" {
name = "test-%[1]d"
resource_group_name = "${azurerm_resource_group.test.name}"
storage_account_name = "${azurerm_storage_account.test.name}"
container_access_type = "private"
}
Expand Down Expand Up @@ -243,7 +200,6 @@ resource "azurerm_storage_account" "test" {
resource "azurerm_storage_container" "test" {
name = "test-%[1]d"
resource_group_name = "${azurerm_resource_group.test.name}"
storage_account_name = "${azurerm_storage_account.test.name}"
container_access_type = "private"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,6 @@ resource "azurerm_storage_account" "test" {
resource "azurerm_storage_container" "test" {
name = "test%[1]d"
resource_group_name = "${azurerm_resource_group.test.name}"
storage_account_name = "${azurerm_storage_account.test.name}"
container_access_type = "private"
}
Expand Down Expand Up @@ -269,7 +268,6 @@ resource "azurerm_storage_account" "test" {
resource "azurerm_storage_container" "test" {
name = "test%[1]d"
resource_group_name = "${azurerm_resource_group.test.name}"
storage_account_name = "${azurerm_storage_account.test.name}"
container_access_type = "private"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ resource "azurerm_iothub" "test" {
sku {
name = "B1"
tier = "Basic"
capacity = "1"
}
Expand Down Expand Up @@ -146,7 +145,6 @@ resource "azurerm_iothub" "test" {
sku {
name = "B1"
tier = "Basic"
capacity = "1"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,6 @@ resource "azurerm_iothub" "import" {
sku {
name = "B1"
tier = "Basic"
capacity = "1"
}
Expand Down Expand Up @@ -333,7 +332,6 @@ resource "azurerm_storage_account" "test" {
resource "azurerm_storage_container" "test" {
name = "test"
resource_group_name = "${azurerm_resource_group.test.name}"
storage_account_name = "${azurerm_storage_account.test.name}"
container_access_type = "private"
}
Expand Down Expand Up @@ -461,7 +459,6 @@ resource "azurerm_storage_account" "test" {
resource "azurerm_storage_container" "test" {
name = "test"
resource_group_name = "${azurerm_resource_group.test.name}"
storage_account_name = "${azurerm_storage_account.test.name}"
container_access_type = "private"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ func resourceArmMySQLConfigurationCreate(d *schema.ResourceData, meta interface{
},
}

// NOTE: this resource intentionally doesn't support Requires Import
// since a fallback route is created by default

future, err := client.CreateOrUpdate(ctx, resourceGroup, serverName, name, properties)
if err != nil {
return fmt.Errorf("Error issuing create/update request for MySQL Configuration %s (resource group %s, server name %s): %v", name, resourceGroup, serverName, err)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ func resourceArmPostgreSQLConfigurationCreateUpdate(d *schema.ResourceData, meta
},
}

// NOTE: this resource intentionally doesn't support Requires Import
// since a fallback route is created by default

future, err := client.CreateOrUpdate(ctx, resGroup, serverName, name, properties)
if err != nil {
return err
Expand Down
4 changes: 4 additions & 0 deletions website/docs/guides/2.0-upgrade-guide.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -327,10 +327,14 @@ The deprecated `internal_public_ip_address_id` field in the `ip_configuration` b

The deprecated `sku.tier` property will be remove.

The `sku.name` property is now case sensitive.

### Resource: `azurerm_iothub_dps`

The deprecated `sku.tier` property will be remove.

The `sku.name` property is now case sensitive.

### Resource: `azurerm_iot_dps`

This resource has been renamed to `azurerm_iothub_dps` which is available from v1.37 of the AzureRM Provider - instructions on [how to migrate are available in this guide](https://terraform.io/docs/providers/azurerm/guides/migrating-between-renamed-resources.html). As such this resource will be removed.
Expand Down
4 changes: 1 addition & 3 deletions website/docs/r/iothub.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -145,12 +145,10 @@ A `sku` block supports the following:

* `name` - (Required) The name of the sku. Possible values are `B1`, `B2`, `B3`, `F1`, `S1`, `S2`, and `S3`.

* `tier` - (Required) The billing tier for the IoT Hub. Possible values are `Basic`, `Free` or `Standard`.
* `capacity` - (Required) The number of provisioned IoT Hub units.

~> **NOTE:** Only one IotHub can be on the `Free` tier per subscription.

* `capacity` - (Required) The number of provisioned IoT Hub units.

---

An `endpoint` block supports the following:
Expand Down
Loading

0 comments on commit b1d5967

Please sign in to comment.