forked from Venafi/terraform-provider-venafi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.tf
253 lines (213 loc) · 5.18 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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
/*
This is an example Terraform file to show capabilities of the VCert integration.
*/
variable "CLOUD_APIKEY" {
default = ""
}
variable "CLOUD_ZONE" {
default = ""
}
variable "CLOUD_URL" {
default = ""
}
variable "TPP_USER" {
default = ""
}
variable "TPP_PASSWORD" {
default = ""
}
variable "TPP_URL" {
default = ""
}
variable "TPP_ZONE" {
default = ""
}
variable "TRUST_BUNDLE" {
default = ""
}
variable "TPP_ACCESS_TOKEN" {
default = ""
}
resource "random_string" "cn" {
length = 5
special = false
upper = false
number = false
}
/*
Here we are configuring the providers using provider aliases.
Dev provider configuration (alias = "dev") for testing; it doesn't need any external sources configured.
*/
provider "venafi" {
alias = "dev"
dev_mode = true
}
/*
VaaS provider configuration (alias = "vaas")
Here we are getting credentials from variables TF_VAR_CLOUDAPIKEY and TF_VAR_CLOUDZONE
*/
provider "venafi" {
alias = "vaas"
api_key = var.CLOUD_APIKEY
zone = var.CLOUD_ZONE
url = var.CLOUD_URL
}
/*
Platform provider configuration (alias = "tpp")
*/
provider "venafi" {
alias = "tpp"
url = var.TPP_URL
tpp_username = var.TPP_USER
tpp_password = var.TPP_PASSWORD
zone = var.TPP_ZONE
trust_bundle = file(var.TRUST_BUNDLE)
}
/*
Platform provider configuration with Token (alias = "tpp_token")
*/
provider "venafi" {
alias = "tpp_token"
url = var.TPP_URL
access_token = var.TPP_ACCESS_TOKEN
zone = var.TPP_ZONE
trust_bundle = file(var.TRUST_BUNDLE)
}
//Certificate resource definition
resource "venafi_certificate" "dev_certificate" {
//Name of the used provider
provider = venafi.dev
common_name = "dev-${random_string.cn.result}.venafi.example.com"
//Key encryption algorithm
algorithm = "RSA"
//DNS aliases
san_dns = [
"dev-web01-${random_string.cn.result}.example.com",
"dev-web02-${random_string.cn.result}.example.com",
]
//IP aliases
san_ip = [
"10.1.1.1",
"192.168.0.1",
]
//Email aliases
san_email = [
"dev@venafi.com",
"dev2@venafi.com",
]
//private key password
key_password = "xxxxx"
}
//output certificate
output "cert_certificate_dev" {
value = venafi_certificate.dev_certificate.certificate
}
//output certificate chain
output "cert_chain_dev" {
value = venafi_certificate.dev_certificate.chain
}
//output private key
output "cert_private_key_dev" {
sensitive = true
value = venafi_certificate.dev_certificate.private_key_pem
}
resource "venafi_certificate" "dev_certificate_ecdsa" {
provider = venafi.dev
common_name = "dev-${random_string.cn.result}.venafi.example.com"
algorithm = "ECDSA"
san_dns = [
"dev-web01-${random_string.cn.result}.example.com",
"dev-web02-${random_string.cn.result}.example.com",
]
san_ip = [
"10.1.1.1",
"192.168.0.1",
]
san_email = [
"dev@venafi.com",
"dev2@venafi.com",
]
key_password = "xxxxx"
}
output "cert_certificate_dev_ecdsa" {
value = venafi_certificate.dev_certificate_ecdsa.certificate
}
output "cert_chain_dev_ecdsa" {
value = venafi_certificate.dev_certificate_ecdsa.chain
}
output "cert_private_key_dev_ecdsa" {
sensitive = true
value = venafi_certificate.dev_certificate_ecdsa.private_key_pem
}
resource "venafi_certificate" "vaas_certificate" {
provider = venafi.vaas
common_name = "vaas-${random_string.cn.result}.venafi.example.com"
}
output "cert_certificate_vaas" {
value = venafi_certificate.vaas_certificate.certificate
}
output "cert_chain_vaas" {
value = venafi_certificate.vaas_certificate.chain
}
output "cert_private_key_vaas" {
sensitive = true
value = venafi_certificate.vaas_certificate.private_key_pem
}
resource "venafi_certificate" "tpp_certificate" {
provider = venafi.tpp
common_name = "tpp-${random_string.cn.result}.venafi.example.com"
algorithm = "RSA"
rsa_bits = "2048"
san_dns = [
"tpp-${random_string.cn.result}-web01.example.com",
"tpp-${random_string.cn.result}-web02.example.com",
]
san_ip = [
"10.1.1.1",
"192.168.0.1",
]
san_email = [
"tpp@venafi.com",
"tpp2@venafi.com",
]
key_password = "xxxxx"
}
output "cert_certificate_tpp" {
value = venafi_certificate.tpp_certificate.certificate
}
output "cert_chain_tpp" {
value = venafi_certificate.tpp_certificate.chain
}
output "cert_private_key_tpp" {
sensitive = true
value = venafi_certificate.tpp_certificate.private_key_pem
}
resource "venafi_certificate" "token_certificate" {
provider = venafi.tpp_token
common_name = "tpp-${random_string.cn.result}.venafi.example.com"
algorithm = "RSA"
rsa_bits = "2048"
san_dns = [
"tpp-${random_string.cn.result}-web01.example.com",
"tpp-${random_string.cn.result}-web02.example.com",
]
san_ip = [
"10.1.1.1",
"192.168.0.1",
]
san_email = [
"tpp@venafi.com",
"tpp2@venafi.com",
]
key_password = "xxxxx"
}
output "cert_certificate_token" {
value = venafi_certificate.token_certificate.certificate
}
output "cert_chain_tpp_token" {
value = venafi_certificate.token_certificate.chain
}
output "cert_private_key_token" {
sensitive = true
value = venafi_certificate.token_certificate.private_key_pem
}