· 7 years ago · Nov 10, 2018, 02:20 AM
1#
2# Variables
3#
4variable "aws_access_key" {}
5variable "aws_secret_key" {}
6variable "region" {
7 default = "ap-southeast-2"
8}
9variable "subnets" {
10 type = "list"
11 default = ["10.0.101.0/24", "10.0.102.0/24", "10.0.103.0/24"]
12}
13
14
15#
16# Create an AWS Provider
17#
18provider "aws" {
19 access_key = "${var.aws_access_key}"
20 secret_key = "${var.aws_secret_key}"
21 region = "${var.region}"
22}
23
24
25#
26# Create a VPC
27#
28resource "aws_vpc" "main" {
29 cidr_block = "10.0.0.0/16"
30 tags {
31 Name = "Infocentric Training VPC"
32 }
33}
34
35output "vpc_id" {
36 value = "${aws_vpc.main.id}"
37}
38
39output "vpc_arn" {
40 value = "${aws_vpc.main.arn}"
41}
42
43#
44# Create some subnets
45#
46
47resource "aws_subnet" "main" {
48 count = "${length(var.subnets)}"
49 vpc_id = "${aws_vpc.main.id}"
50 cidr_block = "${element(var.subnets, count.index)}"
51 tags {
52 Name = "Subnet_${count.index+1}"
53 }
54}
55
56
57#
58# Create an internet gateway
59#
60
61
62
63
64#
65# Create an EC2 instance for Jenkins
66#