rancher / terraform-provider-rancher2

Terraform Rancher2 provider
https://www.terraform.io/docs/providers/rancher2/
Mozilla Public License 2.0
263 stars 228 forks source link

[BUG] Can't update any `rancher2_role_template` #1381

Closed mouellet closed 1 month ago

mouellet commented 3 months ago

Rancher Server Setup

Information about the Cluster

User Information

Provider Information

Describe the bug

We have custom roles _without external_rules defined_. When terraform-provider-rancher2 to v4.2.0 any update to the a rancher2_role_template resource is blocked by the Rancher Webhook with the following error message:

error: roletemplates.management.cattle.io "rt-p***" could not be patched: admission webhook "rancher.cattle.io.roletemplates.management.cattle.io" denied the request: ExternalRules can't be set in RoleTemplates with external=false

The provider might be sending and empty array value for the externalRules attribute to the rancher API but the Rancher Webhook checks for a nil value. See: https://github.com/rancher/webhook/blob/main/pkg/resources/management.cattle.io/v3/roletemplate/validator.go#L130

To Reproduce

With kubectl, edit a roletemplates by adding externalRules: [] to the manifest.

Actual Result

See error above

Expected Result

Role template should be updated

Screenshots

Additional context

joesims22 commented 1 month ago

Validated on v2.10-head id 8b50f83

# Priority Description & Link PASS/FAIL
1 P0 Verify updating RT via TFP is successful ✅ PASS
2 P0 Verify TFP sets external attribute to false by default ✅ PASS
3 P0 Verify external rules value is set to nil if external attribute is not set ✅ PASS
4 P0 Verify external rules cannot be set when updating RT via TFP while external is set to false ✅ PASS
5 P0 Verify external rules can be set when updating RT via TFP after setting external to true ✅ PASS
6 P1 Verify external rules cannot be set via kubectl when external is set to false ✅ PASS
7 P1 Verify external rules can be set when updating RT via kubectl after setting external to true ✅ PASS
8 P0 Verify external rules are removed when external set to false via TFP ✅ PASS
9 P0 Upgrade: Verify updating RT via TFP is successful upon upgrading Rancher ✅ PASS