-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.tf
executable file
·158 lines (132 loc) · 3.75 KB
/
main.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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
/////REQUIRED PROVIDERS
terraform {
required_providers {
venafi = {
source = "Venafi/venafi"
version = "~> 0.16.0"
}
docker = {
source = "kreuzwerker/docker"
version = "~> 2.22.0"
}
}
}
/////VARIABLE DEFINITIONS
variable "api_key" {
description = "Venafi as a Service API Key"
sensitive = true
}
variable "deploy_target" {
description = "Target deployment environment."
}
/////PROVIDER
provider "venafi" {
api_key = var.api_key
zone = "BankApp\\${var.deploy_target} CA Template"
}
/////VENAFI MACHINE IDENTITY
resource "venafi_certificate" "nginx-bankapp-frontend" {
common_name = "bankapp-frontend.venafidemo.com"
}
resource "venafi_certificate" "nginx-bankapp-processing" {
common_name = "bankapp-processing.venafidemo.com"
}
resource "venafi_certificate" "nginx-bankapp-the-beam" {
common_name = "bankapp-the-beam.venafidemo.com"
}
/////DOCKER
provider "docker" {
host = "tcp://venafi-ecosystem-linux.vm.cld.sr:2376"
}
resource "docker_image" "nginx" {
name = "paulternate/ssl-nginx"
keep_locally = true
}
resource "docker_container" "nginx-bankapp-frontend" {
name = "Bank-App-frontend"
image = docker_image.nginx.image_id
ports {
internal = "443"
external = "8443"
ip = "0.0.0.0"
}
# Inject the key and certificate into the NGINX docker container.
upload {
content = venafi_certificate.nginx-bankapp-frontend.certificate
file = "/etc/nginx/ssl/certificate.pem"
}
upload {
content = venafi_certificate.nginx-bankapp-frontend.private_key_pem
file = "/etc/nginx/ssl/privatekey.pem"
}
upload {
source = "assets/index-frontend.html"
file = "/var/www/index.html"
}
upload {
source = "assets/styles.css"
file = "/var/www/styles.css"
}
upload {
source = "assets/images/background-frontend.png"
file = "/var/www/background.png"
}
}
resource "docker_container" "nginx-bankapp-processing" {
name = "Bank-App-processing"
image = docker_image.nginx.image_id
ports {
internal = "443"
external = "8444"
ip = "0.0.0.0"
}
upload {
content = venafi_certificate.nginx-bankapp-processing.certificate
file = "/etc/nginx/ssl/certificate.pem"
}
upload {
content = venafi_certificate.nginx-bankapp-processing.private_key_pem
file = "/etc/nginx/ssl/privatekey.pem"
}
upload {
source = "assets/index-processing.html"
file = "/var/www/index.html"
}
upload {
source = "assets/styles.css"
file = "/var/www/styles.css"
}
upload {
source = "assets/images/background-processing.png"
file = "/var/www/background.png"
}
}
resource "docker_container" "nginx-bankapp-the-beam" {
name = "Bank-App-the-beam"
image = docker_image.nginx.image_id
ports {
internal = "443"
external = "8445"
ip = "0.0.0.0"
}
upload {
content = venafi_certificate.nginx-bankapp-the-beam.certificate
file = "/etc/nginx/ssl/certificate.pem"
}
upload {
content = venafi_certificate.nginx-bankapp-the-beam.private_key_pem
file = "/etc/nginx/ssl/privatekey.pem"
}
upload {
source = "assets/index-the-beam.html"
file = "/var/www/index.html"
}
upload {
source = "assets/styles.css"
file = "/var/www/styles.css"
}
upload {
source = "assets/images/background-the-beam.png"
file = "/var/www/background.png"
}
}