Skip to content

Commit 21083c4

Browse files
authored
Merge pull request #72 from Sashwat-K/sashwatk-contract-expiry-example
feat: add terraform example to provision HPVS with contract expiry
2 parents 91f4ef0 + 12a95be commit 21083c4

File tree

5 files changed

+222
-0
lines changed

5 files changed

+222
-0
lines changed
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
## Contract generation with contract expiry example
2+
3+
This sample creates an encrypted and signed contract with expiry enabled and stores it locally in a file. In addition this example identifies
4+
the latest version of HPCR in the VPC cloud and then downloads the matching encryption certifcicate.
5+
6+
### Prerequisite
7+
8+
Prepare your environment according to [these steps](../README.md)
9+
10+
### Settings
11+
12+
#### Prerequisites
13+
14+
1. Generate private key using the following commnad:
15+
```bash
16+
openssl genrsa -out private.pem 4096
17+
```
18+
2. Generate CA private key using the following command:
19+
```bash
20+
openssl genrsa -out personal_ca.key 2048
21+
```
22+
3. Generate CA certificate using the following command:
23+
```bash
24+
openssl req -new -x509 -days 365 -key personal_ca.key -out personal_ca.crt
25+
```
26+
27+
Use one of the following options to set your settings:
28+
29+
#### Template file
30+
31+
1. Copy contents of `my-settings.auto.tfvars-template` to `my-settings.auto.tfvars`.
32+
```bash
33+
cp my-settings.auto.tfvars-template my-settings.auto.tfvars
34+
```
35+
2. Update `my-settings.auto.tfvars` to appropriate values.
36+
37+
#### Environment variables
38+
39+
Set the following environment variables:
40+
41+
```text
42+
TF_VAR_logdna_ingestion_key="<logdna ingestion key>"
43+
TF_VAR_logdna_ingestion_hostname="<logdna hostname>"
44+
45+
TF_VAR_hpcr_csr_country="<CSR - Country>"
46+
TF_VAR_hpcr_csr_state="<CSR - State>"
47+
TF_VAR_hpcr_csr_location="<CSR - Location>"
48+
TF_VAR_hpcr_csr_org="<CSR - Organisation>"
49+
TF_VAR_hpcr_csr_unit="<CSR - Unit>"
50+
TF_VAR_hpcr_csr_domain="<CSR - Domain>"
51+
TF_VAR_hpcr_csr_mail="<CSR - Mail>"
52+
53+
TF_VAR_hpcr_private_key_path="<Private key path>"
54+
TF_VAR_hpcr_contract_expiry_days=<Expiry days>
55+
TF_VAR_hpcr_ca_privatekey_path="<CA private key path>"
56+
TF_VAR_hpcr_cacert_path="<CA certificate path>"
57+
```
58+
59+
### Run the Example
60+
61+
Initialize terraform:
62+
63+
```bash
64+
terraform init
65+
```
66+
67+
Deploy the example:
68+
69+
```bash
70+
terraform apply
71+
```
72+
73+
The contract will be persisted in the `build/contract.yml` folder for further use.
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)