· 9 years ago · Nov 02, 2016, 07:48 PM
1provider "aws" {
2 access_key = "${var.aws_access_key}"
3 secret_key = "${var.aws_secret_key}"
4 region = "${var.aws_region}"
5}
6
7variable "coreos_user_data" {
8 description = "user-data for coreos"
9 default = "#cloud-config
10
11coreos:
12 units:
13 - name: docker-tcp.socket
14 command: start
15 enable: true
16 content: |
17 [Unit]
18 Description=Docker Socket for the API
19
20 [Socket]
21 ListenStream=2375
22 BindIPv6Only=both
23 Service=docker.service
24
25 [Install]
26 WantedBy=sockets.target"
27}
28
29resource "aws_security_group" "jenkinsServer" {
30 name = "vpc_jenkinsServer"
31 description = "Allow incoming jenkins connections."
32
33 ingress {
34 from_port = 443
35 to_port = 443
36 cidr_blocks = ["0.0.0.0/0"]
37 }
38
39 ingress {
40 from_port = 22
41 to_port = 22
42 cidr_blocks = ["0.0.0.0/0"]
43 }
44
45 tags {
46 Name = "jenkinsServerSG"
47 }
48}
49
50resource "aws_instance" "jenkins-server" {
51 ami = "${lookup(var.amis, var.aws_region)}"
52 availability_zone = "eu-central-1a"
53 instance_type = "m1.small"
54 key_name = "${var.aws_key_name}"
55 vpc_security_group_ids = ["${aws_security_group.jenkinsServer.id}"]
56 subnet_id = "${aws_subnet.eu-central-1a-management.id}"
57 source_dest_check = false
58
59 tags {
60 Name = "Jenkins Server"
61 }
62}
63variable "aws_access_key" {}
64variable "aws_secret_key" {}
65variable "aws_key_path" {}
66variable "aws_key_name" {}
67
68variable "aws_region" {
69 description = "EC2 Region for the VPC"
70 default = "eu-central-1a"
71}
72
73variable "amis" {
74 description = "AMIs by region"
75 default = {
76 eu-central-1a = "ami-27877c48" #CoreOS
77 }
78}
79
80variable "vpc_cidr" {
81 description = "CIDR for the whole VPC"
82 default = "10.0.0.0/16"
83}
84
85variable "public_subnet_cidr" {
86 description = "CIDR for the Public Subnet"
87 default = "10.0.0.0/24"
88}
89
90variable "private_subnet_cidr" {
91 description = "CIDR for the Private Subnet"
92 default = "10.0.1.0/24"
93}
94
95variable "management_subnet_cidr" {
96 description = "CIDR for the Management subnet"
97 default = "10.1.1.1.1/24"
98}
99resource "aws_vpc" "default" {
100 cidr_block = "${var.vpc_cidr}"
101 enable_dns_hostnames = true
102 tags {
103 Name = "terraform-aws-vpc"
104 }
105}
106
107resource "aws_subnet" "aws_subnet.eu-central-1a-management" {
108 vpc_id = "${aws_vpc.default.id}"
109
110 cidr_block = "${var.management_subnet_cidr}"
111 availability_zone = "eu-central-1a"
112
113 tags {
114 Name = "Management Subnet"
115 }
116}