diff --git a/internal/services/appservice/service_plan_data_source.go b/internal/services/appservice/service_plan_data_source.go index 51346febe5d7..f31ffa5cd60e 100644 --- a/internal/services/appservice/service_plan_data_source.go +++ b/internal/services/appservice/service_plan_data_source.go @@ -31,6 +31,7 @@ type ServicePlanDataSourceModel struct { Reserved bool `tfschema:"reserved"` WorkerCount int `tfschema:"worker_count"` MaximumElasticWorkerCount int `tfschema:"maximum_elastic_worker_count"` + ZoneBalancing bool `tfschema:"zone_balancing_enabled"` Tags map[string]string `tfschema:"tags"` } @@ -98,6 +99,11 @@ func (r ServicePlanDataSource) Attributes() map[string]*pluginsdk.Schema { Computed: true, }, + "zone_balancing_enabled": { + Type: pluginsdk.TypeBool, + Computed: true, + }, + "tags": tags.SchemaDataSource(), } } @@ -147,13 +153,11 @@ func (r ServicePlanDataSource) Read() sdk.ResourceFunc { servicePlan.AppServiceEnvironmentId = utils.NormalizeNilableString(props.HostingEnvironmentProfile.ID) } - if v := props.PerSiteScaling; v != nil { - servicePlan.PerSiteScaling = *v - } + servicePlan.PerSiteScaling = utils.NormaliseNilableBool(props.PerSiteScaling) - if v := props.Reserved; v != nil { - servicePlan.Reserved = *v - } + servicePlan.Reserved = utils.NormaliseNilableBool(props.Reserved) + + servicePlan.ZoneBalancing = utils.NormaliseNilableBool(props.ZoneRedundant) servicePlan.MaximumElasticWorkerCount = int(utils.NormaliseNilableInt32(props.MaximumElasticWorkerCount)) } diff --git a/internal/services/appservice/service_plan_resource.go b/internal/services/appservice/service_plan_resource.go index 75bf4633c9aa..9124b9a4adac 100644 --- a/internal/services/appservice/service_plan_resource.go +++ b/internal/services/appservice/service_plan_resource.go @@ -45,6 +45,7 @@ type ServicePlanModel struct { Reserved bool `tfschema:"reserved"` WorkerCount int `tfschema:"worker_count"` MaximumElasticWorkerCount int `tfschema:"maximum_elastic_worker_count"` + ZoneBalancing bool `tfschema:"zone_balancing_enabled"` Tags map[string]string `tfschema:"tags"` } @@ -106,6 +107,12 @@ func (r ServicePlanResource) Arguments() map[string]*pluginsdk.Schema { ValidateFunc: validation.IntAtLeast(0), }, + "zone_balancing_enabled": { + Type: pluginsdk.TypeBool, + ForceNew: true, + Optional: true, + }, + "tags": tags.Schema(), } } @@ -159,6 +166,7 @@ func (r ServicePlanResource) Create() sdk.ResourceFunc { PerSiteScaling: utils.Bool(servicePlan.PerSiteScaling), Reserved: utils.Bool(servicePlan.OSType == OSTypeLinux), HyperV: utils.Bool(servicePlan.OSType == OSTypeWindowsContainer), + ZoneRedundant: utils.Bool(servicePlan.ZoneBalancing), }, Sku: &web.SkuDescription{ Name: utils.String(servicePlan.Sku), @@ -252,13 +260,11 @@ func (r ServicePlanResource) Read() sdk.ResourceFunc { state.AppServiceEnvironmentId = *ase.ID } - if v := props.PerSiteScaling; v != nil { - state.PerSiteScaling = *v - } + state.PerSiteScaling = utils.NormaliseNilableBool(props.PerSiteScaling) - if v := props.Reserved; v != nil { - state.Reserved = *v - } + state.Reserved = utils.NormaliseNilableBool(props.Reserved) + + state.ZoneBalancing = utils.NormaliseNilableBool(props.ZoneRedundant) state.MaximumElasticWorkerCount = int(utils.NormaliseNilableInt32(props.MaximumElasticWorkerCount)) } @@ -318,9 +324,11 @@ func (r ServicePlanResource) Update() sdk.ResourceFunc { if metadata.ResourceData.HasChange("per_site_scaling_enabled") { existing.AppServicePlanProperties.PerSiteScaling = utils.Bool(state.PerSiteScaling) } + if metadata.ResourceData.HasChange("sku_name") { existing.Sku.Name = utils.String(state.Sku) } + if metadata.ResourceData.HasChange("tags") { existing.Tags = tags.FromTypedObject(state.Tags) } diff --git a/internal/services/appservice/service_plan_resource_test.go b/internal/services/appservice/service_plan_resource_test.go index 2593699339ef..76b5bff434b0 100644 --- a/internal/services/appservice/service_plan_resource_test.go +++ b/internal/services/appservice/service_plan_resource_test.go @@ -240,10 +240,12 @@ resource "azurerm_service_plan" "test" { name = "acctest-SP-%[1]d" resource_group_name = azurerm_resource_group.test.name location = azurerm_resource_group.test.location - sku_name = "S1" + sku_name = "P1v3" os_type = "Linux" per_site_scaling_enabled = true - worker_count = 2 + worker_count = 3 + + zone_balancing_enabled = true tags = { environment = "AccTest" @@ -273,6 +275,8 @@ resource "azurerm_service_plan" "test" { per_site_scaling_enabled = true worker_count = 3 + zone_balancing_enabled = true + tags = { Foo = "bar" } diff --git a/website/docs/d/service_plan.html.markdown b/website/docs/d/service_plan.html.markdown index 7ecbbf104009..b430fecfb32b 100644 --- a/website/docs/d/service_plan.html.markdown +++ b/website/docs/d/service_plan.html.markdown @@ -55,6 +55,8 @@ In addition to the Arguments listed above - the following Attributes are exporte * `sku_name` - The SKU for the Service Plan. +* `zone_balancing_enabled` - Is the Service Plan balance across Availability Zones in the region? + * `tags` - A mapping of tags assigned to the Service Plan. ## Timeouts diff --git a/website/docs/r/service_plan.html.markdown b/website/docs/r/service_plan.html.markdown index b82371072afe..f0377d5b310e 100644 --- a/website/docs/r/service_plan.html.markdown +++ b/website/docs/r/service_plan.html.markdown @@ -60,6 +60,10 @@ The following arguments are supported: * `worker_count` - (Optional) The number of Workers (instances) to be allocated. * `per_site_scaling_enabled` - (Optional) Should Per Site Scaling be enabled. Defaults to `false`. + +* `zone_balancing_enabled` - (Optional) Should the Service Plan balance across Availability Zones in the region. Defaults to `false`. + +~> **NOTE:** If this setting is set to `true` and the `worker_count` value is specified, it should be set to a multiple of the number of availability zones in the region. Please see the Azure documentation for the number of Availability Zones in your region. * `tags` - (Optional) A mapping of tags which should be assigned to the AppService.