-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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_automation_certificate keeps recreating #12456
Comments
Encounter the same issue since Azurerm 2.57 and also 2.87 |
Hi @mina69 and @markwong-citihub , I've tried to reproduce this issue with the following code but failed to reproduce: provider "azurerm" {
features {
resource_group {
prevent_deletion_if_contains_resources = false
}
}
}
data "azurerm_client_config" "current" {}
resource "azurerm_resource_group" "example" {
name = "zjhe-f12456"
location = "West Europe"
}
resource "azurerm_key_vault" "example" {
name = "zjhef12456"
location = azurerm_resource_group.example.location
resource_group_name = azurerm_resource_group.example.name
tenant_id = data.azurerm_client_config.current.tenant_id
sku_name = "premium"
access_policy {
tenant_id = data.azurerm_client_config.current.tenant_id
object_id = data.azurerm_client_config.current.object_id
certificate_permissions = [for p in [
"create",
"delete",
"deleteIssuers",
"get",
"getIssuers",
"import",
"list",
"listIssuers",
"manageContacts",
"ManageIssuers",
"SetIssuers",
"update",
] : title(p)]
key_permissions = [for op in [
"backup",
"create",
"decrypt",
"delete",
"encrypt",
"get",
"import",
"list",
"purge",
"recover",
"restore",
"sign",
"unwrapKey",
"update",
"verify",
"wrapKey",
]:title(op)]
secret_permissions = [
"Backup",
"Delete",
"Get",
"List",
"Purge",
"Recover",
"Restore",
"Set",
]
}
}
resource "azurerm_key_vault_certificate" "azure_automation_cert" {
name = "zjhef12456"
key_vault_id = azurerm_key_vault.example.id #var.keyvault_id
certificate_policy {
issuer_parameters {
name = "Self"
}
key_properties {
exportable = true
key_size = 2048
key_type = "RSA"
reuse_key = true
}
lifetime_action {
action {
action_type = "AutoRenew"
}
trigger {
days_before_expiry = 180
}
}
secret_properties {
content_type = "application/x-pkcs12"
}
x509_certificate_properties {
extended_key_usage = ["1.3.6.1.5.5.7.3.2"]
key_usage = [
"dataEncipherment",
"digitalSignature",
"keyCertSign",
"keyEncipherment",
]
subject = "CN=test"
validity_in_months = 12
}
}
}
data "azurerm_key_vault_secret" "certificate" {
name = azurerm_key_vault_certificate.azure_automation_cert.name
key_vault_id = azurerm_key_vault_certificate.azure_automation_cert.key_vault_id
depends_on = [
azurerm_key_vault_certificate.azure_automation_cert,
]
}
resource "azurerm_automation_account" "example" {
name = "zjhe-f12456"
location = azurerm_resource_group.example.location
resource_group_name = azurerm_resource_group.example.name
sku_name = "Basic"
tags = {
environment = "development"
}
}
resource "azurerm_automation_certificate" "test" {
name = "AzureRunAsCertificate"
resource_group_name = azurerm_resource_group.example.name
automation_account_name = azurerm_automation_account.example.name
base64 = data.azurerm_key_vault_secret.certificate.value
depends_on = [
azurerm_key_vault_certificate.azure_automation_cert,
]
} Would you please provide a minimum sample code that could reproduce this issue? Thanks! |
|
In the TF plan the follow fields are being updated:
|
Hi @markwong-citihub , I tried the following code but I cannot reproduce this issue: provider "azurerm" {
features {
resource_group {
prevent_deletion_if_contains_resources = false
}
}
}
data "azurerm_client_config" "current" {}
resource "azurerm_resource_group" "example" {
name = "zjhe-f12456"
location = "West Europe"
}
resource "azurerm_key_vault" "example" {
name = "zjhef12456"
location = azurerm_resource_group.example.location
resource_group_name = azurerm_resource_group.example.name
tenant_id = data.azurerm_client_config.current.tenant_id
sku_name = "premium"
access_policy {
tenant_id = data.azurerm_client_config.current.tenant_id
object_id = data.azurerm_client_config.current.object_id
certificate_permissions = [for p in [
"create",
"delete",
"deleteIssuers",
"get",
"getIssuers",
"import",
"list",
"listIssuers",
"manageContacts",
"ManageIssuers",
"SetIssuers",
"update",
] : title(p)]
key_permissions = [for op in [
"backup",
"create",
"decrypt",
"delete",
"encrypt",
"get",
"import",
"list",
"purge",
"recover",
"restore",
"sign",
"unwrapKey",
"update",
"verify",
"wrapKey",
]:title(op)]
secret_permissions = [
"Backup",
"Delete",
"Get",
"List",
"Purge",
"Recover",
"Restore",
"Set",
]
}
}
resource "azurerm_key_vault_certificate" "azure_automation_cert" {
name = "zjhef12456"
key_vault_id = azurerm_key_vault.example.id #var.keyvault_id
certificate_policy {
issuer_parameters {
name = "Self"
}
key_properties {
exportable = true
key_size = 2048
key_type = "RSA"
reuse_key = true
}
lifetime_action {
action {
action_type = "AutoRenew"
}
trigger {
days_before_expiry = 180
}
}
secret_properties {
content_type = "application/x-pkcs12"
}
x509_certificate_properties {
extended_key_usage = ["1.3.6.1.5.5.7.3.2"]
key_usage = [
"dataEncipherment",
"digitalSignature",
"keyCertSign",
"keyEncipherment",
]
subject = "CN=test"
validity_in_months = 12
}
}
}
data "azurerm_key_vault_secret" "certificate" {
name = azurerm_key_vault_certificate.azure_automation_cert.name
key_vault_id = azurerm_key_vault_certificate.azure_automation_cert.key_vault_id
depends_on = [
azurerm_key_vault_certificate.azure_automation_cert,
]
}
resource "azurerm_automation_account" "example" {
name = "zjhe-f12456"
location = azurerm_resource_group.example.location
resource_group_name = azurerm_resource_group.example.name
sku_name = "Basic"
tags = {
environment = "development"
}
}
resource "azurerm_automation_certificate" "test" {
name = "AzureRunAsCertificate"
resource_group_name = azurerm_resource_group.example.name
automation_account_name = azurerm_automation_account.example.name
base64 = filebase64("${path.module}/automation_certificate_test.pfx")
depends_on = [
azurerm_key_vault_certificate.azure_automation_cert,
]
} After apply, the |
Hi @markwong-citihub , thank you for your detailed information. I've checked the code, the document missed something, that changing |
@lonegunmanb Ar... think you hit the nail on the head. Each time we run our pipeline, the Certificate's pfx file are regenerated from it's .pem format using openssl pkcs12 command. Each time the binary would be different, thus the base64 would be different. (Even it is the same certficiate with the same thumbprint) Thus, a replacement everytime. Thanks for helping solving this mystery. |
Co-authored-by: zjhe <[email protected]>
@markwong-citihub I'm glad that your issue has been solved! Would you please close this issue if you don't have any further question? Thanks! |
@mina69 is the original creator. Not my issue to close. Sorry. |
Hello @mina69 , would you please check if |
Hello @mina69, is there any update? |
Thanks for opening this issue. Since time has passed and @lonegunmanb was not able to reproduce this issue, and documentation has been updated related to base64, I am going to close this issue. If this is still an issue with the 3.x version of the provider please do let us know by opening a new issue, thanks! |
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. |
Community Note
Description
I have created and applied a certificate using keyvault and assigned it to azure automation-run as account, whenever I run terraform plan it wants to recreate the certificate that is already created by terraform apply.
Terrom and Azurerm versions:
Terraform v0.15.1
Terraform code which is applied:
Debug Output
Bug->Recreating cert
The text was updated successfully, but these errors were encountered: