hashicorp / terraform-provider-azurerm

Terraform provider for Azure Resource Manager
https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs
Mozilla Public License 2.0
4.61k stars 4.65k forks source link

Container apps key vault secret `ignore_changes` not recognised #25727

Open jordanhavard opened 7 months ago

jordanhavard commented 7 months ago

Is there an existing issue for this?

Community Note

Terraform Version

1.5.7

AzureRM Provider Version

3.100

Affected Resource(s)/Data Source(s)

azurerm_container_app

Terraform Configuration Files

Adding the following secret block to a standard container apps block

secret {
    name  = "password"
    identity = var.container-apps-identity-id
    key_vault_secret_id = "https://kv.vault.azure.net/secrets/password"
    ignore_changes = true
    value = ""
  }

### Debug Output/Panic Output

```shell
╷
│ Error: Unsupported argument
│ 
│   on module/container/env_staging.tf line 186, in resource "azurerm_container_app" "oct-staging-auth":
│  186:     ignore_changes = true
│ 
│ An argument named "ignore_changes" is not expected here.
╵

Expected Behaviour

When running terraform plan no updates / changes are made to this block

Actual Behaviour

Unable to run terraform plan. Removing ignore_changes results in terraform advising an update to this block is expected

Steps to Reproduce

Run terraform plan -out tfplan.plan

Important Factoids

no

References

Docs: https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/container_app#secret

ASHR4 commented 7 months ago

Hi @jordanhavard,

This is correct as you're supplying that argument as if it's a part of the resource scheme, which it's not.

If you wish to ignore the changes then wrap it in a lifecycle block as per the docs

resource "azurerm_container_app" "oct-staging-auth" {
  ...
    secret {
        name  = "password"
        identity = var.container-apps-identity-id
        key_vault_secret_id = "https://kv.vault.azure.net/secrets/password"
        value = ""
    } 

    lifecycle {
        ignore_changes = [ secret ]
    }
}
mmillican commented 7 months ago

I am running into this issue as well and the docs are definitely confusing/contradictory.

Ignoring all secret blocks is not reasonable, because what happens when you need to add a new secret to the container?

When attempting to do something like the following, it complains that the blocks cannot be addressed and recommends using a for loop, but that also throws an error because its not a static list.

lifecycle {
  ignore_changes = [
    secret[0].value
  ]
}
jordanhavard commented 7 months ago

Hi @jordanhavard,

This is correct as you're supplying that argument as if it's a part of the resource scheme, which it's not.

If you wish to ignore the changes then wrap it in a lifecycle block as per the docs

resource "azurerm_container_app" "oct-staging-auth" {
  ...
    secret {
        name  = "password"
        identity = var.container-apps-identity-id
        key_vault_secret_id = "https://kv.vault.azure.net/secrets/password"
        value = ""
    } 

    lifecycle {
        ignore_changes = [ secret ]
    }
}

Hey @ASHR4

Can you advise how we should best use this case when setting up a resource and adding a new secret?

Something like @mmillican mentioned below would be nice too as then the key_vault_secret_id could still be updated if using versioned secrets.

lifecycle {
  ignore_changes = [
    secret[0].value
  ]
}
lonegunmanb commented 7 months ago

According to the schema, the secret is a set so we cannot use secret[0] to access it.

I have a question to @jordanhavard:

secret {
    name  = "password"
    identity = var.container-apps-identity-id
    key_vault_secret_id = "https://kv.vault.azure.net/secrets/password"
    ignore_changes = true
    value = ""
  }

It looks like your real password is stored in the key vault, and you've referenced this secret via a versionless id, why you want to ignore change on this password? If you'd like to change the password you can upgrade the secret in your Key Vault, the secret id could stay unchanged.

jordanhavard commented 7 months ago

It looks like your real password is stored in the key vault, and you've referenced this secret via a versionless id, why you want to ignore change on this password? If you'd like to change the password you can upgrade the secret in your Key Vault, the secret id could stay unchanged.

@lonegunmanb Even when doing this, during the plan phase, its mentioned that a change will be made however like you mentioned, this is a versionless id so I was confused as to why this was happening in the first place

lonegunmanb commented 7 months ago

@jordanhavard Could you please share us a minimum example code that could reproduce your issue? Once we can reproduce the issue on our side we can try to solve it. Thanks in advance!

reddyalready commented 6 months ago

I think the documentation might be incorrect here, as it states:

Note: When using key_vault_secret_id, ignore_changes should be used to ignore any changes to value.

But this doesn't seem to be required as no changes are detected on subsequent runs (in my initial forays into this provider).

jorgomehilli commented 4 months ago

Any update on this? Having the exact same issue.

AmiirNabil commented 1 month ago

@jordanhavard I am having the same issue here, as I am using dynamic secret, so I have multiples listed in my Container App, I want to ignore vaule for each of these secrets in ignore_changes . how can we do that?