Skip to content

msrajawat298/Terraform-aws-examples

Repository files navigation

Terraform aws examples

Welcome to the Terraform aws examples repository! This collection includes useful Terraform scripts for various AWS resources.

Directory Structure:

  • create-free-tier-ec2-using-terraform: (Directory) Demonstrates how to create a free-tier AWS EC2 instance using Terraform.

Usage:

  1. Clone the repository:

    git clone https://github.com/your-username/terraform-examples.git
    cd terraform-aws-examples
  2. Navigate to the specific example directory like this:

    cd create-free-tier-ec2-using-terraform

Getting Started

  1. Make sure you have Terraform installed on your local machine. You can download it from Terraform Downloads.

  2. 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.

  3. Navigate to the example directory you are interested in.

  4. Initialize Terraform by running:

    terraform init
  5. Preview the changes with:

    terraform plan
  6. Apply the changes:

    terraform apply
  7. To destroy the created resources, run:

    terraform destroy

Contributions

Contributions to this collection of Terraform aws examples are welcome! Feel free to add new examples or improve existing ones.

License

This project is licensed under the MIT License - see the LICENSE file for details.

About Terraform

Terraform Useful commands

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 } }

provisioner "remote-exec" {

inline = [

"chmod +x /tmp/script.sh",

"/tmp/script.sh",

]

connection {

type = "ssh"

user = var.ssh_username

host = self.private_ip # Use the public IP of the EC2 instance as the host

private_key = file("${path.module}/${var.key_name}.pem")

agent = false

}

}

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published