Course 1 Week 4 Programming Assignment 3

There was an error after running terraform plan. I tried to redo the assignment many times, and this part always giving me error.

│ Error: Error acquiring the state lock

│ Error message: resource temporarily unavailable
│ Lock Info:
│ ID:
│ Path: /home/coder/.local/share/code-server/User/de-c1w4-XXXXXXXXXXX-us-east-1-terraform-state.state
│ Operation: OperationTypePlan
│ Who:
│ Version: 1.9.8
│ Created: 2025-06-11 16:40:15.019620742 +0000 UTC
│ Info:


│ Terraform acquires a state lock to protect the state from being written
│ by multiple users at the same time. Please resolve the issue above and try
│ again. For most commands, you can disable locking with the “-lock=false”
│ flag, but this is not recommended.

@Aloha1 A couple of questions for you:

  • at what step you got this error?
  • did you have to halt any previous terraform commands? (by typing for example CTRL+X)

Hi @hawraa.salami ,

Thank you for your response to my post. I got this error after I run the first “terraform plan” command given in the 1.11 instruction.

Thanks.

Okay, and regarding my second question,

in step 1.10, did you have to stop or halt that command? Did anything unexpectedly happen in the environment before you received that error?

No, I didn’t stop the command (terraform init). It executed successfully.

@Aloha1 One last question before I suggest what to do:

you said you redid the assignment many times: did you wait for the two hours to finish and start the lab again and still encounter the same problem?

With my first few attempts, it was past 2 hrs before I redid. However, for the last 2 attempts wherein I encountered that error, I didn’t wait for 2 hrs.

Is it possible that if I redo the lab, all the Terraform files are new? I might have accidentally deleted something from the main, outputs, or other files. I noticed that after leaving the lab, the Terraform folder still retains the previous files. But every time I relaunch the lab, shouldn’t the files always be freshly generated?

@Aloha1 The lab files do not automatically reset. You would need to do that manually:

  • Either delete all your current files or create a folder (old_lab_files) and then move all your current files to that folder.
  • click on the question mark on the top right
  • click on “get latest version”

You should see the fresh lab files.

Thank you. I’m trying it now.

The problem is really in the terraform plan. After I ran “terraform init” successfully, I executed terraform plan, and it asked me to enter a value

var.data_lake_bucket
S3 Bucket for Data lake

Enter a value:

var.db_sg_id
Security group ID for RDS

Enter a value:

var.project
Project name

Enter a value:

var.public_subnet_a_id
Public subnet A ID

Enter a value:

var.public_subnet_b_id
Public subnet B ID

Enter a value:

var.recommendations_bucket
S3 Bucket for Recommendations results

Enter a value:

var.region
AWS Region

Enter a value:

var.scripts_bucket
S3 Bucket for Glue scripts

Enter a value:

var.source_host
RDS host

Enter a value:

var.source_username
RDS username

Enter a value:

var.vpc_id
VPC ID

@Aloha1 Did you make to run source scripts/setup.sh?

Anytime you got prompted to enter values for terraform variables, you can cut the process (CTRL C) and then run again source scripts/setup.sh

Everytime you open a new terminal, you have to run source scripts/setup.sh

Hi @hawraa.salami. I didn’t do that. Let me try it. I don’t get that “Enter a value” if I reboot and try it again. Thanks for your response. I appreciate it.