-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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_service_plan
- support premium service plan auto scale feature
#28524
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,6 +32,8 @@ var _ sdk.ResourceWithUpdate = ServicePlanResource{} | |
|
||
var _ sdk.ResourceWithStateMigration = ServicePlanResource{} | ||
|
||
var _ sdk.ResourceWithCustomizeDiff = ServicePlanResource{} | ||
|
||
type OSType string | ||
|
||
const ( | ||
|
@@ -41,19 +43,20 @@ const ( | |
) | ||
|
||
type ServicePlanModel struct { | ||
Name string `tfschema:"name"` | ||
ResourceGroup string `tfschema:"resource_group_name"` | ||
Location string `tfschema:"location"` | ||
Kind string `tfschema:"kind"` | ||
OSType OSType `tfschema:"os_type"` | ||
Sku string `tfschema:"sku_name"` | ||
AppServiceEnvironmentId string `tfschema:"app_service_environment_id"` | ||
PerSiteScaling bool `tfschema:"per_site_scaling_enabled"` | ||
Reserved bool `tfschema:"reserved"` | ||
WorkerCount int64 `tfschema:"worker_count"` | ||
MaximumElasticWorkerCount int64 `tfschema:"maximum_elastic_worker_count"` | ||
ZoneBalancing bool `tfschema:"zone_balancing_enabled"` | ||
Tags map[string]string `tfschema:"tags"` | ||
Name string `tfschema:"name"` | ||
ResourceGroup string `tfschema:"resource_group_name"` | ||
Location string `tfschema:"location"` | ||
Kind string `tfschema:"kind"` | ||
OSType OSType `tfschema:"os_type"` | ||
Sku string `tfschema:"sku_name"` | ||
AppServiceEnvironmentId string `tfschema:"app_service_environment_id"` | ||
PerSiteScaling bool `tfschema:"per_site_scaling_enabled"` | ||
Reserved bool `tfschema:"reserved"` | ||
WorkerCount int64 `tfschema:"worker_count"` | ||
PremiumPlanAutoScaleEnabled bool `tfschema:"premium_plan_auto_scale_enabled"` | ||
MaximumElasticWorkerCount int64 `tfschema:"maximum_elastic_worker_count"` | ||
ZoneBalancing bool `tfschema:"zone_balancing_enabled"` | ||
Tags map[string]string `tfschema:"tags"` | ||
} | ||
|
||
func (r ServicePlanResource) Arguments() map[string]*pluginsdk.Schema { | ||
|
@@ -107,6 +110,12 @@ func (r ServicePlanResource) Arguments() map[string]*pluginsdk.Schema { | |
ValidateFunc: validation.IntAtLeast(1), | ||
}, | ||
|
||
"premium_plan_auto_scale_enabled": { | ||
Type: pluginsdk.TypeBool, | ||
Optional: true, | ||
Default: false, | ||
}, | ||
|
||
"maximum_elastic_worker_count": { | ||
Type: pluginsdk.TypeInt, | ||
Optional: true, | ||
|
@@ -191,9 +200,19 @@ func (r ServicePlanResource) Create() sdk.ResourceFunc { | |
} | ||
} | ||
|
||
if servicePlan.PremiumPlanAutoScaleEnabled { | ||
if !helpers.PlanIsPremium(&servicePlan.Sku) { | ||
return fmt.Errorf("`premium_plan_auto_scale_enabled` can only be set for premium app service plan") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a duplicate of what is in the CustomizeDiff |
||
} else { | ||
appServicePlan.Properties.ElasticScaleEnabled = pointer.To(servicePlan.PremiumPlanAutoScaleEnabled) | ||
} | ||
} | ||
|
||
if servicePlan.MaximumElasticWorkerCount > 0 { | ||
if !isServicePlanSupportScaleOut(servicePlan.Sku) { | ||
return fmt.Errorf("`maximum_elastic_worker_count` can only be specified with Elastic Premium Skus") | ||
if helpers.PlanIsPremium(&servicePlan.Sku) && !servicePlan.PremiumPlanAutoScaleEnabled { | ||
return fmt.Errorf("`maximum_elastic_worker_count` can only be specified with Elastic Premium Skus or Premium Skus that has `premium_plan_auto_scale_enabled` set to `true`") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seems to be a duplicate of what is already in the CustomizeDiff. Do we need this check twice? |
||
} | ||
} | ||
appServicePlan.Properties.MaximumElasticWorkerCount = pointer.To(servicePlan.MaximumElasticWorkerCount) | ||
} | ||
|
@@ -264,6 +283,10 @@ func (r ServicePlanResource) Read() sdk.ResourceFunc { | |
state.AppServiceEnvironmentId = *ase.Id | ||
} | ||
|
||
if props.ElasticScaleEnabled != nil && *props.ElasticScaleEnabled && state.Sku != "" && helpers.PlanIsPremium(&state.Sku) { | ||
state.PremiumPlanAutoScaleEnabled = pointer.From(props.ElasticScaleEnabled) | ||
} | ||
|
||
state.PerSiteScaling = pointer.From(props.PerSiteScaling) | ||
state.Reserved = pointer.From(props.Reserved) | ||
state.ZoneBalancing = pointer.From(props.ZoneRedundant) | ||
|
@@ -341,6 +364,14 @@ func (r ServicePlanResource) Update() sdk.ResourceFunc { | |
model.Sku.Capacity = pointer.To(state.WorkerCount) | ||
} | ||
|
||
if metadata.ResourceData.HasChange("premium_plan_auto_scale_enabled") { | ||
if !helpers.PlanIsPremium(&state.Sku) { | ||
return fmt.Errorf("`premium_plan_auto_scale_enabled` can only be set for premium app service plan") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This also seems like a duplicate of the CustomizeDiff |
||
} else { | ||
model.Properties.ElasticScaleEnabled = pointer.To(state.PremiumPlanAutoScaleEnabled) | ||
} | ||
} | ||
|
||
if metadata.ResourceData.HasChange("maximum_elastic_worker_count") { | ||
if metadata.ResourceData.HasChange("maximum_elastic_worker_count") && !isServicePlanSupportScaleOut(state.Sku) { | ||
return fmt.Errorf("`maximum_elastic_worker_count` can only be specified with Elastic Premium Skus") | ||
|
@@ -373,3 +404,25 @@ func (r ServicePlanResource) StateUpgraders() sdk.StateUpgradeData { | |
}, | ||
} | ||
} | ||
|
||
func (r ServicePlanResource) CustomizeDiff() sdk.ResourceFunc { | ||
return sdk.ResourceFunc{ | ||
Timeout: 5 * time.Minute, | ||
Func: func(ctx context.Context, metadata sdk.ResourceMetaData) error { | ||
rd := metadata.ResourceDiff | ||
servicePlanSku := rd.Get("sku_name").(string) | ||
_, newAutoScaleEnabled := rd.GetChange("premium_plan_auto_scale_enabled") | ||
_, newEcValue := rd.GetChange("maximum_elastic_worker_count") | ||
if rd.HasChange("premium_plan_auto_scale_enabled") { | ||
if !helpers.PlanIsPremium(&servicePlanSku) && newAutoScaleEnabled.(bool) { | ||
return fmt.Errorf("`premium_plan_auto_scale_enabled` can only be set for premium app service plan") | ||
} | ||
} | ||
|
||
if rd.HasChange("maximum_elastic_worker_count") && newEcValue.(int) > 1 && helpers.PlanIsPremium(&servicePlanSku) && !newAutoScaleEnabled.(bool) { | ||
return fmt.Errorf("`maximum_elastic_worker_count` can only be specified when Premium Skus that has `premium_plan_auto_scale_enabled` set to `true`") | ||
} | ||
return nil | ||
}, | ||
} | ||
} |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -55,7 +55,9 @@ The following arguments are supported: | |||||
|
||||||
~> **NOTE:** Requires an Isolated SKU. Use one of `I1`, `I2`, `I3` for `azurerm_app_service_environment`, or `I1v2`, `I2v2`, `I3v2` for `azurerm_app_service_environment_v3` | ||||||
|
||||||
* `maximum_elastic_worker_count` - (Optional) The maximum number of workers to use in an Elastic SKU Plan. Cannot be set unless using an Elastic SKU. | ||||||
* `premium_plan_auto_scale_enabled` - (Optional) Should automatic scaling be enabled for the Premium SKU Plan. Defaults to `false`.Cannot be set unless using a Premium SKU. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
* `maximum_elastic_worker_count` - (Optional) The maximum number of workers to use in an Elastic SKU Plan or Premium Plan that have `premium_plan_auto_scale_enabled` set to `true`. Cannot be set unless using an Elastic or Premium SKU. | ||||||
|
||||||
* `worker_count` - (Optional) The number of Workers (instances) to be allocated. | ||||||
|
||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we have to pass a pointer to a string for this function? It looks like every time we call this function, you're passing in the address of a string when we could just pass the string