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

New Resources: azurerm_static_web_app, azurerm_static_web_app_custom_domain #25117

Merged
merged 16 commits into from
Mar 4, 2024
Merged
Show file tree
Hide file tree
Changes from 14 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
2 changes: 1 addition & 1 deletion .github/labeler-issue-triage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ service/app-configuration:
- '### (|New or )Affected Resource\(s\)\/Data Source\(s\)((.|\n)*)azurerm_app_configuration((.|\n)*)###'

service/app-service:
- '### (|New or )Affected Resource\(s\)\/Data Source\(s\)((.|\n)*)azurerm_(app_service_environment_v3\W+|app_service_environment_v3\W+|app_service_source_control\W+|app_service_source_control_slot\W+|function_app_active_slot\W+|function_app_function\W+|function_app_hybrid_connection\W+|linux_function_app\W+|linux_function_app\W+|linux_function_app_slot\W+|linux_web_app\W+|linux_web_app\W+|linux_web_app_slot\W+|service_plan|source_control_token|web_app_|windows_function_app\W+|windows_function_app\W+|windows_function_app_slot\W+|windows_web_app\W+|windows_web_app\W+|windows_web_app_slot\W+)((.|\n)*)###'
- '### (|New or )Affected Resource\(s\)\/Data Source\(s\)((.|\n)*)azurerm_(app_service_environment_v3\W+|app_service_environment_v3\W+|app_service_source_control\W+|app_service_source_control_slot\W+|function_app_active_slot\W+|function_app_function\W+|function_app_hybrid_connection\W+|linux_function_app\W+|linux_function_app\W+|linux_function_app_slot\W+|linux_web_app\W+|linux_web_app\W+|linux_web_app_slot\W+|service_plan|source_control_token|static_web_app|web_app_|windows_function_app\W+|windows_function_app\W+|windows_function_app_slot\W+|windows_web_app\W+|windows_web_app\W+|windows_web_app_slot\W+)((.|\n)*)###'

service/application-insights:
- '### (|New or )Affected Resource\(s\)\/Data Source\(s\)((.|\n)*)azurerm_application_insights((.|\n)*)###'
Expand Down
9 changes: 9 additions & 0 deletions internal/services/appservice/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/hashicorp/go-azure-sdk/resource-manager/web/2023-01-01/appserviceenvironments"
"github.com/hashicorp/go-azure-sdk/resource-manager/web/2023-01-01/appserviceplans"
"github.com/hashicorp/go-azure-sdk/resource-manager/web/2023-01-01/resourceproviders"
"github.com/hashicorp/go-azure-sdk/resource-manager/web/2023-01-01/staticsites"
"github.com/hashicorp/go-azure-sdk/resource-manager/web/2023-01-01/webapps"
"github.com/hashicorp/terraform-provider-azurerm/internal/common"
)
Expand All @@ -17,6 +18,7 @@ type Client struct {
AppServiceEnvironmentClient *appserviceenvironments.AppServiceEnvironmentsClient
ResourceProvidersClient *resourceproviders.ResourceProvidersClient
ServicePlanClient *appserviceplans.AppServicePlansClient
StaticSitesClient *staticsites.StaticSitesClient
WebAppsClient *webapps.WebAppsClient
}

Expand All @@ -39,6 +41,12 @@ func NewClient(o *common.ClientOptions) (*Client, error) {
}
o.Configure(resourceProvidersClient.Client, o.Authorizers.ResourceManager)

staticSitesClient, err := staticsites.NewStaticSitesClientWithBaseURI(o.Environment.ResourceManager)
if err != nil {
return nil, fmt.Errorf("building ServicePlan client: %+v", err)
jackofallops marked this conversation as resolved.
Show resolved Hide resolved
}
o.Configure(staticSitesClient.Client, o.Authorizers.ResourceManager)

servicePlanClient, err := appserviceplans.NewAppServicePlansClientWithBaseURI(o.Environment.ResourceManager)
if err != nil {
return nil, fmt.Errorf("building ServicePlan client: %+v", err)
Expand All @@ -49,6 +57,7 @@ func NewClient(o *common.ClientOptions) (*Client, error) {
AppServiceEnvironmentClient: appServiceEnvironmentClient,
ResourceProvidersClient: resourceProvidersClient,
ServicePlanClient: servicePlanClient,
StaticSitesClient: staticSitesClient,
WebAppsClient: webAppServiceClient,
}, nil
}
5 changes: 5 additions & 0 deletions internal/services/appservice/helpers/enums.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,8 @@ const (
PublicNetworkAccessEnabled string = "Enabled"
PublicNetworkAccessDisabled string = "Disabled"
)

const (
ValidationTypeTXT = "dns-txt-token"
ValidationTypeCName = "cname-delegation"
)
67 changes: 67 additions & 0 deletions internal/services/appservice/helpers/static_web_app.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package helpers

import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/appservice/validate"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/validation"
)

type BasicAuth struct {
Password string `tfschema:"password"`
Environments string `tfschema:"environments"` // AllEnvironments, StagingEnvironments
jackofallops marked this conversation as resolved.
Show resolved Hide resolved
}

type BasicAuthComputed struct {
Environments string `tfschema:"environments"` // AllEnvironments, StagingEnvironments
jackofallops marked this conversation as resolved.
Show resolved Hide resolved
}

const (
EnvironmentsTypeAllEnvironments string = "AllEnvironments"
EnvironmentsTypeStagingEnvironments string = "StagingEnvironments"
EnvironmentsTypeSpecifiedEnvironments string = "SpecifiedEnvironments"
)

func BasicAuthSchema() *pluginsdk.Schema {
return &pluginsdk.Schema{
Type: pluginsdk.TypeList,
MaxItems: 1,
Optional: true,
Sensitive: true,
Elem: &pluginsdk.Resource{
Schema: map[string]*schema.Schema{
"password": {
Type: pluginsdk.TypeString,
Required: true,
Sensitive: true,
ValidateFunc: validate.StaticWebAppPassword,
},

"environments": {
Type: pluginsdk.TypeString,
Required: true,
ValidateFunc: validation.StringInSlice([]string{
EnvironmentsTypeAllEnvironments,
EnvironmentsTypeStagingEnvironments,
}, false),
},
},
},
}
}

func BasicAuthSchemaComputed() *pluginsdk.Schema {
return &pluginsdk.Schema{
Type: pluginsdk.TypeList,
Computed: true,
Sensitive: true,
Elem: &pluginsdk.Resource{
Schema: map[string]*schema.Schema{
"environments": {
Type: pluginsdk.TypeString,
Computed: true,
},
},
},
}
}
3 changes: 3 additions & 0 deletions internal/services/appservice/registration.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ func (r Registration) DataSources() []sdk.DataSource {
LinuxFunctionAppDataSource{},
LinuxWebAppDataSource{},
ServicePlanDataSource{},
StaticWebAppDataSource{},
WindowsFunctionAppDataSource{},
WindowsWebAppDataSource{},
}
Expand All @@ -49,6 +50,8 @@ func (r Registration) Resources() []sdk.Resource {
ServicePlanResource{},
SourceControlResource{},
SourceControlSlotResource{},
StaticWebAppResource{},
StaticWebAppCustomDomainResource{},
WebAppActiveSlotResource{},
WebAppHybridConnectionResource{},
WindowsFunctionAppResource{},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
package sdkhacks

import (
"context"
"fmt"
"net/http"

"github.com/hashicorp/go-azure-sdk/resource-manager/web/2023-01-01/staticsites"
"github.com/hashicorp/go-azure-sdk/sdk/client"
)

type StaticSitesClient struct {
client *staticsites.StaticSitesClient
}

func NewStaticWebAppClient(client *staticsites.StaticSitesClient) StaticSitesClient {
return StaticSitesClient{
client: client,
}
}

// CreateOrUpdateBasicAuth ...
func (c StaticSitesClient) CreateOrUpdateBasicAuth(ctx context.Context, id staticsites.StaticSiteId, input staticsites.StaticSiteBasicAuthPropertiesARMResource) (result staticsites.CreateOrUpdateBasicAuthOperationResponse, err error) {
opts := client.RequestOptions{
ContentType: "application/json; charset=utf-8",
ExpectedStatusCodes: []int{
http.StatusOK,
},
HttpMethod: http.MethodPut,
Path: fmt.Sprintf("%s/config/basicAuth", id.ID()),
}

req, err := c.client.Client.NewRequest(ctx, opts)
if err != nil {
return
}

if err = req.Marshal(input); err != nil {
return
}

var resp *client.Response
resp, err = req.Execute(ctx)
if resp != nil {
result.OData = resp.OData
result.HttpResponse = resp.Response
}
if err != nil {
return
}

if err = resp.Unmarshal(&result.Model); err != nil {
return
}

return
}

func (c StaticSitesClient) GetBasicAuth(ctx context.Context, id staticsites.StaticSiteId) (result staticsites.GetBasicAuthOperationResponse, err error) {
opts := client.RequestOptions{
ContentType: "application/json; charset=utf-8",
ExpectedStatusCodes: []int{
http.StatusOK,
},
HttpMethod: http.MethodGet,
Path: fmt.Sprintf("%s/basicAuth/default", id.ID()),
}

req, err := c.client.Client.NewRequest(ctx, opts)
if err != nil {
return
}

var resp *client.Response
resp, err = req.Execute(ctx)
if resp != nil {
result.OData = resp.OData
result.HttpResponse = resp.Response
}
if err != nil {
return
}

if err = resp.Unmarshal(&result.Model); err != nil {
return
}

return
}
Loading
Loading