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

dbtcloud_global_connection resource is not properly assigning the connection id when used in dbtcloud_environment resource. #311

Open
akulasanthosh opened this issue Oct 28, 2024 · 6 comments
Labels
Awaiting Response Waiting for response from reporter bug Something isn't working

Comments

@akulasanthosh
Copy link

Describe the bug

dbtcloud_global_connection resource is not properly assigning the connection id when used in dbtcloud_environment resource.
for example if i create 4 differenet connections using global connection resource and refer them individually in different environmnets each what we see is the connection which gets created first will be referenced to all the 4 environments and other 3 connections are refereenced in zero environments.

Error message

no error

Resource configuration

resource "dbtcloud_global_connection" "my_connection_dev" {
name = "terraform_snowflake_testing_proj_dev"
snowflake = {
account = "salesforce_poc"
database = "RAW_DEV"
warehouse = "DEMO_WH_DEV"
}
}

resource "dbtcloud_global_connection" "my_connection_qa" {
name = "terraform_snowflake_testing_proj_qa"
snowflake = {
account = "salesforce_poc"
database = "RAW_QA"
warehouse = "DEMO_WH_QA"
}
}

resource "dbtcloud_environment" "my_dev" {
dbt_version = "versionless"
name = "Dev"
project_id = dbtcloud_project.my_project.id
type = "development"
connection_id = dbtcloud_global_connection.my_connection_dev.id
credential_id = dbtcloud_snowflake_credential.dev_credential.credential_id
}

resource "dbtcloud_environment" "my_qa" {
dbt_version = "versionless"
name = "QA"
project_id = dbtcloud_project.my_project.id
type = "deployment"
connection_id = dbtcloud_global_connection.my_connection_qa.id
credential_id = dbtcloud_snowflake_credential.qa_credential.credential_id
}

Expected behavior

each connection should refer to their respective environment defined in the code

Config (please complete the following information):

( the version can be retrieved running the command terraform providers )

  • dbt Cloud provider version [v0.3.13]

Additional context

Add any other context about the problem here.

@akulasanthosh akulasanthosh added the bug Something isn't working label Oct 28, 2024
@b-per
Copy link
Collaborator

b-per commented Oct 28, 2024

Hi @akulasanthosh .

I tried to reproduce it but couldn't.

Does the rest of your config contains a dbtcloud_project_connection? And if so, can you remove it and try applying changes again?

People should use wither the old approach of dbtcloud_project_connection + the legacy connections or stop using dbtcloud_project_connection and use dbtcloud_global_connection + set the connection_id in dbtcloud_environment.

I will update the docs on dbtcloud_project_connection anyway to add a warning that it shouldn't be used anymore.

@b-per b-per added the Awaiting Response Waiting for response from reporter label Oct 28, 2024
@T-Dunlap
Copy link

@b-per - I just jumped on a call and got eyes on the issue. The first time Santhosh runs a terraform apply, all the environments are tied to the my_connection_dev global connection. If he runs terraform apply a second time, the environments are then mapped to the proper global connections.

I was also able to confirm that there is no dbtcloud_project_connection, only dbtcloud_global_connection in the script.

Here is a recording of the issue

@b-per
Copy link
Collaborator

b-per commented Oct 28, 2024

Thanks! I looked at the recording and I also don't understand why a depends_on is fixing the issue here. This feels more like a Terraform issue than a provider issue (Terraform would be the one building the internal DAG of resources based on the dynamic parameters...).

Could you share what Terraform version you are using? (not the provider but Terraform itself)

Also, I have doubts that it will fix it, but could you try installing the latest version of the provider? It should be 0.3.19 now.

Another shot in the dark but could you also share the output of terraform graph?

@akulasanthosh
Copy link
Author

Hi, Thanks for checking, v1.9.7 is the terraform version. i dont think either it will work in a different terraform version.

@akulasanthosh
Copy link
Author

(venv) (base) santhosh.akula@santhos-ltmdelw dbt_terraform % cat graph.dot
digraph G {
rankdir = "RL";
node [shape = rect, fontname = "sans-serif"];
"dbtcloud_environment.my_dev" [label="dbtcloud_environment.my_dev"];
"dbtcloud_environment.my_prod" [label="dbtcloud_environment.my_prod"];
"dbtcloud_environment.my_qa" [label="dbtcloud_environment.my_qa"];
"dbtcloud_environment.my_stg" [label="dbtcloud_environment.my_stg"];
"dbtcloud_global_connection.my_connection_dev" [label="dbtcloud_global_connection.my_connection_dev"];
"dbtcloud_global_connection.my_connection_prd" [label="dbtcloud_global_connection.my_connection_prd"];
"dbtcloud_global_connection.my_connection_qa" [label="dbtcloud_global_connection.my_connection_qa"];
"dbtcloud_global_connection.my_connection_stg" [label="dbtcloud_global_connection.my_connection_stg"];
"dbtcloud_group_partial_permissions.okta_group" [label="dbtcloud_group_partial_permissions.okta_group"];
"dbtcloud_license_map.dev_license_map" [label="dbtcloud_license_map.dev_license_map"];
"dbtcloud_project.my_project" [label="dbtcloud_project.my_project"];
"dbtcloud_project_repository.my_project_repository" [label="dbtcloud_project_repository.my_project_repository"];
"dbtcloud_repository.my_repository" [label="dbtcloud_repository.my_repository"];
"dbtcloud_snowflake_credential.dev_credential" [label="dbtcloud_snowflake_credential.dev_credential"];
"dbtcloud_snowflake_credential.prd_credential" [label="dbtcloud_snowflake_credential.prd_credential"];
"dbtcloud_snowflake_credential.qa_credential" [label="dbtcloud_snowflake_credential.qa_credential"];
"dbtcloud_snowflake_credential.stg_credential" [label="dbtcloud_snowflake_credential.stg_credential"];
"dbtcloud_environment.my_dev" -> "dbtcloud_global_connection.my_connection_dev";
"dbtcloud_environment.my_dev" -> "dbtcloud_snowflake_credential.dev_credential";
"dbtcloud_environment.my_prod" -> "dbtcloud_global_connection.my_connection_prd";
"dbtcloud_environment.my_prod" -> "dbtcloud_snowflake_credential.prd_credential";
"dbtcloud_environment.my_qa" -> "dbtcloud_global_connection.my_connection_qa";
"dbtcloud_environment.my_qa" -> "dbtcloud_snowflake_credential.qa_credential";
"dbtcloud_environment.my_stg" -> "dbtcloud_global_connection.my_connection_stg";
"dbtcloud_environment.my_stg" -> "dbtcloud_snowflake_credential.stg_credential";
"dbtcloud_project_repository.my_project_repository" -> "dbtcloud_repository.my_repository";
"dbtcloud_repository.my_repository" -> "dbtcloud_project.my_project";
"dbtcloud_snowflake_credential.dev_credential" -> "dbtcloud_project.my_project";
"dbtcloud_snowflake_credential.prd_credential" -> "dbtcloud_project.my_project";
"dbtcloud_snowflake_credential.qa_credential" -> "dbtcloud_project.my_project";
"dbtcloud_snowflake_credential.stg_credential" -> "dbtcloud_project.my_project";
}

@b-per
Copy link
Collaborator

b-per commented Oct 29, 2024

The graph looks good. Would you be able to try a brand new Terraform project with the provider at the latest version (0.3.20 was released yesterday), to see if there is any behavior change?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Awaiting Response Waiting for response from reporter bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants