· 7 years ago · Mar 18, 2018, 07:36 PM
1provider "aws" {
2 access_key = "xxxxxxxxxxxxxx"
3 secret_key = "yyyyyyyyyyyyyyyyyyyyyy"
4 region = "us-west-2"
5}
6
7resource "aws_security_group" "myweb" {
8 name = "web-node"
9 description = "Web Security Group"
10
11 ingress {
12 from_port = 80
13 to_port = 80
14 protocol = "tcp"
15 cidr_blocks = ["0.0.0.0/0"]
16 }
17
18 ingress {
19 from_port = 22
20 to_port = 22
21 protocol = "tcp"
22 cidr_blocks = ["0.0.0.0/0"]
23 }
24
25 egress {
26 from_port = 0
27 to_port = 0
28 protocol = "-1"
29 cidr_blocks = ["0.0.0.0/0"]
30 }
31}
32resource "aws_instance" "myweb" {
33 ami = "ami-7f43f307"
34 instance_type = "t2.micro"
35 key_name = "test"
36 security_groups = ["${aws_security_group.myweb.name}"]
37 tags {
38 Name = "terraform-instance"
39 }
40}