Skip to content

Commit

Permalink
azurerm_service_plan - add support for zone_balancing_enabled (#1…
Browse files Browse the repository at this point in the history
  • Loading branch information
jackofallops authored Apr 6, 2022
1 parent c0d41cb commit 09ccbbc
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 14 deletions.
16 changes: 10 additions & 6 deletions internal/services/appservice/service_plan_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}

Expand Down Expand Up @@ -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(),
}
}
Expand Down Expand Up @@ -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))
}
Expand Down
20 changes: 14 additions & 6 deletions internal/services/appservice/service_plan_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}

Expand Down Expand Up @@ -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(),
}
}
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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))
}
Expand Down Expand Up @@ -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)
}
Expand Down
8 changes: 6 additions & 2 deletions internal/services/appservice/service_plan_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -273,6 +275,8 @@ resource "azurerm_service_plan" "test" {
per_site_scaling_enabled = true
worker_count = 3
zone_balancing_enabled = true
tags = {
Foo = "bar"
}
Expand Down
2 changes: 2 additions & 0 deletions website/docs/d/service_plan.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions website/docs/r/service_plan.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down

0 comments on commit 09ccbbc

Please sign in to comment.