From e686181e9c50f30403da4a5b154dfb7e29bfb0dc Mon Sep 17 00:00:00 2001 From: Ned Bellavance Date: Wed, 8 Jan 2025 03:10:17 -0500 Subject: [PATCH] `azurerm_static_web_app` - support `repository_url`, `repository_branch`, and `repository_token` properties (#27401) * add arguments * add tests * Token fix and data source update * remove acceptance test * Update internal/services/appservice/static_web_app_resource.go Co-authored-by: stephybun * Update internal/services/appservice/static_web_app_resource.go Co-authored-by: stephybun * Update website/docs/r/static_web_app.html.markdown Co-authored-by: stephybun * Update internal/services/appservice/static_web_app_resource.go Co-authored-by: stephybun * update syntax in static web app * Fix prop name * Remove unnecessary blank lines in static_web_app_resource.go --------- Co-authored-by: stephybun --- .../appservice/static_web_app_data_source.go | 14 ++++++ .../appservice/static_web_app_resource.go | 48 +++++++++++++++++++ website/docs/d/static_web_app.html.markdown | 4 ++ .../r/security_center_contact.html.markdown | 2 +- website/docs/r/static_web_app.html.markdown | 6 +++ 5 files changed, 73 insertions(+), 1 deletion(-) diff --git a/internal/services/appservice/static_web_app_data_source.go b/internal/services/appservice/static_web_app_data_source.go index 9d92cd7e8574..15aa529dcb7e 100644 --- a/internal/services/appservice/static_web_app_data_source.go +++ b/internal/services/appservice/static_web_app_data_source.go @@ -42,6 +42,8 @@ type StaticWebAppDataSourceModel struct { SkuTier string `tfschema:"sku_tier"` SkuSize string `tfschema:"sku_size"` Tags map[string]string `tfschema:"tags"` + RepositoryUrl string `tfschema:"repository_url"` + RepositoryBranch string `tfschema:"repository_branch"` } func (s StaticWebAppDataSource) Arguments() map[string]*pluginsdk.Schema { @@ -109,6 +111,16 @@ func (s StaticWebAppDataSource) Attributes() map[string]*pluginsdk.Schema { Computed: true, }, + "repository_url": { + Type: pluginsdk.TypeString, + Computed: true, + }, + + "repository_branch": { + Type: pluginsdk.TypeString, + Computed: true, + }, + "tags": tags.SchemaDataSource(), } } @@ -157,6 +169,8 @@ func (s StaticWebAppDataSource) Read() sdk.ResourceFunc { state.ConfigFileChanges = pointer.From(props.AllowConfigFileUpdates) state.DefaultHostName = pointer.From(props.DefaultHostname) state.PreviewEnvironments = pointer.From(props.StagingEnvironmentPolicy) == staticsites.StagingEnvironmentPolicyEnabled + state.RepositoryUrl = pointer.From(props.RepositoryURL) + state.RepositoryBranch = pointer.From(props.Branch) state.PublicNetworkAccess = !strings.EqualFold(pointer.From(props.PublicNetworkAccess), helpers.PublicNetworkAccessDisabled) } diff --git a/internal/services/appservice/static_web_app_resource.go b/internal/services/appservice/static_web_app_resource.go index a297b7f9bcf6..e9a785204a0c 100644 --- a/internal/services/appservice/static_web_app_resource.go +++ b/internal/services/appservice/static_web_app_resource.go @@ -47,6 +47,10 @@ type StaticWebAppResourceModel struct { ApiKey string `tfschema:"api_key"` DefaultHostName string `tfschema:"default_host_name"` + + RepositoryUrl string `tfschema:"repository_url"` + RepositoryToken string `tfschema:"repository_token"` + RepositoryBranch string `tfschema:"repository_branch"` } func (r StaticWebAppResource) Arguments() map[string]*pluginsdk.Schema { @@ -112,6 +116,28 @@ func (r StaticWebAppResource) Arguments() map[string]*pluginsdk.Schema { "identity": commonschema.SystemAssignedUserAssignedIdentityOptional(), + "repository_url": { + Type: pluginsdk.TypeString, + Optional: true, + ValidateFunc: validation.IsURLWithHTTPorHTTPS, + RequiredWith: []string{"repository_token", "repository_branch"}, + }, + + "repository_token": { + Type: pluginsdk.TypeString, + Optional: true, + Sensitive: true, + ValidateFunc: validation.StringIsNotEmpty, + RequiredWith: []string{"repository_url", "repository_branch"}, + }, + + "repository_branch": { + Type: pluginsdk.TypeString, + Optional: true, + ValidateFunc: validation.StringIsNotEmpty, + RequiredWith: []string{"repository_url", "repository_token"}, + }, + "tags": tags.Schema(), } } @@ -196,6 +222,13 @@ func (r StaticWebAppResource) Create() sdk.ResourceFunc { props.StagingEnvironmentPolicy = pointer.To(staticsites.StagingEnvironmentPolicyDisabled) } + // Check if repository URL, branch, or token are set + if model.RepositoryUrl != "" || model.RepositoryBranch != "" || model.RepositoryToken != "" { + props.Branch = pointer.To(model.RepositoryBranch) + props.RepositoryURL = pointer.To(model.RepositoryUrl) + props.RepositoryToken = pointer.To(model.RepositoryToken) + } + if !model.PublicNetworkAccess { props.PublicNetworkAccess = pointer.To(helpers.PublicNetworkAccessDisabled) } @@ -279,6 +312,15 @@ func (r StaticWebAppResource) Read() sdk.ResourceFunc { state.ConfigFileChanges = pointer.From(props.AllowConfigFileUpdates) state.DefaultHostName = pointer.From(props.DefaultHostname) state.PreviewEnvironments = pointer.From(props.StagingEnvironmentPolicy) == staticsites.StagingEnvironmentPolicyEnabled + + state.RepositoryUrl = pointer.From(props.RepositoryURL) + state.RepositoryBranch = pointer.From(props.Branch) + + // Token isn't returned in the response, so we need to grab it from the config + if repositoryToken, ok := metadata.ResourceData.GetOk("repository_token"); ok { + state.RepositoryToken = repositoryToken.(string) + } + state.PublicNetworkAccess = !strings.EqualFold(pointer.From(props.PublicNetworkAccess), helpers.PublicNetworkAccessDisabled) } @@ -454,6 +496,12 @@ func (r StaticWebAppResource) Update() sdk.ResourceFunc { } } + if metadata.ResourceData.HasChanges("repository_url", "repository_branch", "repository_token") { + model.Properties.RepositoryURL = pointer.To(config.RepositoryUrl) + model.Properties.Branch = pointer.To(config.RepositoryBranch) + model.Properties.RepositoryToken = pointer.To(config.RepositoryToken) + } + return nil }, } diff --git a/website/docs/d/static_web_app.html.markdown b/website/docs/d/static_web_app.html.markdown index a87d407b2f1d..a4f6b27b0fcb 100644 --- a/website/docs/d/static_web_app.html.markdown +++ b/website/docs/d/static_web_app.html.markdown @@ -51,6 +51,10 @@ The following arguments are supported: * `identity` - An `identity` block as defined below. +* `repository_branch` - Repository branch of the Static Web App. + +* `repository_url` - Repository URL of the Static Web App. + * `tags` - The mapping of tags assigned to the resource. --- diff --git a/website/docs/r/security_center_contact.html.markdown b/website/docs/r/security_center_contact.html.markdown index 5dbf52420090..4229cb400ef0 100644 --- a/website/docs/r/security_center_contact.html.markdown +++ b/website/docs/r/security_center_contact.html.markdown @@ -62,4 +62,4 @@ Security Center Contacts can be imported using the `resource id`, e.g. ```shell terraform import azurerm_security_center_contact.example /subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.Security/securityContacts/default1 -``` \ No newline at end of file +``` diff --git a/website/docs/r/static_web_app.html.markdown b/website/docs/r/static_web_app.html.markdown index 345f562c7136..dc79bca40e83 100644 --- a/website/docs/r/static_web_app.html.markdown +++ b/website/docs/r/static_web_app.html.markdown @@ -51,6 +51,12 @@ The following arguments are supported: * `app_settings` - (Optional) A key-value pair of App Settings. +* `repository_branch` - (Optional) Repository branch to use for the Static Web App. `repository_url` and `repository_token` must also be set. + +* `repository_url` - (Optional) Repository URL to use for the Static Web App. `repository_branch` and `repository_token` must also be set. + +* `repository_token` - (Optional) Repository Token with `admin` privileges to use for the Static Web App. `repository_branch` and `repository_url` must also be set. + * `tags` - (Optional) A mapping of tags to assign to the resource. ---