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_static_site: Add support for tags attribute #11849

Merged
merged 2 commits into from
May 25, 2021
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
6 changes: 5 additions & 1 deletion azurerm/internal/services/web/static_site_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"time"

"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/location"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tags"
azSchema "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tf/schema"

"github.com/hashicorp/terraform-plugin-sdk/helper/validation"
Expand Down Expand Up @@ -74,6 +75,8 @@ func resourceStaticSite() *schema.Resource {
Type: schema.TypeString,
Computed: true,
},

"tags": tags.Schema(),
},
}
}
Expand Down Expand Up @@ -110,6 +113,7 @@ func resourceStaticSiteCreateOrUpdate(d *schema.ResourceData, meta interface{})
},
StaticSite: &web.StaticSite{},
Location: &loc,
Tags: tags.Expand(d.Get("tags").(map[string]interface{})),
}

if _, err := client.CreateOrUpdateStaticSite(ctx, id.ResourceGroup, id.Name, siteEnvelope); err != nil {
Expand Down Expand Up @@ -178,7 +182,7 @@ func resourceStaticSiteRead(d *schema.ResourceData, meta interface{}) error {
}
d.Set("api_key", apiKey)

return nil
return tags.FlattenAndSet(d, resp.Tags)
}

func resourceStaticSiteDelete(d *schema.ResourceData, meta interface{}) error {
Expand Down
57 changes: 57 additions & 0 deletions azurerm/internal/services/web/static_site_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,41 @@ func TestAccAzureStaticSite_basic(t *testing.T) {
check.That(data.ResourceName).ExistsInAzure(r),
check.That(data.ResourceName).Key("default_host_name").Exists(),
check.That(data.ResourceName).Key("api_key").Exists(),
check.That(data.ResourceName).Key("tags.environment").HasValue("acceptance"),
),
},
data.ImportStep(),
})
}

func TestAccAzureStaticSite_basicUpdate(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_static_site", "test")
r := StaticSiteResource{}

data.ResourceTest(t, r, []resource.TestStep{
{
Config: r.basic(data),
Check: resource.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
check.That(data.ResourceName).Key("default_host_name").Exists(),
check.That(data.ResourceName).Key("api_key").Exists(),
check.That(data.ResourceName).Key("tags.environment").HasValue("acceptance"),
),
},
data.ImportStep(),
{
Config: r.basicUpdate(data),
Check: resource.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
check.That(data.ResourceName).Key("default_host_name").Exists(),
check.That(data.ResourceName).Key("api_key").Exists(),
check.That(data.ResourceName).Key("tags.environment").HasValue("acceptance"),
check.That(data.ResourceName).Key("tags.updated").HasValue("true"),
),
},
})
}

func TestAccAzureStaticSite_requiresImport(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_static_site", "test")
r := StaticSiteResource{}
Expand Down Expand Up @@ -82,6 +111,34 @@ resource "azurerm_static_site" "test" {
name = "acctestSS-%d"
location = azurerm_resource_group.test.location
resource_group_name = azurerm_resource_group.test.name

tags = {
environment = "acceptance"
}
}
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger)
}

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

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

resource "azurerm_static_site" "test" {
name = "acctestSS-%d"
location = azurerm_resource_group.test.location
resource_group_name = azurerm_resource_group.test.name

tags = {
environment = "acceptance"
updated = "true"
}
}
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger)
}
Expand Down
2 changes: 2 additions & 0 deletions website/docs/r/static_site.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ The following arguments are supported:

* `resource_group_name` - (Required) The name of the Resource Group where the Static Web App should exist. Changing this forces a new Static Web App to be created.

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

## Attributes Reference

In addition to the Arguments listed above - the following Attributes are exported:
Expand Down