Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IoTHub: support for the Basic SKU #1717

Merged
merged 1 commit into from
Aug 3, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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