Forked from jjruescas/install_choco_and_packages.ps1
Created
December 12, 2022 15:52
-
-
Save dannybarrientos/1a59899e904aac2be7f5c1197bc38a87 to your computer and use it in GitHub Desktop.
Simple Terraform example that provisions a Linux 2 EC2 Instance and installs Nginx on it.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Install Chocolatey | |
Set-ExecutionPolicy Bypass -Scope Process -Force; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1')) | |
#Install Packages | |
choco install terraform -y | |
choco install awscli -y | |
#Refresh Environment Variables | |
$env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
provider "aws" { | |
region = "us-west-2" | |
} | |
resource "aws_security_group" "instance" { | |
name = "terraform-example-sg" | |
ingress { | |
from_port = 80 | |
to_port = 80 | |
protocol = "tcp" | |
cidr_blocks = ["0.0.0.0/0"] | |
} | |
egress { | |
from_port = 0 | |
to_port = 0 | |
protocol = "-1" | |
cidr_blocks = ["0.0.0.0/0"] | |
} | |
} | |
resource "aws_instance" "web" { | |
ami = "ami-0c5204531f799e0c6" | |
instance_type = "t2.micro" | |
vpc_security_group_ids = [aws_security_group.instance.id] | |
user_data = <<-EOF | |
#!/bin/bash | |
sudo amazon-linux-extras install nginx1.12 -y | |
sudo service nginx start | |
EOF | |
tags = { | |
Name = "HelloWorld" | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
output "public_ip" { | |
value = "${aws_instance.web.public_ip}" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment