CircleCI-Public / terraform-orb

Deploy your infrastructure via a CircleCI pipeline using the Terraform orb. Integrate Infrastructure-as-Code (IaC) to help provision and manage any cloud, infrastructure, or service of your choice.
https://circleci.com/orbs/registry/orb/circleci/terraform
MIT License
10 stars 44 forks source link

(1) Can't install, (2) Can't validate #101

Closed aprilmintacpineda closed 1 week ago

aprilmintacpineda commented 12 months ago

Orb Version circleci/terraform@3.2.1

I have the following code in my circle ci file

terraformation:
  executor: terraform/default
  steps:
    - attach_workspace:
        at: ~/project
    - aws-cli/setup:
        aws_access_key_id: AWS_ACCESS_KEY_ID
        aws_secret_access_key: AWS_SECRET_ACCESS_KEY
        region: ap-southeast-1
    - terraform/install:
        terraform_version: 1.6.3
    - run:
        name: TFVars
        command: |
          rm -rf terraform.tfvars
          touch terraform.tfvars
          //.. bunch of echoes that to terraform.tfvars like echo 'something = "something"' >> terraform.tfvars
          cat terraform.tfvars
    - terraform/init
    - terraform/validate
    - terraform/apply

I'm getting 2 errors here,

Here's the first one: image

The 2nd one is when I remove the terraform/install step, I will get the following Screen Shot 2023-11-11 at 6 27 07 PM

I have tested these variables locally and when I run terraform validate, I don't get any errors.

The variables.tf file:

variable "project_name" {
  type = string
}

variable "stage" {
  type = string

  validation {
    condition     = contains(["development", "staging", "production"], var.stage)
    error_message = "Allowed values for stage are \"development\", \"staging\", and \"production\""
  }
}

variable "aws_region" {
  type = string
}

variable "hosted_zone_id" {
  type = string
}

variable "hosted_zone_name" {
  type = string
}

variable "images_server_subdomain" {
  type    = string
  default = ""
}

variable "cache_policy_id" {
  type = string
}

variable "origin_request_policy_id" {
  type = string
}

To Reproduce

Expected behavior

Additional context

aprilmintacpineda commented 11 months ago

I opted out of using this orb and instead used this:

terraformation:
  machine:
    image: ubuntu-2004:202010-01
  steps:
    - attach_workspace:
        at: ~/project
    - run:
        name: Install terraform
        command: |
          sudo apt-get update && sudo apt-get install -y gnupg software-properties-common
          wget -O- https://apt.releases.hashicorp.com/gpg | gpg --dearmor | sudo tee /usr/share/keyrings/hashicorp-archive-keyring.gpg
          wget -O- https://apt.releases.hashicorp.com/gpg | gpg --dearmor | sudo tee /usr/share/keyrings/hashicorp-archive-keyring.gpg
          gpg --no-default-keyring --keyring /usr/share/keyrings/hashicorp-archive-keyring.gpg --fingerprint
          echo "deb [signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] https://apt.releases.hashicorp.com $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/hashicorp.list
          sudo apt update
          sudo apt-get install terraform
          terraform --version
    - run:
        name: TFVars
        command: |
          rm -rf variables.tfvars
          touch variables.tfvars
          // ... setup tf vars
    - run:
        name: Terraform deployment
        command: |
          terraform init
          terraform apply

This works.

pielu commented 7 months ago

The first error most likely comes from using an image with dash as sh not bash. When looking at the orb's code one can see the <<< redirection that won't work on dash.

exarkun commented 4 months ago

The first error most likely comes from using an image with dash as sh not bash. When looking at the orb's code one can see the <<< redirection that won't work on dash.

If the Orb requires bash, it should probably ask for bash. The default shell is bash unless bash isn't installed, then it's sh. If bash is required, the script should at least check for it and report a meaningful error if it isn't available.

But, it's not like the script does anything terribly complex so it could probably also just be written as valid sh.

marboledacci commented 1 week ago

The first problem as was already mentioned, is related to bash not being part of the executor, using an executor with bash installed should solve the problem.

The second problem is also related to the executor, you removed the terraform/install step, so you are using the terraform on the image, and you were using the default executor without parameters so it uses terraform 1.0.0. The message you showed was about the error message you used on the validation of the variable, which was not valid on terraform 1.0.0, you probably were using a newer version locally and that's why it worked

I'm closing this as I consider these two problems solved with this explanation, but we will update the orb to make it more consistent.