dbt-labs / terraform-provider-dbtcloud

dbt Cloud Terraform Provider
https://registry.terraform.io/providers/dbt-labs/dbtcloud
MIT License
80 stars 18 forks source link

Removing an `environment_values` for `dbtcloud_environment_variable` doesn't remove it in dbt Cloud #221

Closed b-per closed 7 months ago

b-per commented 7 months ago

Describe the bug

Removing an environment_values for an existing dbtcloud_environment_variable resource doesn't remove it in dbt Cloud

Error message

No error message, but the env variable is not removed

Expected behavior

The env var is removed

b-per commented 7 months ago

Setting the value to "" doesn't do anything either

b-per commented 7 months ago

The current resource uses an "older" API technique where we do a PUT on https://emea.dbt.com/api/v3/accounts/<account>/projects/<project>/environment-variables/bulk/ with the body

{
    "env_vars": {
        "DEV": "2",
        "PROD": "",
        "name": "DBT_TF_ENV_VAR",
        "project": "1"
    }
}

If some keys are removed, or provided empty inputs, they are not removed in dbt Cloud.

Some options to fix it would be:

  1. try to add some logic where if a key is removed from env_vars we force the destroy and recreation of the resource
  2. and/or creating a new resource where the resource grain would be at the env_var + scope (e.g. project or env name) rather than just env_var, allowing to destroy specific env_var + scope resources
b-per commented 7 months ago

Option 2 might actually help with allowing people to overwrite the env var on at the job level