hashicorp / terraform-provider-google

Terraform Provider for Google Cloud Platform
https://registry.terraform.io/providers/hashicorp/google/latest/docs
Mozilla Public License 2.0
2.34k stars 1.74k forks source link

Bad deprecation on `google_container_cluster.binary_authorization.enabled` #16759

Closed rileykarson closed 10 months ago

rileykarson commented 11 months ago

Community Note

Terraform Version

Affected Resource(s)

Terraform Configuration Files

- enable_binary_authorization = true
+ binary_authorization {
+   evaluation_mode = "PROJECT_SINGLETON_POLICY_ENFORCE"
+ }

Debug Output

Panic Output

Expected Behavior

Binary authorization remains enabled

Actual Behavior

Binary authorization is disabled

Steps to Reproduce

  1. terraform apply

Important Factoids

In 5.0.0 we deprecated enable_binary_authorization in favour of binary_authorization.enabled: https://registry.terraform.io/providers/hashicorp/google/latest/docs/guides/version_5_upgrade#enable_binary_authorization-is-now-removed

However, the field that we directed folks to was introduced as deprecated in https://github.com/GoogleCloudPlatform/magic-modules/pull/6101 and pointed folks to a different field, binary_authorization.evaluation_mode. In the API if you send just that field the API will determine enabled based on its value (and has deprecated setting enablement explicitly). Our implementation always sends an enabled field, which appears to override the value.

This means that I don't think that that upgrade path is possible- and a user that attempts to resolve the deprecation warning is likely to accidentally set binary_authorization.enabled to false, disabling binary authorization on their cluster regardless of their evaluation_mode setting.

We should update our 5.0.0 upgrade guide to warn against specifying just evaluation_mode, and either remove the deprecation clientside until we handle it properly or fix our handling.

References

b/315582550

rmoriar1 commented 11 months ago

This means that I don't think that that upgrade path is possible- and a user that attempts to resolve the deprecation warning is likely to accidentally set binary_authorization.enabled to false, disabling binary authorization on their cluster regardless of their evaluation_mode setting.

I don't think this is right, if the user passes both an evaluation mode and enabled bool the evaluation mode has precedence.

rileykarson commented 11 months ago

I don't think this is right, if the user passes both an evaluation mode and enabled bool the evaluation mode has precedence.

In the API, or Terraform specifically? I think that Terraform is always sending an explicit value to the API.

rileykarson commented 11 months ago

Request/response:

{
  "update": {
    "desiredBinaryAuthorization": {
      "enabled": false,
      "evaluationMode": "PROJECT_SINGLETON_POLICY_ENFORCE"
    }
  }
}
  "binaryAuthorization": {
    "evaluationMode": "PROJECT_SINGLETON_POLICY_ENFORCE",
    "policy": ""
  },

That does mean that an explicit false is not a problem. Note that enabled cannot be true at the same time as evaluationMode is set.

To set BinaryAuthorization.EvaluationMode, leave the deprecated BinaryAuthorization.Enabled field unset.

github-actions[bot] commented 9 months ago

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.