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_dps - support for data_residency_enabled property #18151

Merged
merged 1 commit into from
Aug 30, 2022
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
15 changes: 15 additions & 0 deletions internal/services/iothub/iothub_dps_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,13 @@ func resourceIotHubDPS() *pluginsdk.Resource {
}, false),
},

"data_residency_enabled": {
Type: pluginsdk.TypeBool,
Optional: true,
ForceNew: true,
Default: false,
},

"public_network_access_enabled": {
Type: pluginsdk.TypeBool,
Optional: true,
Expand Down Expand Up @@ -229,6 +236,7 @@ func resourceIotHubDPSCreateUpdate(d *pluginsdk.ResourceData, meta interface{})
Properties: &iothub.IotDpsPropertiesDescription{
IotHubs: expandIoTHubDPSIoTHubs(d.Get("linked_hub").([]interface{})),
AllocationPolicy: iothub.AllocationPolicy(d.Get("allocation_policy").(string)),
EnableDataResidency: utils.Bool(d.Get("data_residency_enabled").(bool)),
IPFilterRules: expandDpsIPFilterRules(d),
PublicNetworkAccess: publicNetworkAccess,
},
Expand Down Expand Up @@ -293,6 +301,13 @@ func resourceIotHubDPSRead(d *pluginsdk.ResourceData, meta interface{}) error {
d.Set("device_provisioning_host_name", props.DeviceProvisioningHostName)
d.Set("id_scope", props.IDScope)
d.Set("allocation_policy", string(props.AllocationPolicy))

enableDataResidency := false
if props.EnableDataResidency != nil {
enableDataResidency = *props.EnableDataResidency
}
d.Set("data_residency_enabled", enableDataResidency)

publicNetworkAccess := true
if props.PublicNetworkAccess != "" {
publicNetworkAccess = strings.EqualFold("Enabled", string(props.PublicNetworkAccess))
Expand Down
44 changes: 44 additions & 0 deletions internal/services/iothub/iothub_dps_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ func TestAccIotHubDPS_basic(t *testing.T) {
check.That(data.ResourceName).Key("device_provisioning_host_name").Exists(),
check.That(data.ResourceName).Key("id_scope").Exists(),
check.That(data.ResourceName).Key("service_operations_host_name").Exists(),
check.That(data.ResourceName).Key("data_residency_enabled").HasValue("false"),
),
},
data.ImportStep(),
Expand Down Expand Up @@ -76,6 +77,21 @@ func TestAccIotHubDPS_update(t *testing.T) {
})
}

func TestAccIotHubDPS_dataResidencyEnabled(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_iothub_dps", "test")
r := IotHubDPSResource{}

data.ResourceTest(t, r, []acceptance.TestStep{
{
Config: r.dataResidencyEnabled(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep(),
})
}

func TestAccIotHubDPS_linkedHubs(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_iothub_dps", "test")
r := IotHubDPSResource{}
Expand Down Expand Up @@ -228,6 +244,34 @@ resource "azurerm_iothub_dps" "test" {
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger)
}

func (IotHubDPSResource) dataResidencyEnabled(data acceptance.TestData) string {
// Data residency has limited region support
data.Locations.Primary = "brazilsouth"
return fmt.Sprintf(`
provider "azurerm" {
features {}
}

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

resource "azurerm_iothub_dps" "test" {
name = "acctestIoTDPS-%d"
resource_group_name = azurerm_resource_group.test.name
location = azurerm_resource_group.test.location

data_residency_enabled = true

sku {
name = "S1"
capacity = "1"
}
}
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger)
}

func (IotHubDPSResource) linkedHubs(data acceptance.TestData) string {
return fmt.Sprintf(`
provider "azurerm" {
Expand Down
2 changes: 2 additions & 0 deletions website/docs/r/iothub_dps.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ The following arguments are supported:

* `allocation_policy` - (Optional) The allocation policy of the IoT Device Provisioning Service (`Hashed`, `GeoLatency` or `Static`). Defaults to `Hashed`.

* `data_residency_enabled` - (Optional) Specifies if the IoT Device Provisioning Service has data residency and disaster recovery enabled. Defaults to `false`.

* `sku` - (Required) A `sku` block as defined below.

* `linked_hub` - (Optional) A `linked_hub` block as defined below.
Expand Down