· 8 years ago · Feb 04, 2018, 07:02 AM
1variable "stage" {}
2variable "access_key" {}
3variable "secret_key" {}
4variable "region" {}
5
6provider "aws" {
7 access_key = "${var.access_key}"
8 secret_key = "${var.secret_key}"
9 region = "${var.region}"
10}
11
12resource "aws_vpc" "328-vpc" {
13 cidr_block = "10.0.0.0/16"
14 instance_tenancy = "default"
15 enable_dns_support = true
16 enable_dns_hostnames = true
17 tags {
18 Name = "328-vpc"
19 }
20}
21
22resource "aws_subnet" "328-external" {
23 vpc_id = "${aws_vpc.328-vpc.id}"
24 cidr_block = "10.0.10.0/24"
25
26 tags {
27 Name = "328-external"
28 }
29}
30
31## route table
32resource "aws_internet_gateway" "328-internet-gw" {
33 vpc_id = "${aws_vpc.328-vpc.id}"
34 tags {
35 Name = "328-vpc"
36 }
37}
38
39## public route table
40resource "aws_route_table" "328-public" {
41 vpc_id = "${aws_vpc.328-vpc.id}"
42 route {
43 cidr_block = "0.0.0.0/0"
44 gateway_id = "${aws_internet_gateway.328-internet-gw.id}"
45 }
46}
47
48resource "aws_route_table_association" "328-external" {
49 subnet_id = "${aws_subnet.328-external.id}"
50 route_table_id = "${aws_route_table.328-public.id}"
51}
52
53resource "aws_main_route_table_association" "328-external" {
54 vpc_id = "${aws_vpc.328-vpc.id}"
55 route_table_id = "${aws_route_table.328-public.id}"
56}
57
58resource "aws_vpn_gateway" "328-vpn-gw" {
59 vpc_id = "${aws_vpc.328-vpc.id}"
60
61 tags {
62 Name = "328vpngateway"
63 }
64}
65
66resource "aws_customer_gateway" "328vpngateway" {
67 bgp_asn = 65000
68 ip_address = "xxx.xxx.xxx.xxx"
69 type = "ipsec.1"
70
71 tags {
72 Name = "328VpnGateway"
73 }
74}
75
76resource "aws_vpn_connection" "328vpn" {
77 vpn_gateway_id = "${aws_vpn_gateway.328-vpn-gw.id}"
78 customer_gateway_id = "${aws_customer_gateway.328vpngateway.id}"
79 type = "ipsec.1"
80 static_routes_only = false
81}