From a5208050ea541ca7b376385262b06270f27ed62f Mon Sep 17 00:00:00 2001 From: jackofallops Date: Wed, 30 Mar 2022 11:17:28 +0100 Subject: [PATCH 1/3] add zone balancing support --- .../appservice/service_plan_resource.go | 20 +++++++++++++------ .../appservice/service_plan_resource_test.go | 8 ++++++-- website/docs/r/service_plan.html.markdown | 4 ++++ 3 files changed, 24 insertions(+), 8 deletions(-) diff --git a/internal/services/appservice/service_plan_resource.go b/internal/services/appservice/service_plan_resource.go index 75bf4633c9aa..662780b8b6d9 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"` + AvailabilityZoneBalancing bool `tfschema:"availability_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), }, + "availability_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.AvailabilityZoneBalancing), }, 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.AvailabilityZoneBalancing = 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..5dfbc8cd90f3 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 + + availability_zone_balancing_enabled = true tags = { environment = "AccTest" @@ -273,6 +275,8 @@ resource "azurerm_service_plan" "test" { per_site_scaling_enabled = true worker_count = 3 + availability_zone_balancing_enabled = true + tags = { Foo = "bar" } diff --git a/website/docs/r/service_plan.html.markdown b/website/docs/r/service_plan.html.markdown index b82371072afe..6637cf79751d 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`. + +* `availability_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. From 1d75e4b572e11f416dd03007e80007fbe4117d37 Mon Sep 17 00:00:00 2001 From: jackofallops Date: Mon, 4 Apr 2022 10:20:06 +0100 Subject: [PATCH 2/3] rename value for consistency with rest of provider --- internal/services/appservice/service_plan_resource.go | 8 ++++---- .../services/appservice/service_plan_resource_test.go | 4 ++-- website/docs/r/service_plan.html.markdown | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/internal/services/appservice/service_plan_resource.go b/internal/services/appservice/service_plan_resource.go index 662780b8b6d9..9124b9a4adac 100644 --- a/internal/services/appservice/service_plan_resource.go +++ b/internal/services/appservice/service_plan_resource.go @@ -45,7 +45,7 @@ type ServicePlanModel struct { Reserved bool `tfschema:"reserved"` WorkerCount int `tfschema:"worker_count"` MaximumElasticWorkerCount int `tfschema:"maximum_elastic_worker_count"` - AvailabilityZoneBalancing bool `tfschema:"availability_zone_balancing_enabled"` + ZoneBalancing bool `tfschema:"zone_balancing_enabled"` Tags map[string]string `tfschema:"tags"` } @@ -107,7 +107,7 @@ func (r ServicePlanResource) Arguments() map[string]*pluginsdk.Schema { ValidateFunc: validation.IntAtLeast(0), }, - "availability_zone_balancing_enabled": { + "zone_balancing_enabled": { Type: pluginsdk.TypeBool, ForceNew: true, Optional: true, @@ -166,7 +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.AvailabilityZoneBalancing), + ZoneRedundant: utils.Bool(servicePlan.ZoneBalancing), }, Sku: &web.SkuDescription{ Name: utils.String(servicePlan.Sku), @@ -264,7 +264,7 @@ func (r ServicePlanResource) Read() sdk.ResourceFunc { state.Reserved = utils.NormaliseNilableBool(props.Reserved) - state.AvailabilityZoneBalancing = utils.NormaliseNilableBool(props.ZoneRedundant) + state.ZoneBalancing = utils.NormaliseNilableBool(props.ZoneRedundant) state.MaximumElasticWorkerCount = int(utils.NormaliseNilableInt32(props.MaximumElasticWorkerCount)) } diff --git a/internal/services/appservice/service_plan_resource_test.go b/internal/services/appservice/service_plan_resource_test.go index 5dfbc8cd90f3..76b5bff434b0 100644 --- a/internal/services/appservice/service_plan_resource_test.go +++ b/internal/services/appservice/service_plan_resource_test.go @@ -245,7 +245,7 @@ resource "azurerm_service_plan" "test" { per_site_scaling_enabled = true worker_count = 3 - availability_zone_balancing_enabled = true + zone_balancing_enabled = true tags = { environment = "AccTest" @@ -275,7 +275,7 @@ resource "azurerm_service_plan" "test" { per_site_scaling_enabled = true worker_count = 3 - availability_zone_balancing_enabled = true + zone_balancing_enabled = true tags = { Foo = "bar" diff --git a/website/docs/r/service_plan.html.markdown b/website/docs/r/service_plan.html.markdown index 6637cf79751d..f0377d5b310e 100644 --- a/website/docs/r/service_plan.html.markdown +++ b/website/docs/r/service_plan.html.markdown @@ -61,7 +61,7 @@ The following arguments are supported: * `per_site_scaling_enabled` - (Optional) Should Per Site Scaling be enabled. Defaults to `false`. -* `availability_zone_balancing_enabled` - (Optional) Should the Service Plan balance across Availability Zones in the region. 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. From 3b7c137ca41ee66a3309550357417c84472fd288 Mon Sep 17 00:00:00 2001 From: jackofallops Date: Mon, 4 Apr 2022 10:21:25 +0100 Subject: [PATCH 3/3] add zone_balancing to ds --- .../appservice/service_plan_data_source.go | 16 ++++++++++------ website/docs/d/service_plan.html.markdown | 2 ++ 2 files changed, 12 insertions(+), 6 deletions(-) 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/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