About a problem which I live on 10th question at the lab-terraform-workspaces

Hi all,

I have a problem about 10th question at the lab-terraform-workspaces. Link is Terraform Basics Training Course | KodeKloud

I applied the solution but I met an error like below .

iac-server $ cat main.tf
module “payroll_app” {
source = “/root/terraform-projects/modules/payroll-app”
app_region = lookup(var.region, terraform.workspace)
ami = lookup(var.ami, terraform_workspace)
}iac-server $ terraform init
Initializing modules…
Downloading /root/terraform-projects/modules/payroll-app for payroll_app…

  • payroll_app in .terraform/modules/payroll_app

Initializing the backend…

Initializing provider plugins…

  • Finding hashicorp/aws versions matching “4.15.0”…
  • Installing hashicorp/aws v4.15.0…
  • Installed hashicorp/aws v4.15.0 (self-signed, key ID 34365D9472D7468F)

Partner and community providers are signed by their developers.
If you’d like to know more about provider signing, you can read about it here:

Terraform has been successfully initialized!

You may now begin working with Terraform. Try running “terraform plan” to see
any changes that are required for your infrastructure. All Terraform commands
should now work.

If you ever set or change modules or backend configuration for Terraform,
rerun this command to reinitialize your working directory. If you forget, other
commands will detect it and remind you to do so if necessary.

iac-server $ pwd
/root/terraform-projects/project-sapphire

iac-server $ terraform plan

Warning: Argument is deprecated

Use s3_use_path_style instead.

Error: Invalid reference

on main.tf line 4, in module “payroll_app”:
4: ami = lookup(var.ami, terraform_workspace)

A reference to a resource type must be followed by at least one attribute
access, specifying the resource name.

Could you please help me about solving?

Thank you
Best Regards
Elif

I would like to add an info. When I click the check button it gives an error like this " The configuration in main.tf does not use the app_region based on the workspace we are in!"

According to this error message I controlled which workspace I am in like below I did not see a problem.

iac-server $ terraform workspace list
default
india-payroll
uk-payroll

  • us-payroll

Best Regards
Elif
iac-server $

Hi @Elif-Basargil ,
on line 4, you write terraform_workspace he should be terraform.workspace the right syntax for the main.tf file should be ;

module "payroll_app" {
  source = "/root/terraform-projects/modules/payroll-app"
  app_region = lookup(var.region, terraform.workspace)
  ami        = lookup(var.ami, terraform.workspace)
}

Regard

1 Like