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

docs: example - how to fail during apply when a service token is used… #244

Closed
wants to merge 1 commit into from

Conversation

matthiasng
Copy link

While migrating our dbt resoruces to terraform i encounter the gitlab integration issue #192 where you cant create a working repository in dbt with a service token. A big problem for me is that we will use the module I'm writing to create new dbt environments/jobs/projects in the future, but the apply stage doesn't throw an error when a service token is used.

So here is a small example of how to throw an error during the apply phase when a service token is used to create a Gitlab repository.

@b-per
Copy link
Collaborator

b-per commented Mar 25, 2024

Thanks for that!
I will get the docs updated in the next release with those examples.

Not being ultra familiar with null_resource, is it fair to say that for Terraform 1.4+ we could also use the new terraform_data resource?

resource "terraform_data" "check_repository" {
  lifecycle {
    precondition {
      condition     = dbtcloud_repository.gitlab_repo.repository_credentials_id != 0
      error_message = "Repositories created with a service token are currently not working properly (https://github.com/dbt-labs/terraform-provider-dbtcloud/issues/192)"
    }
  }
}

@b-per b-per self-assigned this Mar 25, 2024
@b-per b-per added the documentation Improvements or additions to documentation label Mar 25, 2024
@matthiasng
Copy link
Author

I just tested it and terraform_data seems to work similar to null_resource in this case.

@b-per
Copy link
Collaborator

b-per commented Apr 1, 2024

I am thinking a bit more about it and I actually could/should add this check in the provider code itself. If repository_credentials_id = 0 then raise an error message that it might be due to using a service token.

@matthiasng
Copy link
Author

That would be even better. If you run the check right after creating the repository, you could also try to remove it so that no broken repository is left behind (which is the case with my workaround)

@b-per
Copy link
Collaborator

b-per commented Apr 8, 2024

Handled in the logic in #246

@b-per b-per closed this Apr 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants