Skip to content

Commit

Permalink
Support for IoTHub Basic / upgrading to v2018-04-01 fo the IoTHub SDK
Browse files Browse the repository at this point in the history
  • Loading branch information
tombuildsstuff committed Aug 3, 2018
1 parent 2f330a6 commit dbec340
Show file tree
Hide file tree
Showing 13 changed files with 982 additions and 141 deletions.
2 changes: 1 addition & 1 deletion azurerm/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
"github.com/Azure/azure-sdk-for-go/services/eventgrid/mgmt/2018-01-01/eventgrid"
"github.com/Azure/azure-sdk-for-go/services/eventhub/mgmt/2017-04-01/eventhub"
"github.com/Azure/azure-sdk-for-go/services/graphrbac/1.6/graphrbac"
"github.com/Azure/azure-sdk-for-go/services/iothub/mgmt/2017-07-01/devices"
"github.com/Azure/azure-sdk-for-go/services/iothub/mgmt/2018-04-01/devices"
keyVault "github.com/Azure/azure-sdk-for-go/services/keyvault/2016-10-01/keyvault"
"github.com/Azure/azure-sdk-for-go/services/keyvault/mgmt/2016-10-01/keyvault"
"github.com/Azure/azure-sdk-for-go/services/logic/mgmt/2016-06-01/logic"
Expand Down
25 changes: 24 additions & 1 deletion azurerm/import_arm_iothub_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,30 @@ func TestAccAzureRMIotHub_importBasic(t *testing.T) {
resourceName := "azurerm_iothub.test"

ri := acctest.RandInt()
config := testAccAzureRMIotHub_basicStandard(ri, testLocation())
config := testAccAzureRMIotHub_basic(ri, testLocation())

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMIotHubDestroy,
Steps: []resource.TestStep{
{
Config: config,
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func TestAccAzureRMIotHub_importStandard(t *testing.T) {
resourceName := "azurerm_iothub.test"

ri := acctest.RandInt()
config := testAccAzureRMIotHub_standard(ri, testLocation())

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Expand Down
21 changes: 11 additions & 10 deletions azurerm/resource_arm_iothub.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"strconv"
"time"

"github.com/Azure/azure-sdk-for-go/services/iothub/mgmt/2017-07-01/devices"
"github.com/Azure/azure-sdk-for-go/services/iothub/mgmt/2018-04-01/devices"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/helper/schema"
"github.com/hashicorp/terraform/helper/validation"
Expand Down Expand Up @@ -47,6 +47,9 @@ func resourceArmIotHub() *schema.Resource {
Required: true,
DiffSuppressFunc: ignoreCaseDiffSuppressFunc,
ValidateFunc: validation.StringInSlice([]string{
string(devices.B1),
string(devices.B2),
string(devices.B3),
string(devices.F1),
string(devices.S1),
string(devices.S2),
Expand All @@ -59,6 +62,7 @@ func resourceArmIotHub() *schema.Resource {
Required: true,
DiffSuppressFunc: ignoreCaseDiffSuppressFunc,
ValidateFunc: validation.StringInSlice([]string{
string(devices.Basic),
string(devices.Free),
string(devices.Standard),
}, true),
Expand Down Expand Up @@ -119,7 +123,6 @@ func resourceArmIotHub() *schema.Resource {
func resourceArmIotHubCreateAndUpdate(d *schema.ResourceData, meta interface{}) error {
client := meta.(*ArmClient).iothubResourceClient
ctx := meta.(*ArmClient).StopContext
subscriptionID := meta.(*ArmClient).subscriptionId

name := d.Get("name").(string)
resourceGroup := d.Get("resource_group_name").(string)
Expand All @@ -143,12 +146,10 @@ func resourceArmIotHubCreateAndUpdate(d *schema.ResourceData, meta interface{})
tags := d.Get("tags").(map[string]interface{})

properties := devices.IotHubDescription{
Name: utils.String(name),
Location: utils.String(location),
Resourcegroup: utils.String(resourceGroup),
Subscriptionid: utils.String(subscriptionID),
Sku: &skuInfo,
Tags: expandTags(tags),
Name: utils.String(name),
Location: utils.String(location),
Sku: &skuInfo,
Tags: expandTags(tags),
}

future, err := client.CreateOrUpdate(ctx, resourceGroup, name, properties, "")
Expand Down Expand Up @@ -282,15 +283,15 @@ func iothubStateStatusCodeRefreshFunc(ctx context.Context, client devices.IotHub
func expandIoTHubSku(d *schema.ResourceData) devices.IotHubSkuInfo {
skuList := d.Get("sku").([]interface{})
skuMap := skuList[0].(map[string]interface{})
cap := int64(skuMap["capacity"].(int))
capacity := int64(skuMap["capacity"].(int))

name := skuMap["name"].(string)
tier := skuMap["tier"].(string)

return devices.IotHubSkuInfo{
Name: devices.IotHubSku(name),
Tier: devices.IotHubSkuTier(tier),
Capacity: &cap,
Capacity: utils.Int64(capacity),
}
}

Expand Down
47 changes: 44 additions & 3 deletions azurerm/resource_arm_iothub_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/hashicorp/terraform/terraform"
)

func TestAccAzureRMIotHub_basicStandard(t *testing.T) {
func TestAccAzureRMIotHub_basic(t *testing.T) {
rInt := acctest.RandInt()

resource.Test(t, resource.TestCase{
Expand All @@ -19,14 +19,31 @@ func TestAccAzureRMIotHub_basicStandard(t *testing.T) {
CheckDestroy: testCheckAzureRMIotHubDestroy,
Steps: []resource.TestStep{
{
Config: testAccAzureRMIotHub_basicStandard(rInt, testLocation()),
Config: testAccAzureRMIotHub_basic(rInt, testLocation()),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMIotHubExists("azurerm_iothub.test"),
),
},
},
})
}

func TestAccAzureRMIotHub_standard(t *testing.T) {
rInt := acctest.RandInt()

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMIotHubDestroy,
Steps: []resource.TestStep{
{
Config: testAccAzureRMIotHub_standard(rInt, testLocation()),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMIotHubExists("azurerm_iothub.test"),
),
},
},
})
}

func testCheckAzureRMIotHubDestroy(s *terraform.State) error {
Expand Down Expand Up @@ -83,7 +100,31 @@ func testCheckAzureRMIotHubExists(name string) resource.TestCheckFunc {
}
}

func testAccAzureRMIotHub_basicStandard(rInt int, location string) string {
func testAccAzureRMIotHub_basic(rInt int, location 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"
}
}
`, rInt, location, rInt)
}

func testAccAzureRMIotHub_standard(rInt int, location string) string {
return fmt.Sprintf(`
resource "azurerm_resource_group" "foo" {
name = "acctestRG-%d"
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit dbec340

Please sign in to comment.