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_web_app - support repository_url, repository_branch, and repository_token properties #27401

Merged
merged 13 commits into from
Jan 8, 2025
Merged
14 changes: 14 additions & 0 deletions internal/services/appservice/static_web_app_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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(),
}
}
Expand Down Expand Up @@ -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)
}

Expand Down
48 changes: 48 additions & 0 deletions internal/services/appservice/static_web_app_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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(),
}
}
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
}

Expand Down Expand Up @@ -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
},
}
Expand Down
4 changes: 4 additions & 0 deletions website/docs/d/static_web_app.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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.

---
Expand Down
2 changes: 1 addition & 1 deletion website/docs/r/security_center_contact.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
```
6 changes: 6 additions & 0 deletions website/docs/r/static_web_app.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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.

---
Expand Down
Loading