alpine-docker / terragrunt

Auto-trigger docker build for terragrunt when new terraform version released
Apache License 2.0
35 stars 24 forks source link

Cannot set variables into gitlab-ci #29

Closed masbolgankezderim closed 2 months ago

masbolgankezderim commented 2 months ago

When I try set variables via gitlab-ci. I got ERROR bellow, please help

╷
│ Error: Value for undeclared variable
│ 
│ A variable named "function_name" was assigned on the command line, but the
│ root module does not declare a variable of that name. To use this value,
│ add a "variable" block to the configuration.
╵
╷
│ Error: Value for undeclared variable
│ 
│ A variable named "image_uri" was assigned on the command line, but the root
│ module does not declare a variable of that name. To use this value, add a
│ "variable" block to the configuration.
╵
time=2024-04-18T09:26:[30](https://gitlab-test.dev/test-ops/-/jobs/127566#L30)Z level=error
time=2024-04-18T09:26:30Z level=error 
ERROR: Job failed: exit code 1

.gitlab-ci.yaml

deploy:
  stage: deploy-test
  image: 
    name: alpine/terragrunt:1.8.1
  before_script:
    - terragrunt plan -var="function_name=${PROJECT_NAME}" -var="image_uri=123456789.dkr.ecr.${ECR_REGION}.amazonaws.com/${CI_PROJECT_NAME}:${PROJECT_NAME}-${CI_COMMIT_SHORT_SHA}"
  script:
    - terragrunt apply -var="function_name=${PROJECT_NAME}" -var="image_uri=123456789.dkr.ecr.${ECR_REGION}.amazonaws.com/${CI_PROJECT_NAME}:${PROJECT_NAME}-${CI_COMMIT_SHORT_SHA}" --auto-approve

terragrunt.hcl

include "root" {
  path = find_in_parent_folders()
}

terraform {
  source = "https://github.com/terraform-aws-modules/terraform-aws-lambda.git"
}

inputs = {
  function_name   = "var.function_name"
  description     = "My awesome lambda function 5555555"
  create_package  = false
  image_uri       = "var.image_uri"
  package_type    = "Image"
}

terragrunt.hcl in root folder

remote_state {
  backend = "s3"
  generate = {
    path      = "backend.tf"
    if_exists = "overwrite"
  }
  config = {
    bucket         = "test-bucket"
    key            = "${path_relative_to_include()}/terraform.tfstate"
    region         = "eu-north-1"
    encrypt        = true
  }
}

On my local machine terragrunt normaly work

ozbillwang commented 2 months ago

seems that's not the image built in this group

     name: devopsinfra/docker-terragrunt:tf-1.8.0-tg-0.57.1
masbolgankezderim commented 2 months ago

Sorry, that was old ci file right now

Screenshot 2024-04-22 at 13 01 06
ozbillwang commented 2 months ago

Can't help. that's your TG /TF codes. You need figure it out by yourself.