Skip to content

Commit f0218af

Browse files
committed
feat: add example terraform code for contract expiry
1 parent 91f4ef0 commit f0218af

File tree

4 files changed

+149
-0
lines changed

4 files changed

+149
-0
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
services:
2+
helloworld:
3+
image: docker.io/library/hello-world@sha256:4f53e2564790c8e7856ec08e384732aa38dc43c52f02952483e3f003afbf23db
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
logdna_ingestion_key="<logdna-ingestion-key>"
2+
logdna_ingestion_hostname="<logdna-hostname>"
3+
4+
hpcr_csr_country="<CSR - Country>"
5+
hpcr_csr_state="<CSR - State>"
6+
hpcr_csr_location="<CSR - Location>"
7+
hpcr_csr_org="<CSR - Organisation>"
8+
hpcr_csr_unit="<CSR - Unit>"
9+
hpcr_csr_domain="<CSR - Domain>"
10+
hpcr_csr_mail="<CSR - Mail>"
11+
12+
hpcr_private_key_path="<Private key path>"
13+
hpcr_contract_expiry_days=<Expiry days>
14+
hpcr_ca_privatekey_path="<CA private key path>"
15+
hpcr_cacert_path="<CA certificate path>"
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
terraform {
2+
required_providers {
3+
hpcr = {
4+
source = "ibm-hyper-protect/hpcr"
5+
version = ">= 0.5.0"
6+
}
7+
}
8+
}
9+
10+
resource "hpcr_tgz" "contract" {
11+
folder = "compose"
12+
}
13+
14+
locals {
15+
# contract in clear text
16+
contract = yamlencode({
17+
"env" : {
18+
"type" : "env",
19+
"logging" : {
20+
"logDNA" : {
21+
"ingestionKey" : var.logdna_ingestion_key,
22+
"hostname" : var.logdna_ingestion_hostname,
23+
},
24+
},
25+
},
26+
"workload" : {
27+
"type" : "workload",
28+
"compose" : {
29+
"archive" : hpcr_tgz.contract.rendered
30+
}
31+
}
32+
})
33+
34+
csrParams = {
35+
"country": var.hpcr_csr_country,
36+
"state": var.hpcr_csr_state,
37+
"location": var.hpcr_csr_location,
38+
"org": var.hpcr_csr_org,
39+
"unit": var.hpcr_csr_unit,
40+
"domain": var.hpcr_csr_domain,
41+
"mail": var.hpcr_csr_mail
42+
}
43+
}
44+
45+
resource "hpcr_contract_encrypted_contract_expiry" "contract" {
46+
contract = local.contract
47+
privkey= file(var.hpcr_private_key_path)
48+
expiry = var.hpcr_contract_expiry_days
49+
cakey = file(var.hpcr_ca_privatekey_path)
50+
cacert = file(var.hpcr_cacert_path)
51+
csrparams = local.csrParams
52+
}
53+
54+
resource "local_file" "contract" {
55+
content = hpcr_contract_encrypted_contract_expiry.contract.rendered
56+
filename = "${path.module}/build/contract.yml"
57+
}
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
variable "hpcr_private_key_path" {
2+
type = string
3+
description = "Path of private key for signature"
4+
}
5+
6+
variable "hpcr_ca_privatekey_path" {
7+
type = string
8+
description = "Path to CA private key"
9+
}
10+
11+
variable "hpcr_cacert_path" {
12+
type = string
13+
description = "Path to CA certificate"
14+
}
15+
16+
variable "hpcr_csr_country" {
17+
type = string
18+
description = "HPCR CSR country"
19+
}
20+
21+
variable "hpcr_csr_state" {
22+
type = string
23+
description = "HPCR CSR state"
24+
}
25+
26+
variable "hpcr_csr_location" {
27+
type = string
28+
description = "HPCR CSR location"
29+
}
30+
31+
variable "hpcr_csr_org" {
32+
type = string
33+
description = "HPCR CSR org"
34+
}
35+
36+
variable "hpcr_csr_unit" {
37+
type = string
38+
description = "HPCR CSR unit"
39+
}
40+
41+
variable "hpcr_csr_domain" {
42+
type = string
43+
description = "HPCR CSR domain"
44+
}
45+
46+
variable "hpcr_csr_mail" {
47+
type = string
48+
description = "HPCR CSR Mail ID"
49+
}
50+
51+
variable "hpcr_contract_expiry_days" {
52+
type = number
53+
description = "Number of days for contract to expire"
54+
}
55+
56+
variable "logdna_ingestion_key" {
57+
type = string
58+
sensitive = true
59+
description = <<-DESC
60+
Ingestion key for IBM Log Analysis instance. This can be
61+
obtained from "Linux/Ubuntu" section of "Logging resource"
62+
tab of IBM Log Analysis instance
63+
DESC
64+
}
65+
66+
variable "logdna_ingestion_hostname" {
67+
type = string
68+
description = <<-DESC
69+
rsyslog endpoint of IBM Log Analysis instance.
70+
Don't include the port. Example:
71+
syslog-a.<log_region>.logging.cloud.ibm.com
72+
log_region is the region where IBM Log Analysis is deployed
73+
DESC
74+
}

0 commit comments

Comments
 (0)