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_private_endpoint: Add support for tags #6574

Merged
merged 2 commits into from
Apr 23, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tags"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils"
)
Expand Down Expand Up @@ -98,8 +99,7 @@ func resourceArmPrivateEndpoint() *schema.Resource {
},
},

// tags has been removed
// API Issue "Unable to remove Tags from Private Endpoint": https://github.com/Azure/azure-sdk-for-go/issues/6467
"tags": tags.Schema(),
},
}
}
Expand Down Expand Up @@ -142,6 +142,7 @@ func resourceArmPrivateEndpointCreateUpdate(d *schema.ResourceData, meta interfa
ID: utils.String(subnetId),
},
},
Tags: tags.Expand(d.Get("tags").(map[string]interface{})),
}

future, err := client.CreateOrUpdate(ctx, resourceGroup, name, parameters)
Expand Down Expand Up @@ -223,8 +224,7 @@ func resourceArmPrivateEndpointRead(d *schema.ResourceData, meta interface{}) er
d.Set("subnet_id", subnetId)
}

// API Issue "Unable to remove Tags from Private Link Endpoint": https://github.com/Azure/azure-sdk-for-go/issues/6467
return nil
return tags.FlattenAndSet(d, resp.Tags)
}

func resourceArmPrivateEndpointDelete(d *schema.ResourceData, meta interface{}) error {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,42 @@ func TestAccAzureRMPrivateEndpoint_basic(t *testing.T) {
})
}

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

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acceptance.PreCheck(t) },
Providers: acceptance.SupportedProviders,
CheckDestroy: testCheckAzureRMPrivateEndpointDestroy,
Steps: []resource.TestStep{
{
Config: testAccAzureRMPrivateEndpoint_basic(data),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMPrivateEndpointExists(data.ResourceName),
resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "0"),
),
},
data.ImportStep(),
{
Config: testAccAzureRMPrivateEndpoint_withTag(data),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMPrivateEndpointExists(data.ResourceName),
resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "1"),
),
},
data.ImportStep(),
{
Config: testAccAzureRMPrivateEndpoint_basic(data),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMPrivateEndpointExists(data.ResourceName),
resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "0"),
),
},
data.ImportStep(),
},
})
}

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

Expand Down Expand Up @@ -241,6 +277,29 @@ resource "azurerm_private_endpoint" "test" {
`, testAccAzureRMPrivateEndpointTemplate_template(data, testAccAzureRMPrivateEndpoint_serviceAutoApprove(data)), data.RandomInteger)
}

func testAccAzureRMPrivateEndpoint_withTag(data acceptance.TestData) string {
return fmt.Sprintf(`
%s

resource "azurerm_private_endpoint" "test" {
name = "acctest-privatelink-%d"
resource_group_name = azurerm_resource_group.test.name
location = azurerm_resource_group.test.location
subnet_id = azurerm_subnet.endpoint.id

private_service_connection {
name = azurerm_private_link_service.test.name
is_manual_connection = false
private_connection_resource_id = azurerm_private_link_service.test.id
}

tags = {
env = "TEST"
}
}
`, testAccAzureRMPrivateEndpointTemplate_template(data, testAccAzureRMPrivateEndpoint_serviceAutoApprove(data)), data.RandomInteger)
}

func testAccAzureRMPrivateEndpoint_requestMessage(data acceptance.TestData, msg string) string {
return fmt.Sprintf(`
%s
Expand Down
2 changes: 2 additions & 0 deletions website/docs/r/private_endpoint.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ The following arguments are supported:

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

* `tags` - (Optional) A mapping of tags to assign to the resource.

---

A `private_service_connection` supports the following:
Expand Down