Skip to content

Commit

Permalink
azurerm_static_site: Add support for tags attribute (#11849)
Browse files Browse the repository at this point in the history
  • Loading branch information
favoretti authored May 25, 2021
1 parent ce635ee commit ac087a8
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 1 deletion.
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

0 comments on commit ac087a8

Please sign in to comment.