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

azurerm_iothub - Support for public_network_access_enabled #8586

Merged
merged 5 commits into from
Oct 2, 2020
Merged
Show file tree
Hide file tree
Changes from 4 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/internal/services/iothub/client/client.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package client

import (
"github.com/Azure/azure-sdk-for-go/services/preview/iothub/mgmt/2019-03-22-preview/devices"
"github.com/Azure/azure-sdk-for-go/services/iothub/mgmt/2020-03-01/devices"
"github.com/Azure/azure-sdk-for-go/services/provisioningservices/mgmt/2018-01-22/iothub"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/common"
)
Expand Down
2 changes: 1 addition & 1 deletion azurerm/internal/services/iothub/iothub_dps_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"strconv"
"time"

"github.com/Azure/azure-sdk-for-go/services/preview/iothub/mgmt/2019-03-22-preview/devices"
"github.com/Azure/azure-sdk-for-go/services/iothub/mgmt/2020-03-01/devices"
"github.com/Azure/azure-sdk-for-go/services/provisioningservices/mgmt/2018-01-22/iothub"
"github.com/hashicorp/go-azure-helpers/response"
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"strings"
"time"

"github.com/Azure/azure-sdk-for-go/services/preview/iothub/mgmt/2019-03-22-preview/devices"
"github.com/Azure/azure-sdk-for-go/services/iothub/mgmt/2020-03-01/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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"strings"
"time"

"github.com/Azure/azure-sdk-for-go/services/preview/iothub/mgmt/2019-03-22-preview/devices"
"github.com/Azure/azure-sdk-for-go/services/iothub/mgmt/2020-03-01/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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"strings"
"time"

"github.com/Azure/azure-sdk-for-go/services/preview/iothub/mgmt/2019-03-22-preview/devices"
"github.com/Azure/azure-sdk-for-go/services/iothub/mgmt/2020-03-01/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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"strings"
"time"

"github.com/Azure/azure-sdk-for-go/services/preview/iothub/mgmt/2019-03-22-preview/devices"
"github.com/Azure/azure-sdk-for-go/services/iothub/mgmt/2020-03-01/devices"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/helper/validation"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"
"time"

"github.com/Azure/azure-sdk-for-go/services/preview/iothub/mgmt/2019-03-22-preview/devices"
"github.com/Azure/azure-sdk-for-go/services/iothub/mgmt/2020-03-01/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/validate"
Expand Down
20 changes: 19 additions & 1 deletion azurerm/internal/services/iothub/iothub_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"strings"
"time"

"github.com/Azure/azure-sdk-for-go/services/preview/iothub/mgmt/2019-03-22-preview/devices"
"github.com/Azure/azure-sdk-for-go/services/iothub/mgmt/2020-03-01/devices"
"github.com/hashicorp/go-azure-helpers/response"
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
Expand Down Expand Up @@ -403,6 +403,11 @@ func resourceArmIotHub() *schema.Resource {
},
},

"public_network_access": {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be public_network_access_enabled ?

Type: schema.TypeBool,
Optional: true,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this need to default to enabled? it'd be good to confirm with the portal's behaviour

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you don't specify it when creating an iothub, it doesn't get returned by the api so I don't think we can default it without breaking people.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're required to specify it when creating it in the portal. I believe this functionality was added recently. I imagine it's on by default but the api doesn't return it if a user didn't specify it when creating.

image

},

"type": {
Type: schema.TypeString,
Computed: true,
Expand Down Expand Up @@ -508,6 +513,15 @@ func resourceArmIotHubCreateUpdate(d *schema.ResourceData, meta interface{}) err
Tags: tags.Expand(d.Get("tags").(map[string]interface{})),
}

// nolint staticcheck
if v, ok := d.GetOkExists("public_network_access"); ok {
enabled := devices.Disabled
if v.(bool) {
enabled = devices.Enabled
}
props.Properties.PublicNetworkAccess = enabled
}

retention, retentionOk := d.GetOk("event_hub_retention_in_days")
partition, partitionOk := d.GetOk("event_hub_partition_count")
if partitionOk || retentionOk {
Expand Down Expand Up @@ -621,6 +635,10 @@ func resourceArmIotHubRead(d *schema.ResourceData, meta interface{}) error {
if err := d.Set("file_upload", fileUpload); err != nil {
return fmt.Errorf("Error setting `file_upload` in IoTHub %q: %+v", name, err)
}

if enabled := properties.PublicNetworkAccess; enabled != "" {
d.Set("public_network_access", enabled == devices.Enabled)
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

couldn't we could make this:

Suggested change
}
publicNetworkAccessEnabled := properties.PublicNetworkAccess == devices.Enabled
d.Set("public_network_access", publicNetworkAccessEnabled)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure could

}

d.Set("name", name)
Expand Down
2 changes: 1 addition & 1 deletion azurerm/internal/services/iothub/iothub_route_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"strings"
"time"

"github.com/Azure/azure-sdk-for-go/services/preview/iothub/mgmt/2019-03-22-preview/devices"
"github.com/Azure/azure-sdk-for-go/services/iothub/mgmt/2020-03-01/devices"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/helper/validation"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"strings"
"time"

"github.com/Azure/azure-sdk-for-go/services/preview/iothub/mgmt/2019-03-22-preview/devices"
"github.com/Azure/azure-sdk-for-go/services/iothub/mgmt/2020-03-01/devices"
"github.com/hashicorp/go-multierror"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/helper/validation"
Expand Down
102 changes: 101 additions & 1 deletion azurerm/internal/services/iothub/tests/iothub_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,46 @@ func TestAccAzureRMIotHub_fallbackRoute(t *testing.T) {
})
}

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

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acceptance.PreCheck(t) },
Providers: acceptance.SupportedProviders,
CheckDestroy: testCheckAzureRMIotHubDestroy,
Steps: []resource.TestStep{
{
Config: testAccAzureRMIotHub_basic(data),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMIotHubExists(data.ResourceName),
),
},
data.ImportStep(),
{
Config: testAccAzureRMIotHub_publicAccessEnabled(data),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMIotHubExists(data.ResourceName),
),
},
data.ImportStep(),
{
Config: testAccAzureRMIotHub_publicAccessDisabled(data),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMIotHubExists(data.ResourceName),
),
},
data.ImportStep(),
{
Config: testAccAzureRMIotHub_basic(data),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMIotHubExists(data.ResourceName),
),
},
data.ImportStep(),
},
})
}

func testCheckAzureRMIotHubDestroy(s *terraform.State) error {
client := acceptance.AzureProvider.Meta().(*clients.Client).IoTHub.ResourceClient
ctx := acceptance.AzureProvider.Meta().(*clients.Client).StopContext
Expand Down Expand Up @@ -242,7 +282,7 @@ provider "azurerm" {
}

resource "azurerm_resource_group" "test" {
name = "acctestRG-%d"
name = "acctestRG-iothub-%d"
location = "%s"
}

Expand Down Expand Up @@ -601,3 +641,63 @@ resource "azurerm_iothub" "test" {
}
`, data.RandomInteger, data.Locations.Primary, data.RandomString, data.RandomInteger)
}

func testAccAzureRMIotHub_publicAccessEnabled(data acceptance.TestData) string {
return fmt.Sprintf(`
provider "azurerm" {
features {}
}

resource "azurerm_resource_group" "test" {
name = "acctestRG-iothub-%d"
location = "%s"
}

resource "azurerm_iothub" "test" {
name = "acctestIoTHub-%d"
resource_group_name = azurerm_resource_group.test.name
location = azurerm_resource_group.test.location

sku {
name = "B1"
capacity = "1"
}

public_network_access = true

tags = {
purpose = "testing"
}
}
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger)
}

func testAccAzureRMIotHub_publicAccessDisabled(data acceptance.TestData) string {
return fmt.Sprintf(`
provider "azurerm" {
features {}
}

resource "azurerm_resource_group" "test" {
name = "acctestRG-iothub-%d"
location = "%s"
}

resource "azurerm_iothub" "test" {
name = "acctestIoTHub-%d"
resource_group_name = azurerm_resource_group.test.name
location = azurerm_resource_group.test.location

sku {
name = "B1"
capacity = "1"
}

public_network_access = false

tags = {
purpose = "testing"
}
}
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger)
}

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.

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