CodexBloom - Programming Q&A Platform

Terraform Provisioner Not Executing After Resource Creation in AWS

👀 Views: 10 đŸ’Ŧ Answers: 1 📅 Created: 2025-06-18
terraform aws provisioner hcl

I'm working through a tutorial and I'm having trouble with a local-exec provisioner in my Terraform configuration that is supposed to run a shell script after an EC2 instance is created. The instance gets created successfully, but the provisioner doesn't seem to execute at all. I've tried adding a few `depends_on` statements to ensure execution order, but that hasn't resolved the scenario. Here's the relevant part of my configuration: ```hcl resource "aws_instance" "my_instance" { ami = "ami-0c55b159cbfafe1f0" # Amazon Linux 2 AMI instance_type = "t2.micro" provisioner "local-exec" { command = "./setup.sh" interpreter = ["bash", "-c"] } tags = { Name = "MyInstance" } } ``` The `setup.sh` script is located in the same directory as my Terraform configuration file and has executable permissions. When I run `terraform apply`, I see the following output: ``` aws_instance.my_instance: Creating... ... aws_instance.my_instance: Creation complete after 60s (ID: i-0abcdef1234567890) behavior: "local-exec" provisioner failed on main.tf line 10, in resource "aws_instance" "my_instance": 10: command = "./setup.sh" The command failed with the following behavior message: ./setup.sh: No such file or directory ``` I've verified that the script runs fine manually from the command line. I've also checked the working directory context in which Terraform is being executed, and it matches where the script is located. Is there something specific about using `local-exec` that could cause this scenario? I've also tried running it on a different machine and got the same behavior. Any insights would be greatly appreciated.