Terraform Questions about project environment variables, qovery_git_token

Hi, i have a couple of Terraform related questions.

1: If you set a project level environment variable. How do you call it from a terraform job?

2: How do you call a git_token from terraform the data source document is empty: Terraform Registry

I tried creating a token via Terraform and getting an output id and then using:

data "qovery_git_token" "github" {
  id = "xxx"
}

but i get an error

 Error: Error on git token read
│ 
│   with data.qovery_git_token.github,
│   on data.tf line 14, in data "qovery_git_token" "github":
│   14: data "qovery_git_token" "github" {
│ 
│ Could not read git token 'xxx', unexpected error: 401 Unauthorized

3: How do you link pipelines together in terraformfor example i want to deploy lifecycle job A, then lifecycle job B then helm deployment C

Hi @Stephen_Bennett ,

Sorry for the late reply here. I know you ended up fixing a lot of those issues yourself, but I will respond for the record.

You can access them the same way you access service scoped variables. There is no difference for your Terraform job.

Did you succeed here?

You have to use the deployment_stage resource and create your different stages.

https://registry.terraform.io/providers/Qovery/qovery/latest/docs/resources/deployment_stage

Then, you can add your service to your different stages with the deployment_stage_id reference.

https://registry.terraform.io/providers/Qovery/qovery/latest/docs/resources/application#deployment_stage_id

Hi,

thanks for the reply!

I still can get a deployment working via Terraform due to git_token

Example terraform:

data "qovery_git_token" "github" {
  id = "9e7fc347-835e-4860-8ce5-93a6dbxxx"
}

resource "qovery_job" "s3" {
  environment_id       = data.qovery_environment.devops.id
  name                 = "oc-aws-s3"
  cpu                  = 3000
  memory               = 2024
  max_nb_restart       = 0
  max_duration_seconds = 899
  auto_preview         = true
  auto_deploy          = true

  source = {

    docker = {
      git_repository = {
        url          = "https://github.com/xxx/oc-aws-s3.git"
        branch       = "master"
        root_path    = "/"
        git_token_id = data.qovery_git_token.github.id
      }
      dockerfile_path = "Dockerfile"
    }

  }

I get error:

 Error: Error on git token read
│ 
│   with data.qovery_git_token.github,
│   on data.tf line 14, in data "qovery_git_token" "github":
│   14: data "qovery_git_token" "github" {
│ 
│ Could not read git token '9e7fc347-835e-4860-8ce5-93a6db5fdd65', unexpected
│ error: 401 Unauthorized

Any ideas?

Hi @Stephen_Bennett , I see that you defined the qovery_git_token resource via the read-only property id

data "qovery_git_token" "github" {
  id = "9e7fc347-835e-4860-8ce5-93a6dbxxx"
}

But I’m not sure it’s possible to use a data type here.

Could you please define the qovery git token resource with

resource "qovery_git_token" "github" {
  # Required
  organization_id = qovery_organization.my_organization.id
  name            = "my-git-token"
  type            = "GITHUB"
  token           = "my-git-provider-token"

  # Optional
  description = "Github token"
}

Example from our provider documentation

Hi,

So i have already got a git token created and i wanted to call that (hense data call not creating one)

If i hardcode the git token i still get the same error: ie:

**strong text**resource "qovery_job" "s3" {
  environment_id       = data.qovery_environment.devops.id
  name                 = "oc-aws-s3"
  cpu                  = 3000
  memory               = 2024
  max_nb_restart       = 0
  max_duration_seconds = 899
  auto_preview         = true
  auto_deploy          = true

  source = {

    docker = {
      git_repository = {
        url          = "https://github.com/openc/oc-aws-s3.git"
        branch       = "master"
        root_path    = "/"
        git_token_id = "xxx"
      }
      dockerfile_path = "Dockerfile"
    }

  }

ignore that! ts good.

There is a issues with if it deploys and has a failure (ie like i had) it would create the service, but then fails on reply saying that

│ Error: Error on job create
│ 
│   with qovery_job.s3,
│   on oc-aws-s3.tf line 1, in resource "qovery_job" "s3":
│    1: resource "qovery_job" "s3" {
│ 
│ failed to create job: Could not create job 'oc-aws-s3', unexpected error: 400 Bad Request - A Job named `oc-aws-s3` already
│ exists

and

╷
│ Error: Error on job create
│ 
│   with qovery_job.s3,
│   on oc-aws-s3.tf line 1, in resource "qovery_job" "s3":
│    1: resource "qovery_job" "s3" {
│ 
│ failed to create job: failed to update variables: Could not create job environment variable 'TF_VAR_aws_access_key_id',
│ unexpected error: 409 Conflict - Variable already exists: TF_VAR_aws_access_key_id

i would expect it to know its deployed those resources right? and not say there are duplicates

S

Hi @Stephen_Bennett ,

sorry for the late reply, do you still have issues?

still an issue im afraid

the error says that you already have a job (lifecycle or cronjob) in the same env with the same name. I can’t really check this but can you verify if the env id sent in the manifest is the right one?

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.