C2W3 Issues with terraform config files

Issue 1:
In C2W3Lab2, while attempting to do 4.1 - CloudWatch Showcase, I received following error in terraform plan stage.
voclabs:~/environment/terraform $ terraform init
Initializing the backend…
Initializing modules…
Initializing provider plugins…

  • Reusing previous version of hashicorp/aws from the dependency lock file
  • Reusing previous version of hashicorp/local from the dependency lock file
  • Reusing previous version of hashicorp/random from the dependency lock file
  • Reusing previous version of hashicorp/tls from the dependency lock file
  • Using previously-installed hashicorp/aws v5.39.1
  • Using previously-installed hashicorp/local v2.4.1
  • Using previously-installed hashicorp/random v3.6.0
  • Using previously-installed hashicorp/tls v4.0.5

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.
voclabs:~/environment/terraform $ terraform plan
var.private_subnet_a_id
The id of the private subnet in the availability zone A
Enter a value: ^C

Not sure why this happened.

Workaround: I added a tfvars file like below and copied values from CloudFormation output to make it work.

vpc_id = “vpc-0a1707a1e95b74f4d”
public_subnet_a_id = “subnet-09544cc18f53fec2d”
public_subnet_b_id = “subnet-096498feeda81460e”
private_subnet_a_id = “subnet-0b8c08e31e8699417”
private_subnet_b_id = “subnet-0a3aa5da402a8caec”

Issue 2:
This issue is present both in terraform intro lab (C2W3Lab1) and cloudwatch lab (C2W3Lab2).

In main.tf
module “bastion_host” {
source = “./modules/bastion_host”
project = var.project
region = var.region
vpc_id = var.vpc_id
public_subnet_a_id = var.public_subnet_a_id
public_subnet_b_id = var.public_subnet_b_id
private_subnet_a_id = var.public_subnet_a_id
private_subnet_b_id = var.public_subnet_b_id
db_master_username = var.db_master_username
}

It looks like a typo. Though the setup works with this config, I think the intended values are.

private_subnet_a_id = var.private_subnet_a_id
private_subnet_b_id = var.private_subnet_b_id

Hello @Muthukumaran
Regarding the first issue, you might have skipped running source scripts/setup.sh as it is said in step 6 in the Vocareum page. Terraform variables are initialized in the setup.sh file, so you won’t need to use a tfvars file.
As for the second issue, I’m not sure why it is like that. However, as I can see from the lab instructions, bastion host works on the public subnet. Anyway, as you have mentioned, the setup is working with this config.

1 Like