Skip to content

Commit c46d405

Browse files
ops(iac): improve Openstack Docker terraform example (#15)
* ops(iac): improve Openstack Docker terraform example feat(iac): Generate portainer password feat(iac): Split docker example into two folders feat(iac): Allow any flavour in openstack compute fix(iac): Pin portainer version * ops(iac): improve Openstack Docker terraform example feat(iac): Generate portainer password feat(iac): Split docker example into two folders feat(iac): Allow any flavour in openstack compute fix(iac): Pin portainer version
1 parent 999fcfd commit c46d405

File tree

25 files changed

+341
-233
lines changed

25 files changed

+341
-233
lines changed

deployment/terraform/examples/openstack-docker/.terraform.lock.hcl

Lines changed: 15 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

deployment/terraform/examples/openstack-docker/README.md

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,27 @@ Create a `terraform.tfvars` file, based on `terraform.tfvars.example`, containin
2323

2424
### 2. Run Terraform
2525

26+
Terraform is run on two modules, so we will run one terraform apply in one folder, then another terraform apply in a second folder. This split is needed to solve dependency ordering with terraform providers.
27+
2628
```bash
29+
# Create VMs in openstack
30+
cd openstack-vms
2731
terraform init
28-
terraform apply
32+
terraform apply --auto-approve
33+
34+
# Export the created values as environment variables, for usage as terraform variables
35+
OPENSTACK_HOSTS=$(terraform output -json created_hosts)
36+
PORTAINER_INSTANCE=$(terraform output -json portainer_instance)
37+
SSH_PRIVATE_KEY=$(terraform output -json ssh_keys | jq -r .private_key_file)
38+
39+
export TF_VAR_portainer_instance=$PORTAINER_INSTANCE
40+
export TF_VAR_hosts=$OPENSTACK_HOSTS
41+
export TF_VAR_ssh_private_key_file=$SSH_PRIVATE_KEY
42+
43+
# Deploy services using docker and portainer
44+
cd ../docker-deployment
45+
terraform init
46+
terraform apply --auto-approve
2947
```
3048

3149
Initial provisioning takes up to 10 minutes, where time is mostly downloading large docker images
@@ -35,28 +53,16 @@ Initial provisioning takes up to 10 minutes, where time is mostly downloading la
3553
Once the deployment is complete and all services are running, you can access the CogStack platform and its components using the following URLs:
3654

3755
```bash
38-
terraform output service_urls
56+
terraform output
3957
```
4058

41-
## Troubleshooting
42-
43-
44-
### unsupported protocol scheme
45-
If you make changes to the created VM infrastructure, and want to reapply, you can run into this error
46-
47-
```
48-
│ Error: Get "/api/endpoints/4": unsupported protocol scheme ""
49-
50-
│ with module.cogstack_docker_services.portainer_environment.portainer_envs["cogstack-devops"],
51-
│ on ../../modules/cogstack-docker-services/environments.tf line 3, in resource "portainer_environment" "portainer_envs":
52-
│ 3: resource "portainer_environment" "portainer_envs" {
53-
```
54-
55-
Fix by targetting just the infra module first:
56-
57-
```bash
58-
terraform apply -target=module.openstack_cogstack_infra
59-
terraform apply
59+
```hcl
60+
created_services = {
61+
"service_urls" = {
62+
"grafana" = "http://10.0.0.1/grafana"
63+
"medcat_service" = "http://10.0.0.1:5000"
64+
"prometheus" = "http://10.0.0.1/prometheus"
65+
}
66+
}
6067
```
6168

62-
For details: the error specifically occurs after making a change to the controller host, forcing it to be deleted and recreated, however terraform still uses the IP address in the portainer provider. Targetting just the infra module first, means terraform wont call any APIs during the plan stage using the old IP address.

deployment/terraform/examples/openstack-docker/docker-deployment/.terraform.lock.hcl

Lines changed: 64 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
2+
module "cogstack_docker_services" {
3+
source = "../../../modules/cogstack-docker-services"
4+
hosts = var.hosts
5+
service_targets = {
6+
observability = { hostname = "cogstack-devops" }
7+
medcat_service = { hostname = "medcat-nlp" }
8+
}
9+
ssh_private_key_file = var.ssh_private_key_file
10+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
output "created_services" {
2+
value = module.cogstack_docker_services
3+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
terraform {
2+
required_providers {
3+
portainer = {
4+
source = "portainer/portainer"
5+
version = "~> 1.10.0"
6+
}
7+
ansible = {
8+
version = "~> 1.3.0"
9+
source = "ansible/ansible"
10+
}
11+
}
12+
}
13+
14+
15+
provider "portainer" {
16+
endpoint = var.portainer_instance.endpoint
17+
api_user = var.portainer_instance.username
18+
api_password = var.portainer_instance.password
19+
skip_ssl_verify = true # optional (default value is `false`)
20+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
portainer_instance = {
2+
endpoint = "https://10.0.0.1:9443"
3+
username = ""
4+
password = ""
5+
}
6+
7+
hosts = {
8+
"cogstack-devops" = {
9+
"ip_address" = "10.0.0.1"
10+
"name" = "cogstack-devops"
11+
"unique_name" = "w6R2tw-cogstack-devops"
12+
}
13+
}
14+
15+
ssh_private_key_file = "~/my-key.pem"
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Variables for Docker Deployment
2+
# It's recommended to follow the README.md and use the output of the openstack-vms module
3+
4+
variable "portainer_instance" {
5+
type = object({
6+
endpoint = string
7+
username = string
8+
password = string
9+
})
10+
11+
description = <<EOT
12+
endpoint = API to call portainer on
13+
username = Portainer username
14+
password = Portainer password to use
15+
EOT
16+
}
17+
18+
variable "ssh_private_key_file" {
19+
type = string
20+
description = "A filepath to a SSH Private key that is used to SSH login to created hosts"
21+
}
22+
23+
variable "hosts" {
24+
type = map(object({
25+
ip_address = string,
26+
unique_name = string,
27+
name = string
28+
}))
29+
description = "Created Hosts: A map of { hostname: { data } }"
30+
}

deployment/terraform/examples/openstack-docker/main.tf

Lines changed: 0 additions & 27 deletions
This file was deleted.

deployment/terraform/examples/openstack-docker/openstack-vms/.terraform.lock.hcl

Lines changed: 81 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)