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

d/azurerm_public_ips: Deprecate attached for attachment_status #13500

Merged
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
32 changes: 30 additions & 2 deletions internal/services/network/public_ips_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,27 @@ func dataSourcePublicIPs() *pluginsdk.Resource {
Optional: true,
},

// TODO - Remove in 3.0.
"attached": {
Type: pluginsdk.TypeBool,
Type: pluginsdk.TypeBool,
Optional: true,
Deprecated: "This property has been deprecated in favour of `attachment_status` to improve filtering",
ConflictsWith: []string{
"attachment_status",
},
},

"attachment_status": {
Type: pluginsdk.TypeString,
Optional: true,
ValidateFunc: validation.StringInSlice([]string{
"Attached",
"Unattached",
"All", // TODO - Remove "All" in 3.0.
}, false),
ConflictsWith: []string{
"attached",
},
},

"allocation_type": {
Expand Down Expand Up @@ -99,8 +117,18 @@ func dataSourcePublicIPsRead(d *pluginsdk.ResourceData, meta interface{}) error
}
}

attachmentStatus, attachmentStatusOk := d.GetOk("attachment_status")
aristosvo marked this conversation as resolved.
Show resolved Hide resolved
if attachmentStatusOk && attachmentStatus.(string) == "Attached" && !nicIsAttached {
continue
}
if attachmentStatusOk && attachmentStatus.(string) == "Unattached" && nicIsAttached {
continue
}

// Deprecated for `attachment_status`, remove in 3.0
// Removal will also change behaviour for data sources without `attachment_status` set
attachedOnly := d.Get("attached").(bool)
if attachedOnly != nicIsAttached {
if !attachmentStatusOk && attachedOnly != nicIsAttached {
continue
}

Expand Down
24 changes: 24 additions & 0 deletions internal/services/network/public_ips_data_source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ func TestAccDataSourcePublicIPs_assigned(t *testing.T) {
r := PublicIPsResource{}

attachedDataSourceName := "data.azurerm_public_ips.attached"
attachedDataSourceName2 := "data.azurerm_public_ips.attached2"
unattachedDataSourceName := "data.azurerm_public_ips.unattached"
unattachedDataSourceName2 := "data.azurerm_public_ips.unattached2"
unattachedAndAttachedDataSourceName := "data.azurerm_public_ips.unattached_and_attached"

data.DataSourceTest(t, []acceptance.TestStep{
{
Expand All @@ -45,8 +48,14 @@ func TestAccDataSourcePublicIPs_assigned(t *testing.T) {
Check: acceptance.ComposeTestCheckFunc(
acceptance.TestCheckResourceAttr(attachedDataSourceName, "public_ips.#", "3"),
acceptance.TestCheckResourceAttr(attachedDataSourceName, "public_ips.0.name", fmt.Sprintf("acctestpip%s-0", data.RandomString)),
acceptance.TestCheckResourceAttr(attachedDataSourceName2, "public_ips.#", "3"),
acceptance.TestCheckResourceAttr(attachedDataSourceName2, "public_ips.0.name", fmt.Sprintf("acctestpip%s-0", data.RandomString)),
acceptance.TestCheckResourceAttr(unattachedDataSourceName, "public_ips.#", "4"),
acceptance.TestCheckResourceAttr(unattachedDataSourceName, "public_ips.0.name", fmt.Sprintf("acctestpip%s-3", data.RandomString)),
acceptance.TestCheckResourceAttr(unattachedDataSourceName2, "public_ips.#", "4"),
acceptance.TestCheckResourceAttr(unattachedDataSourceName2, "public_ips.0.name", fmt.Sprintf("acctestpip%s-3", data.RandomString)),
acceptance.TestCheckResourceAttr(unattachedAndAttachedDataSourceName, "public_ips.#", "7"),
acceptance.TestCheckResourceAttr(unattachedAndAttachedDataSourceName, "public_ips.0.name", fmt.Sprintf("acctestpip%s-0", data.RandomString)),
),
},
})
Expand Down Expand Up @@ -118,11 +127,26 @@ func (r PublicIPsResource) attachedDataSource(data acceptance.TestData) string {
%s
data "azurerm_public_ips" "unattached" {
resource_group_name = azurerm_resource_group.test.name
attachment_status = "Unattached"
}
data "azurerm_public_ips" "unattached2" {
resource_group_name = azurerm_resource_group.test.name
attached = false
}
data "azurerm_public_ips" "unattached_and_attached" {
resource_group_name = azurerm_resource_group.test.name
attachment_status = "All"
}
data "azurerm_public_ips" "attached" {
resource_group_name = azurerm_resource_group.test.name
attachment_status = "Attached"
}
data "azurerm_public_ips" "attached2" {
resource_group_name = azurerm_resource_group.test.name
attached = true
}
Expand Down
2 changes: 1 addition & 1 deletion website/docs/d/public_ips.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ data "azurerm_public_ips" "example" {
## Argument Reference

* `resource_group_name` - Specifies the name of the resource group.
* `attached` - (Optional) Filter to include IP Addresses which are attached to a device, such as a VM/LB (`true`) or unattached (`false`).
* `attachment_status` - (Optional) Filter to include IP Addresses which are attached to a device, such as a VM/LB (`Attached`) or unattached (`Unattached`). To allow for both, use `All`.
* `name_prefix` - (Optional) A prefix match used for the IP Addresses `name` field, case sensitive.
* `allocation_type` - (Optional) The Allocation Type for the Public IP Address. Possible values include `Static` or `Dynamic`.

Expand Down