Skip to content

Commit 5c43258

Browse files
bug(iac): Fix openstack VMs always recreating due to Bcrypt being randomised (#16)
1 parent c46d405 commit 5c43258

File tree

5 files changed

+10
-8
lines changed

5 files changed

+10
-8
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ module "cogstack_docker_services" {
33
source = "../../../modules/cogstack-docker-services"
44
hosts = var.hosts
55
service_targets = {
6-
observability = { hostname = "cogstack-devops" }
7-
medcat_service = { hostname = "medcat-nlp" }
6+
observability = { hostname = "cogstack-docker-controller" }
7+
medcat_service = { hostname = "cogstack-docker-medcat-nlp" }
88
}
99
ssh_private_key_file = var.ssh_private_key_file
1010
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
module "openstack_cogstack_infra" {
22
source = "../../../modules/openstack-cogstack-infra"
33
host_instances = [
4-
{ name = "cogstack-devops", is_controller = true },
5-
{ name = "medcat-nlp" }
4+
{ name = "cogstack-docker-controller", is_controller = true },
5+
{ name = "cogstack-docker-medcat-nlp" }
66
]
77
allowed_ingress_ips_cidr = var.allowed_ingress_ips_cidr
88
ubuntu_immage_name = var.ubuntu_immage_name

deployment/terraform/modules/openstack-cogstack-infra/cloud-init-controller.yaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ system_info:
88
default_user:
99
groups: [docker]
1010

11+
packages:
12+
- apache2-utils
1113

1214
runcmd:
1315
# Install Docker
@@ -31,6 +33,7 @@ runcmd:
3133

3234
# Run Portainer
3335
- echo "Running Portainer"
36+
- bcrypted_pw=$(htpasswd -nb -B admin "${PORTAINER_ADMIN_PASSWORD}" | cut -d ":" -f 2)
3437
- docker pull portainer/portainer-ce:2.33.0
3538
- docker network create portainer-network
3639
- docker volume create portainer-data
@@ -45,7 +48,7 @@ runcmd:
4548
-l 'traefik.enable="true"' \
4649
-l 'traefik.http.routers.portainer-path-router.rule="PathPrefix(`/portainer`)"' \
4750
portainer/portainer-ce:2.33.0 \
48-
--admin-password='${PORTAINER_ADMIN_PASSWORD}'
51+
--admin-password="$${bcrypted_pw}"
4952
- docker pull portainer/agent:2.33.0
5053
- |
5154
docker run -d \

deployment/terraform/modules/openstack-cogstack-infra/compute.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ data "cloudinit_config" "init_docker_controller" {
6969
content = templatefile("${path.module}/cloud-init-controller.yaml",
7070
{
7171
PORTAINER_AGENT_SECRET = var.portainer_secrets.agent_secret,
72-
PORTAINER_ADMIN_PASSWORD = local.portainer_admin_password_bcrypt_hash
72+
PORTAINER_ADMIN_PASSWORD = local.portainer_admin_password
7373
}
7474
)
7575
}

deployment/terraform/modules/openstack-cogstack-infra/shared-locals.tf

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,5 @@ resource "random_password" "portainer_password" {
2424
length = 16
2525
}
2626
locals {
27-
portainer_admin_password_bcrypt_hash = var.portainer_secrets.admin_password != null ? bcrypt(var.portainer_secrets.admin_password) : random_password.portainer_password[0].bcrypt_hash
28-
portainer_admin_password = var.portainer_secrets.admin_password != null ? var.portainer_secrets.admin_password : random_password.portainer_password[0].result
27+
portainer_admin_password = var.portainer_secrets.admin_password != null ? var.portainer_secrets.admin_password : random_password.portainer_password[0].result
2928
}

0 commit comments

Comments
 (0)