Last active
February 14, 2018 10:53
-
-
Save cocoy/2a0c41597c47c64fd4f9b3c73b49b86f to your computer and use it in GitHub Desktop.
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
### NOTE: | |
### You need to input your ACCESS_KEY, SECRET_KEY, KEYPAIR_NAME, VPC_ID | |
### | |
provider "aws" { | |
access_key = "YOUR_ACCESS_KEY" | |
secret_key = "YOUR_SECRET_KEY" | |
region = "us-west-2" | |
} | |
## Instance Declaration | |
resource "aws_instance" "example" { | |
ami = "ami-9ee24ffe" | |
instance_type = "t2.small" | |
key_name = "CHANGE_THIS_TO_KEYPAIR_NAME" | |
vpc_security_group_ids = ["${aws_security_group.terraform.id}"] | |
tags { | |
environment = "development" | |
server = "web" | |
name= "ansible-aws-web" | |
} | |
connection { | |
# The default username for our AMI | |
user = "ubuntu" | |
# The connection will use the local SSH agent for authentication. | |
} | |
## using ansible | |
provisioner "ansible" { | |
connection { | |
user = "ubuntu" | |
} | |
playbook = "playbook.yml" | |
hosts = ["all"] | |
plays = ["terraform"] | |
groups = ["terraform"] | |
#extra_vars = { "extra_var":"terraform"} | |
} | |
} | |
resource "aws_security_group" "terraform" { | |
name = "terraform" | |
description = "terraform VPC security group" | |
vpc_id = "CHANGE_TO_YOUR_VPC_ID" | |
# SSH access from anywhere | |
ingress { | |
from_port = 22 | |
to_port = 22 | |
protocol = "tcp" | |
cidr_blocks = ["0.0.0.0/0"] | |
} | |
# HTTP access from the VPC | |
ingress { | |
from_port = 80 | |
to_port = 80 | |
protocol = "tcp" | |
cidr_blocks = ["0.0.0.0/0"] | |
} | |
# outbound internet access | |
egress { | |
from_port = 0 | |
to_port = 0 | |
protocol = "-1" | |
cidr_blocks = ["0.0.0.0/0"] | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment