diff --git a/internal/services/web/static_site_resource.go b/internal/services/web/static_site_resource.go index 0d048422cf50..752fe3195337 100644 --- a/internal/services/web/static_site_resource.go +++ b/internal/services/web/static_site_resource.go @@ -74,6 +74,14 @@ func resourceStaticSite() *pluginsdk.Resource { }, false), }, + "app_settings": { + Type: pluginsdk.TypeMap, + Optional: true, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, + }, + }, + "default_host_name": { Type: pluginsdk.TypeString, Computed: true, @@ -150,6 +158,16 @@ func resourceStaticSiteCreateOrUpdate(d *pluginsdk.ResourceData, meta interface{ d.SetId(id.ID()) + if d.HasChange("app_settings") { + settings := web.StringDictionary{ + Properties: expandStaticSiteAppSettings(d), + } + + if _, err := client.CreateOrUpdateStaticSiteAppSettings(ctx, id.ResourceGroup, id.Name, settings); err != nil { + return fmt.Errorf("updating Application Settings for %s: %+v", id, err) + } + } + return resourceStaticSiteRead(d, meta) } @@ -216,6 +234,15 @@ func resourceStaticSiteRead(d *pluginsdk.ResourceData, meta interface{}) error { } d.Set("api_key", apiKey) + appSettingsResp, err := client.ListStaticSiteAppSettings(ctx, id.ResourceGroup, id.Name) + if err != nil { + return fmt.Errorf("making Read request for app settings on %s: %+v", id, err) + } + + if err := d.Set("app_settings", appSettingsResp.Properties); err != nil { + return fmt.Errorf("setting `app_settings`: %s", err) + } + return tags.FlattenAndSet(d, resp.Tags) } @@ -290,3 +317,14 @@ func flattenStaticSiteIdentity(input *web.ManagedServiceIdentity) (*[]interface{ return identity.FlattenSystemAndUserAssignedMap(transform) } + +func expandStaticSiteAppSettings(d *pluginsdk.ResourceData) map[string]*string { + input := d.Get("app_settings").(map[string]interface{}) + output := make(map[string]*string, len(input)) + + for k, v := range input { + output[k] = utils.String(v.(string)) + } + + return output +} diff --git a/internal/services/web/static_site_resource_test.go b/internal/services/web/static_site_resource_test.go index 11cd41fbf1ae..19b92aa4571f 100644 --- a/internal/services/web/static_site_resource_test.go +++ b/internal/services/web/static_site_resource_test.go @@ -169,6 +169,37 @@ func TestAccAzureStaticSite_requiresImport(t *testing.T) { }) } +func TestAccStaticSite_appSettings(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_static_site", "test") + r := StaticSiteResource{} + + data.ResourceTest(t, r, []acceptance.TestStep{ + { + Config: r.appSettings(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + check.That(data.ResourceName).Key("app_settings.foo").HasValue("bar"), + ), + }, + data.ImportStep(), + { + Config: r.appSettingsUpdate(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + check.That(data.ResourceName).Key("app_settings.foo").HasValue("bar"), + ), + }, + data.ImportStep(), + { + Config: r.basic(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + data.ImportStep(), + }) +} + func (r StaticSiteResource) Exists(ctx context.Context, clients *clients.Client, state *pluginsdk.InstanceState) (*bool, error) { id, err := parse.StaticSiteID(state.ID) if err != nil { @@ -338,3 +369,50 @@ resource "azurerm_static_site" "import" { } `, template) } + +func (r StaticSiteResource) appSettings(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 + + app_settings = { + "foo" = "bar" + } +} +`, data.RandomInteger, data.Locations.Secondary, data.RandomInteger) +} + +func (r StaticSiteResource) appSettingsUpdate(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 + + app_settings = { + "foo" = "bar" + "baz" = "foo" + } +} +`, data.RandomInteger, data.Locations.Secondary, data.RandomInteger) +} diff --git a/website/docs/r/static_site.html.markdown b/website/docs/r/static_site.html.markdown index d792d1386b6d..1f3e6bf6f981 100644 --- a/website/docs/r/static_site.html.markdown +++ b/website/docs/r/static_site.html.markdown @@ -38,6 +38,8 @@ The following arguments are supported: * `identity` - (Optional) An `identity` block as defined below. +* `app_settings` - (Optional) A key-value pair of App Settings. + * `tags` - (Optional) A mapping of tags to assign to the resource. ---