Skip to content

Commit

Permalink
azurerm_iothub_dps - support data_residency_enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
myc2h6o committed Aug 28, 2022
1 parent ef5eec6 commit 15921b0
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 0 deletions.
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

0 comments on commit 15921b0

Please sign in to comment.