-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathaws.tf
114 lines (91 loc) · 2.67 KB
/
aws.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# Script to create 3 Centos-7 instances on AWS with 2 network interfaces
# suitable for use with Contiv.
# How to use:
# Create terraform.tfvars file and define with correct values for your setup:
# aws_access_key = "XXXXXXXXXXXXXXXXXX"
# aws_secret_key = "XXXXXXXXXXXXXXXXXX"
# ssh_keypair = "foo.pem"
# key_path = "/full/path/to/foo.pem"
# our_security_group_id "sg-XXXXX"
# our_vpc_id = "vpc-XXXXXXXX"
# terraform apply
terraform {
required_version = "> 0.8.0"
}
# optional:
# define buildnum to use for the "name" tag for instances, and subnet.
#
# Normally set by our CI build system (Jenkins)
#
# eg. buildnum=103, creates instances named:
# jenkins-netplugin-103-0
# jenkins-netplugin-103-1
# jenkins-netplugin-103-2
#
# makes it easy to spot and clean-up if something goes wrong
variable "buildnum" {
description = "Jenkins buildnum"
default = "007"
}
# ============================================
# Authentication
provider "aws" {
access_key = "${var.aws_access_key}"
secret_key = "${var.aws_secret_key}"
region = "${var.aws_region}"
}
# defined in terraform.tfvars
variable "aws_access_key" {}
variable "aws_secret_key" {}
# NOTE: keys can only be alphanumeric. no special characters (- _ +)
# while these are valid for AWS, Terraform barfs on them (bug?)
variable "aws_region" {
default = "us-west-1"
}
variable "aws_availability_zone" {
default = "us-west-1b"
}
# ============================================
# EC2 Instance definition
resource "aws_instance" "jenkins_netplugin" {
ami = "${var.aws_ami}"
instance_type = "${var.aws_instance_type}"
key_name = "${var.ssh_keypair}"
count = "${var.num_nodes}"
# Network interface #1 (eth0)
vpc_security_group_ids = ["${var.our_security_group_id}"]
# only available for certain instance types
#ebs_optimized = "true"
root_block_device {
delete_on_termination = "true"
}
tags {
# this is the "Name" field in the Instances view.
Name = "Jenkins-Netplugin-${var.buildnum}-${count.index}"
}
}
# defined in aws.tfvars
variable "our_security_group_id" {}
variable "our_vpc_id" {}
variable "ssh_keypair" {}
variable "key_path" {}
variable "aws_ami" {
default = "ami-7c280d1c" # CentOS 7 AMI
}
variable "aws_instance_type" {
default = "t2.small"
}
# how many VMs to spin up.
#
# default test setup needs 3 VMs.
variable "num_nodes" {
default = "3"
}
# ============================================
# Output section
output "public_ip_addresses" {
value = ["${aws_instance.jenkins_netplugin.*.public_ip}"]
}
output "private_ip_addresses" {
value = ["${aws_instance.jenkins_netplugin.*.private_ip}"]
}