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

Handle the creation of default scaling policies #443

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

mszostok
Copy link
Contributor

Description

This PR allows to manage default scaling policies without importing them. If there is create operation against the default scaling policy, it's changed to update.

Without this PR, the following error is thrown:

   ╷
   │ Error: expected status code 200, received: status=409 body={"message":"scaling policy with the same name already exists", "fieldViolations":[]}
   │
   │   with castai_workload_scaling_policy.default["staging"],
   │   on import.tf line 8, in resource "castai_workload_scaling_policy" "default":8: resource "castai_workload_scaling_policy" "default" {
   ╵

I also update the import section to describe easier way of doing that.

Limitations

  1. Default policies are created in the context of a given cluster ID. As a result, you need to collect and provide all the cluster IDs where you want to change the default policy.
  2. Most of the props are required anyway so if they want to update only a few props, they are still required to provide all of them.

@mszostok mszostok requested a review from a team as a code owner January 21, 2025 14:11
@mszostok mszostok force-pushed the woop-487-upsert-default-policy branch from ab66291 to 4e4021a Compare January 21, 2025 15:07
@mszostok
Copy link
Contributor Author

bumping the SDK causes tests to fail, I will report that to the relevant teams.

Comment on lines +23 to +24
For each connected cluster, a default scaling policy is created. An existing scaling policy can be imported into the
Terraform state using the `terraform import` command or the [`import`](https://developer.hashicorp.com/terraform/language/import#syntax) block.

Choose a reason for hiding this comment

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

Suggested change
For each connected cluster, a default scaling policy is created. An existing scaling policy can be imported into the
Terraform state using the `terraform import` command or the [`import`](https://developer.hashicorp.com/terraform/language/import#syntax) block.
For each connected cluster, a default scaling policy is created. An existing scaling policy can be imported into the
Terraform state using the `terraform import` command or the [`import`](https://developer.hashicorp.com/terraform/language/import#syntax) block (recommended for Terraform 1.5.0+).

Comment on lines +46 to +47
3. Review the `generated.tf` file and ensure that the imported scaling policy is correct. Terraform sets zero values,
e.g., for `look_back_period_seconds`. All such properties can be removed to use the defaults.

Choose a reason for hiding this comment

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

Suggested change
3. Review the `generated.tf` file and ensure that the imported scaling policy is correct. Terraform sets zero values,
e.g., for `look_back_period_seconds`. All such properties can be removed to use the defaults.
3. Review the `generated.tf` file and ensure the imported scaling policy is correct. Terraform will generate this file by setting values equal to zero for certain configuration parameters.
For example:
```hcl
cpu {
look_back_period_seconds = 0
}

You can simplify the configuration by:

  • Removing fields set to 0 to use default values
  • Keeping only the fields you want to configure explicitly

Copy link

@tech-writer-rob tech-writer-rob Jan 24, 2025

Choose a reason for hiding this comment

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

The zero values were a little unclear to me.

I have yet to figure out how to include a code block in a suggestion without breaking the suggestion syntax...

terraform apply "import.plan"
```

### Import using `terraform import` command

Choose a reason for hiding this comment

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

Suggested change
### Import using `terraform import` command
### Import using the `terraform import` command

Comment on lines +142 to +146

The recommended way is to [import](#importing) the scaling policy and then apply the changes to the policy.
However, if that’s not possible, you can define the default policy resource yourself. The CAST AI Terraform provider,
will update the existing policy instead of returning an error.

Choose a reason for hiding this comment

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

Suggested change
## Upsert scaling policy
The recommended way is to [import](#importing) the scaling policy and then apply the changes to the policy.
However, if that’s not possible, you can define the default policy resource yourself. The CAST AI Terraform provider,
will update the existing policy instead of returning an error.
## Upsert scaling policy
The recommended way is to [import](#importing) the scaling policy and then apply the changes to the policy.
However, if that’s not possible, you can define the default policy resource yourself. The CAST AI Terraform provider
will update the existing policy instead of returning an error.

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

Successfully merging this pull request may close these issues.

4 participants