QOVERY Terraform resource error

Hi, when running terraform to create qovery environments im getting an error but it still creates an environment / lifecycle job.

resource "qovery_job" "terraform" {
  environment_id       = qovery_environment.this.id
  name                 = "openc-consumption - Terraform"
  cpu                  = 500
  memory               = 512
  max_nb_restart       = 0
  max_duration_seconds = 1800
  auto_preview         = false
  auto_deploy          = false

  source = {
    docker = {
      git_repository = {
        url          = "https://github.com/openc/openc-consumption.git"
        branch       = "DEV-1610-iac"
        root_path    = "/infra"
        git_token_id = "9e7fc347-835e-4860-8ce5-93a6db5fdd65"
      }
      dockerfile_path = "Dockerfile"
    }
  }

  schedule = {
    on_start = {
      arguments  = ["-c", "terraform apply -no-color -auto-approve && terraform output -json > /qovery-output/qovery-output.json"],
      entrypoint = ""
    }

    on_delete = {
      arguments  = ["-c", "terraform destroy -no-color -auto-approve"],
      entrypoint = ""
    }
  }

  deployment_stage_id = qovery_deployment_stage.terraform.id

  healthchecks = {}

  #    deployment_restrictions = [

  #    ]

  #    advanced_settings_json = jsonencode(
  #         {
  #   "build.timeout_max_sec" : 1800,
  #   "build.cpu_max_in_milli" : 4000,
  #   "build.ram_max_in_gib" : 8,
  #   "deployment.affinity.node.required" : { },
  #   "deployment.termination_grace_period_seconds" : 60,
  #   "job.delete_ttl_seconds_after_finished" : null,
  #   "cronjob.concurrency_policy" : "Forbid",
  #   "cronjob.failed_jobs_history_limit" : 1,
  #   "cronjob.success_jobs_history_limit" : 1,
  #   "security.service_account_name" : "",
  #   "security.read_only_root_filesystem" : false,
  #   "security.automount_service_account_token" : false
  # }
  #    )
}

Generates error:

Error: Error on job create
β”‚ 
β”‚   with qovery_job.terraform,
β”‚   on lifecycle-job.tf line 1, in resource "qovery_job" "terraform":
β”‚    1: resource "qovery_job" "terraform" {
β”‚ 
β”‚ failed to create job: Could not create job 'openc-consumption - Terraform', unexpected error: data failed to match schemas in oneOf(JobResponse)

But you can still see a new env and lifecycle job created in the UI

Hey @Stephen_Bennett ,

which version of our Terraform provider are you using? can you please try again with the latest? (0.28.9)

Hi Upgraded and now it generates error:

β”‚ Error: Error on environment read
β”‚ 
β”‚   with qovery_environment.this,
β”‚   on environment.tf line 1, in resource "qovery_environment" "this":
β”‚    1: resource "qovery_environment" "this" {
β”‚ 
β”‚ failed to get environment: Could not read environment '941a6f1b-c8b6-4a27-8b5f-259304f31c06', unexpected error: 404 Not Found - Cannot find organization for Environment
β”‚ 941a6f1b-c8b6-4a27-8b5f-259304f31c06

related code:

resource "qovery_deployment" "deployment" {
  depends_on = [
    qovery_deployment_stage.terraform
  ]
  environment_id = qovery_environment.this.id
  desired_state  = "STOPPED"
}

resource "qovery_deployment_stage" "terraform" {
  environment_id = qovery_environment.this.id
  name           = "Terraform"
  description    = "Deploys Terraform resources for openc-consumption"
}

I copied the code for a new deployment and this ran successfully (with a new environment name),

I have deleted the env manually and re-run it and still get this error, so guessing its because an environment with the same name was created and dropped?

could it be possible that the env is still in your state file? indeed I confirm that the env doesn’t exist anymore so it’s weird that it is still pulling that ID from our backend

sigh yes! deleted the local files and forgot to remove the statefile. Thats working ty

1 Like

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