Skip to content

Commit acdd7a1

Browse files
Merge pull request #73 from Sashwat-K/hpvs-icic-example
feat: add terraform example to provision HPCR RHVS on ICIC
2 parents fe5c051 + ede08e2 commit acdd7a1

File tree

7 files changed

+341
-0
lines changed

7 files changed

+341
-0
lines changed

terraform-hpcr-rhvs/README.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
## IBM Hyper Protect Container Runtime for Red Hat Virtualization Services for On Prem Examples
2+
3+
## Preparation
4+
5+
1. Make sure to have the [OpenSSL](https://www.openssl.org/) binary installed (see [details](#openssl)).
6+
2. Install the [terraform CLI](https://learn.hashicorp.com/tutorials/terraform/install-cli) for your environment.
7+
3. Make sure you have valid API Key for push logs to IBM Cloud Logs.
8+
4. Follow the description for [HPCR](https://cloud.ibm.com/docs/vpc?topic=vpc-about-se#hpcr_setup_logging) to setup a logging instance.
9+
5. Set either environment variables or fill the template file according to the example README.
10+
11+
## Examples
12+
13+
Follow the README in the subdirectory of the examples for further instructions:
14+
15+
- [IBM Cloud Infrastructure Center](hello-world/README.md) - An Example to bring up nginx through ICIC
16+
17+
18+
## OpenSSL
19+
20+
The [terraform provider](https://registry.terraform.io/providers/ibm-hyper-protect/hpcr/) leverages the [OpenSSL](https://www.openssl.org/) binary for all cryptographic operations in favour of the [golang crypto](https://pkg.go.dev/crypto) packages. This is because the golang libraries are not [FIPS](https://en.wikipedia.org/wiki/FIPS_140-2) certified whereas there exist certified OpenSSL binaries a customer can select.
21+
22+
Make sure to have the binaries installed for your platform. **Note:** on some platforms the default binary is actually a [LibreSSL](https://www.libressl.org/) installation, which is **not** compatible.
23+
24+
Verify your installation via running:
25+
26+
```bash
27+
openssl version
28+
```
29+
30+
this should give an output similar to the following:
31+
32+
```text
33+
OpenSSL 1.1.1q 5 Jul 2022
34+
```
35+
36+
In case you cannot change the OpenSSL binary in the path, you may override the version used by the [terraform provider](https://registry.terraform.io/providers/ibm-hyper-protect/hpcr/) by setting the `OPENSSL_BIN` environment variable to the absolute path of the correct binary, e.g.
37+
38+
```cmd
39+
OPENSSL_BIN="C:\Program Files\OpenSSL-Win64\bin\openssl.exe"
40+
```
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
## Deploy Hyper Protect Container Runtime with RedHat Virtualization Services (HPCR RHVS) on IBM Cloud Infrastructure Center (ICIC)
2+
3+
### Preparation
4+
5+
1. Setup ICIC Management node and compute nodes [see details](https://www.ibm.com/products/cloud-infrastructure-center) and make sure to have details like username, password, tenant name, authentication URL and domain name.
6+
2. Prepare your environment according to [these steps](../README.md)
7+
8+
### Provision on ICIC
9+
10+
Initialize terraform:
11+
12+
```bash
13+
terraform init
14+
```
15+
16+
Deploy the example:
17+
18+
```bash
19+
terraform apply
20+
```
21+
22+
### Settings
23+
24+
Use one of the following options to set your settings:
25+
26+
#### Template file
27+
28+
1. Copy contents of `my-settings.auto.tfvars-template` to `my-settings.auto.tfvars`.
29+
```bash
30+
cp my-settings.auto.tfvars-template my-settings.auto.tfvars
31+
```
32+
2. Update `my-settings.auto.tfvars` to appropriate values.
33+
34+
#### Environment variables
35+
36+
Set the following environment variables:
37+
38+
```text
39+
TF_VAR_icic_username="ICIC username"
40+
TF_VAR_icic_password="ICIC password"
41+
TF_VAR_icic_tenant_name="ICIC tenant name"
42+
TF_VAR_icic_auth_url="ICIC authentication URL"
43+
TF_VAR_icic_domain_name="ICIC domain name"
44+
45+
TF_VAR_prefix = "prefix for names"
46+
TF_VAR_hpcr_rhvs_image_path = "path to HPCR RHVS qcow2"
47+
TF_VAR_icic_network_name = "ICIC network name"
48+
TF_VAR_icic_target_compute_node = "Target compute node to bring up instance"
49+
50+
TF_VAR_icl_iam_apikey="Your IBM Cloud Logs IAM API Key"
51+
TF_VAR_icl_hostname="Your IBM Cloud Logs Hostname"
52+
53+
TF_VAR_hpcr_rhvs_image_cert_path = "HPCR RHVS encryption certificate path"
54+
```
55+
56+
### Run the Example
57+
58+
Initialize terraform:
59+
60+
```bash
61+
terraform init
62+
```
63+
64+
Deploy the example:
65+
66+
```bash
67+
terraform apply
68+
```
69+
70+
#### Test if the example works
71+
72+
Use your browser to access:
73+
74+
```text
75+
http://<IP>
76+
```
77+
78+
This will show a screen like this:
79+
80+
![nginx](images/nginx.png)
81+
82+
Destroy the created resources:
83+
84+
```bash
85+
terraform destroy
86+
```
27.6 KB
Loading
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
icic_username="ICIC username"
2+
icic_password="ICIC password"
3+
icic_tenant_name="ICIC tenant name"
4+
icic_auth_url="ICIC authentication URL"
5+
icic_domain_name="ICIC domain name"
6+
7+
prefix = "prefix for names"
8+
hpcr_rhvs_image_path = "path to HPCR RHVS qcow2"
9+
icic_network_name = "ICIC network name"
10+
icic_target_compute_node = "Target compute node to bring up instance"
11+
12+
icl_iam_apikey="Your IBM Cloud Logs IAM API Key"
13+
icl_hostname="Your IBM Cloud Logs Hostname"
14+
15+
hpcr_rhvs_image_cert_path = "HPCR RHVS encryption certificate path"
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
apiVersion: v1
2+
kind: Pod
3+
metadata:
4+
name: nginxdemos
5+
spec:
6+
containers:
7+
- name: nginxdemos
8+
image: docker.io/nginxdemos/hello@sha256:dedfbe85183df66f3fdc99accf53e1b2171908dffd4d6556603ba4810b1fce6e
9+
ports:
10+
- containerPort: 80
11+
hostPort: 80
12+
restartpolicy: Always
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
terraform {
2+
required_providers {
3+
openstack = {
4+
source = "terraform-provider-openstack/openstack"
5+
version = ">= 2.1.0"
6+
}
7+
hpcr = {
8+
source = "ibm-hyper-protect/hpcr"
9+
version = ">= 0.1.4"
10+
}
11+
}
12+
}
13+
14+
# Initialise openstack
15+
provider "openstack" {
16+
user_name = var.icic_username
17+
password = var.icic_password
18+
tenant_name = var.icic_tenant_name
19+
auth_url = var.icic_auth_url
20+
domain_name = var.icic_domain_name
21+
insecure = true
22+
}
23+
24+
# Create HPCR RHVS Image on ICIC
25+
resource "openstack_images_image_v2" "icic_hpcr_rhvs_image" {
26+
name = "${var.prefix}-image"
27+
local_file_path = var.hpcr_rhvs_image_path
28+
container_format = "bare"
29+
disk_format = "qcow2"
30+
properties = {
31+
os_name = "Linux"
32+
os_distro = "Rhel9"
33+
architecture = "s390x"
34+
disk_type = "SCSI"
35+
secure_execution = "True"
36+
hypervisor_type = "kvm"
37+
}
38+
}
39+
40+
# Create flavour to define resource requirements for HPCR-RHVS
41+
resource "openstack_compute_flavor_v2" "icic_hpcr_rhvs_flavor" {
42+
name = "${var.prefix}-flavor"
43+
ram = "4096"
44+
vcpus = "2"
45+
disk = "10"
46+
}
47+
48+
# Create security group
49+
resource "openstack_networking_secgroup_v2" "icic_hpcr_rhvs_sg" {
50+
name = "${var.prefix}-sg"
51+
description = "HPCR RHVS ICIC security group"
52+
}
53+
54+
# Allow inbound HTTP (port 80)
55+
resource "openstack_networking_secgroup_rule_v2" "icic_hpcr_rhvs_sg_rule_http" {
56+
direction = "ingress"
57+
ethertype = "IPv4"
58+
protocol = "tcp"
59+
port_range_min = 80
60+
port_range_max = 80
61+
remote_ip_prefix = "0.0.0.0/0"
62+
security_group_id = openstack_networking_secgroup_v2.icic_hpcr_rhvs_sg.id
63+
}
64+
65+
# Allow all outbound traffic
66+
resource "openstack_networking_secgroup_rule_v2" "icic_hpcr_rhvs_rule_all_outbound" {
67+
direction = "egress"
68+
ethertype = "IPv4"
69+
protocol = "tcp"
70+
port_range_min = 1
71+
port_range_max = 65535
72+
remote_ip_prefix = "0.0.0.0/0"
73+
security_group_id = openstack_networking_secgroup_v2.icic_hpcr_rhvs_sg.id
74+
}
75+
76+
# Generates base64 of archive of pods.yaml
77+
resource "hpcr_tgz" "contract" {
78+
folder = "pods"
79+
}
80+
81+
locals {
82+
# contract in clear text
83+
contract = yamlencode({
84+
"env" : {
85+
"type" : "env",
86+
"logging" : {
87+
"logRouter" : {
88+
"iamApiKey" : var.icl_iam_apikey,
89+
"hostname" : var.icl_hostname,
90+
}
91+
}
92+
},
93+
"workload" : {
94+
"type" : "workload",
95+
"play" : {
96+
"archive" : hpcr_tgz.contract.rendered
97+
}
98+
}
99+
})
100+
}
101+
102+
# Generates encrypted contract
103+
resource "hpcr_contract_encrypted" "contract" {
104+
contract = local.contract
105+
cert = file(var.hpcr_rhvs_image_cert_path)
106+
}
107+
108+
# Provision HPCR RHVS instance
109+
resource "openstack_compute_instance_v2" "icic_hpcr_rhvs_instance" {
110+
name = "${var.prefix}-instance"
111+
image_id = openstack_images_image_v2.icic_hpcr_rhvs_image.id
112+
flavor_id = openstack_compute_flavor_v2.icic_hpcr_rhvs_flavor.id
113+
114+
network {
115+
name = var.icic_network_name
116+
}
117+
118+
scheduler_hints {
119+
query = ["==", "hypervisor_hostname", var.icic_target_compute_node]
120+
}
121+
122+
security_groups = [ openstack_networking_secgroup_v2.icic_hpcr_rhvs_sg.name ]
123+
user_data = hpcr_contract_encrypted.contract.rendered
124+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
variable "icic_username" {
2+
type = string
3+
default = "root"
4+
description = "Username to access ICIC"
5+
}
6+
7+
variable "icic_password" {
8+
type = string
9+
description = "Password to access ICIC"
10+
}
11+
12+
variable "icic_tenant_name" {
13+
type = string
14+
default = "ibm-default"
15+
description = "Tenant name for ICIC account"
16+
}
17+
18+
variable "icic_auth_url" {
19+
type = string
20+
description = "ICIC authentication URL"
21+
}
22+
23+
variable "prefix" {
24+
type = string
25+
description = "name prefix"
26+
default = "hpcr-rhvs"
27+
}
28+
29+
variable "icic_domain_name" {
30+
type = string
31+
default = "default"
32+
description = "ICIC domain name"
33+
}
34+
35+
variable "hpcr_rhvs_image_path" {
36+
type = string
37+
description = "Path to HPCR RHVS image"
38+
}
39+
40+
variable "icic_network_name" {
41+
type = string
42+
description = "ICIC network name"
43+
}
44+
45+
variable "icic_target_compute_node" {
46+
type = string
47+
description = "Target compute node"
48+
}
49+
50+
variable "icl_iam_apikey" {
51+
type = string
52+
sensitive = true
53+
description = "IAM Key of IBM Cloud Logs"
54+
}
55+
56+
variable "icl_hostname" {
57+
type = string
58+
description = "Hostname of IBM Cloud Logs"
59+
}
60+
61+
variable "hpcr_rhvs_image_cert_path" {
62+
type = string
63+
description = "Path to your HPCR image certificate"
64+
}

0 commit comments

Comments
 (0)