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

azurerm_service_plan - support premium service plan auto scale feature #28524

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

xiaxyi
Copy link
Contributor

@xiaxyi xiaxyi commented Jan 16, 2025

Community Note

  • Please vote on this PR by adding a 👍 reaction to the original PR to help the community and maintainers prioritize for review
  • Please do not leave comments along the lines of "+1", "me too" or "any updates", they generate extra noise for PR followers and do not help prioritize for review

Description

PR Checklist

  • I have followed the guidelines in our Contributing Documentation.
  • I have checked to ensure there aren't other open Pull Requests for the same update/change.
  • I have checked if my changes close any open issues. If so please include appropriate closing keywords below.
  • I have updated/added Documentation as required written in a helpful and kind way to assist users that may be unfamiliar with the resource / data source.
  • I have used a meaningful PR title to help maintainers and other users understand this change and help prevent duplicate work.
    For example: “resource_name_here - description of change e.g. adding property new_property_name_here

Changes to existing Resource / Data Source

  • I have added an explanation of what my changes do and why I'd like you to include them (This may be covered by linking to an issue above, but may benefit from additional explanation).
  • I have written new tests for my resource or datasource changes & updated any relevent documentation.
  • I have successfully run tests with my changes locally. If not, please provide details on testing challenges that prevented you running the tests.
  • (For changes that include a state migration only). I have manually tested the migration path between relevant versions of the provider.

Testing

  • My submission includes Test coverage as described in the Contribution Guide and the tests pass. (if this is not possible for any reason, please include details of why you did or could not add test coverage)

--- PASS: TestAccServicePlan_completeUpdate (223.57s)
--- PASS: TestAccServicePlan_completeUpdate (223.57s)
--- PASS: TestAccServicePlan_completeUpdate (223.57s)
--- PASS: TestAccServicePlan_maxElasticWorkerCount (230.74s)
--- PASS: TestAccServicePlan_basic (128.02s)
--- PASS: TestAccServicePlan_requiresImport (108.08s)
--- PASS: TestAccServicePlan_linuxFlexConsumption (111.20s)
--- PASS: TestAccServicePlan_linuxConsumption (119.28s)
--- PASS: TestAccServicePlan_linuxPremiumAutoScaleFeatureUpdate (311.50s)
--- PASS: TestAccServicePlanIsolated_appServiceEnvironmentV3 (4023.99s)
FAIL

Change Log

Below please provide what should go into the changelog (if anything) conforming to the Changelog Format documented here.

This is a (please select all that apply):

  • Bug Fix
  • New Feature (ie adding a service, resource, or data source)
  • Enhancement
  • Breaking Change

Related Issue(s)

Fixes #22313
Fixes #28358

Note

If this PR changes meaningfully during the course of review please update the title and description as required.

Copy link
Member

@mbfrahry mbfrahry left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @xiaxyi, this overall looks good but there are a few things I've called out. Mainly that there is duplicate checks curing Create/Update that should be caught by the CustomizeDiff. Did you see something that required those checks to be run at plan and apply time?

Also I'm seeing a test failure

=== CONT  TestAccServicePlan_linuxPremiumAutoScaleFeatureUpdate
    testcase.go:173: Step 4/9 error: Error running apply: exit status 1
        Error: `maximum_elastic_worker_count` can only be specified with Elastic Premium Skus
          with azurerm_service_plan.test,
          on terraform_plugin_test.tf line 40, in resource "azurerm_service_plan" "test":
          40: resource "azurerm_service_plan" "test" {
        `maximum_elastic_worker_count` can only be specified with Elastic Premium
        Skus
--- FAIL: TestAccServicePlan_linuxPremiumAutoScaleFeatureUpdate (235.71s)```

@@ -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")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a duplicate of what is in the CustomizeDiff

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`")
Copy link
Member

Choose a reason for hiding this comment

The 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?

@@ -88,6 +94,19 @@ func PlanIsConsumption(input *string) bool {
return false
}

func PlanIsPremium(input *string) bool {
Copy link
Member

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

Suggested change
func PlanIsPremium(input *string) bool {
func PlanIsPremium(input string) bool {

@@ -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")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This also seems like a duplicate of the CustomizeDiff

@@ -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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* `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.
* `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.

@xiaxyi
Copy link
Contributor Author

xiaxyi commented Jan 17, 2025

@mbfrahry Thanks for the comments, code is updated and tests are passed. The failed tests are irrelevant to the code change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants