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_policy_definition mode is case sensitive #8748

Closed
sebastus opened this issue Oct 5, 2020 · 3 comments · Fixed by #8795
Closed

azurerm_policy_definition mode is case sensitive #8748

sebastus opened this issue Oct 5, 2020 · 3 comments · Fixed by #8795

Comments

@sebastus
Copy link
Contributor

sebastus commented Oct 5, 2020

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or "me too" comments, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

Terraform (and AzureRM Provider) Version

Affected Resource(s)

  • azurerm_policy_definition

Terraform Configuration Files

resource "azurerm_policy_definition" "key_vault_soft_delete" {
  name                  = "Key-Vault-Soft-Delete"
  policy_type           = "Custom"
  mode                  = "indexed"
  display_name          = "Key-Vault-Soft-Delete"
  management_group_name = var.definition_management_group
  policy_rule           = file("${path.module}/policies/keyVaultSoftDelete/policyRule.json")
}

Expected Behavior

When this snippet is applied, a policy definition is created as one would expect. A "terraform plan" after apply should yield that no changes are required.

Actual Behavior

However, a "terraform plan" after "terraform apply" yields the need to update the resource.

The problem is a case sensitive comparison on the 'mode' property and that mode "indexed" is stored as "Indexed" during apply.

Steps to Reproduce

  1. terraform apply with the snippet
  2. terraform plan

Important Factoids

References

  • #0000
@tombuildsstuff
Copy link
Contributor

hi @sebastus

Thanks for opening this issue.

Taking a look into this this appears to be a bug where the validation for the mode field allows this to be the incorrect case - Terraform is case-sensitive and as such this validation wants updating here. For now you should be able to remove the diff by updating indexed to Indexed to match what's coming back from Azure here.

Thanks!

beandrad added a commit to beandrad/terraform-provider-azurerm that referenced this issue Oct 8, 2020
Policy creation succeeds even if the policy mode in the request is
not capitalized, however, when fetching the policy mode value from
Azure, the correct capitalized version is returned, which causes
the Terraform state and configuration to be different.

Ideally, there should be an enum with a set of allowed values, but
thi is not the case in the latest version of the Azure Rest API specs.
However, the supported mode values are returned in the create error
response when an invalid mode is requested.

Fixes hashicorp#8748
beandrad added a commit to beandrad/terraform-provider-azurerm that referenced this issue Oct 8, 2020
Policy creation succeeds even if the policy mode in the request is
not capitalized, however, when fetching the policy mode value from
Azure, the correct capitalized version is returned, which causes
the Terraform state and configuration to be different.

Ideally, there should be an enum with a set of allowed values, but
this is not the case in the latest version of the Azure Rest API specs.
However, the supported mode values are returned in the error
response when an invalid mode is requested.

Fixes hashicorp#8748
@tombuildsstuff tombuildsstuff added this to the v2.31.0 milestone Oct 8, 2020
beandrad added a commit to beandrad/terraform-provider-azurerm that referenced this issue Oct 8, 2020
Policy creation succeeds even if the policy mode in the request is
not capitalized, however, when fetching the policy mode value from
Azure, the correct capitalized version is returned, which causes
the Terraform state and configuration to be different.

Ideally, there should be an enum with a set of allowed values, but
this is not the case in the latest version of the Azure Rest API specs.
However, the supported mode values are returned in the error
response when an invalid mode is requested.

Fixes hashicorp#8748
jackofallops pushed a commit that referenced this issue Oct 8, 2020
Policy creation succeeds even if the policy mode in the request is
not capitalized, however, when fetching the policy mode value from
Azure, the correct capitalized version is returned, which causes
the Terraform state and configuration to be different.

Ideally, there should be an enum with a set of allowed values, but
this is not the case in the latest version of the Azure Rest API specs.
However, the supported mode values are returned in the error
response when an invalid mode is requested.

Fixes #8748
@ghost
Copy link

ghost commented Oct 8, 2020

This has been released in version 2.31.0 of the provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading. As an example:

provider "azurerm" {
    version = "~> 2.31.0"
}
# ... other configuration ...

@ghost
Copy link

ghost commented Nov 8, 2020

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 feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. If you feel I made an error 🤖 🙉 , please reach out to my human friends 👉 [email protected]. Thanks!

@ghost ghost locked as resolved and limited conversation to collaborators Nov 8, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants