dbt-labs / terraform-provider-dbtcloud

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

Error when creating new environment variables using the dbt_cloud_environment_variable resource #108

Closed subrasub closed 1 year ago

subrasub commented 1 year ago

I am running into an issue while attempting to create an environment variable using the dbt_cloud_environment_variable resource.

Running terraform plan was successful, however, I am unable to apply these changes, as the endpoint is returning a 500 error. Upon investigating the code for this resource, I realized it was using dbt-cloud v3 API, so I attempted to manually create a POST request to the endpoint with the help of v3 API docs, but I was unable to find it. https://github.com/GtheSheep/terraform-provider-dbt-cloud/blob/e65faea6fa1226a129e208d2f33a76582611a94d/pkg/dbt_cloud/environment_variable.go#L87

I am not sure if the endpoint has been deprecated or if there is another issue at hand. Also, I am curious as to why our CircleCI build pipeline did not flag this error - terraform apply command was successful, but had a 500 error within. I would appreciate any help!

GtheSheep commented 1 year ago

Hey @subrasub - Could you please provide a little more context around how this failed? As far as I can tell, as long as your project names match case sensitively then there's no issue? You could try making a request like:

import json, requests
response = requests.post(
    'https://cloud.getdbt.com/api/v3/accounts/<account ID>/projects/<project ID>/environment-variables/bulk/',
    headers={
      'Accept': 'application/json',
      'Content-Type': 'application/json',
      'Authorization': 'Token <token>'
  },
    json={
        'env_var': {
            'new_name': 'DBT_<env var name>',
            'project': '<project level var>',
            '< env 1 >: '< val for env 1 >',
            '< env 2 >: '< val for env 2 >',
            ...
        }
    }
)
response.json()

Could you also please provide any config terraform (with values redacted) where possible so I can attempt to reproduce, please?

github-actions[bot] commented 1 year ago

This issue has been marked as Stale because it has been open for 90 days with no activity. If you would like the issue to remain open, please comment on the issue or else it will be closed in 7 days.