Welcome to the Terraform aws examples repository! This collection includes useful Terraform scripts for various AWS resources.
- create-free-tier-ec2-using-terraform: (Directory) Demonstrates how to create a free-tier AWS EC2 instance using Terraform.
-
Clone the repository:
git clone https://github.com/your-username/terraform-examples.git cd terraform-aws-examples
-
Navigate to the specific example directory like this:
cd create-free-tier-ec2-using-terraform
-
Make sure you have Terraform installed on your local machine. You can download it from Terraform Downloads.
-
Configure your AWS CLI with the necessary credentials. Run
aws configure
and provide your AWS access key ID, secret access key, default region, and output format. -
Navigate to the example directory you are interested in.
-
Initialize Terraform by running:
terraform init
-
Preview the changes with:
terraform plan
-
Apply the changes:
terraform apply
-
To destroy the created resources, run:
terraform destroy
Contributions to this collection of Terraform aws examples are welcome! Feel free to add new examples or improve existing ones.
This project is licensed under the MIT License - see the LICENSE file for details.
terraform version
terraform version -json
Feel free to explore, use, and modify these examples for your Terraform projects. If you have any questions or improvements, please open an issue or submit a pull request.
Happy Terraforming!
# Use the remote-exec provisioner to execute the shell script after the instance is created
# readme: https://developer.hashicorp.com/terraform/language/resources/provisioners/remote-exec
provisioner "file" { source = "${path.module}/script/index.php" destination = "/var/www/html/index.php" connection { type = "ssh" user = var.ssh_username private_key = file("${path.module}/${var.key_name}.pem") host = self.private_ip # Use the public IP of the EC2 instance as the host port = 22 } }