From 1ebba00b3e850a49af9206efecd13f0ec48efd37 Mon Sep 17 00:00:00 2001 From: Michele Cereda Date: Wed, 18 Jan 2023 01:23:35 +0100 Subject: [PATCH] Made sense of terraform's cloud-init temmplate example with docker installation --- terraform/multi-part cloud-init/data.tf | 21 ++++++++++++------- .../boinc-client.oci-core-instance.yaml.tftpl | 6 ------ .../templates/docker-ce.yaml.tftpl | 20 ++++++++++++++++++ 3 files changed, 33 insertions(+), 14 deletions(-) delete mode 100644 terraform/multi-part cloud-init/templates/boinc-client.oci-core-instance.yaml.tftpl create mode 100644 terraform/multi-part cloud-init/templates/docker-ce.yaml.tftpl diff --git a/terraform/multi-part cloud-init/data.tf b/terraform/multi-part cloud-init/data.tf index 478de89..249b842 100644 --- a/terraform/multi-part cloud-init/data.tf +++ b/terraform/multi-part cloud-init/data.tf @@ -12,12 +12,17 @@ data "cloudinit_config" "azurerm_linux_virtual_machine" { filename = "base" } - # part { - # content = file("${path.module}/templates/n-th.yaml") - # content_type = "text/cloud-config" - # merge_type = "dict(recurse_array,no_replace)+list(append)" - # filename = "n-th.yaml" - # } + part { + content = templatefile( + "${path.module}/templates/docker-ce.yaml.tftpl", + { + user = "azureuser" + } + ) + content_type = "text/cloud-config" + merge_type = "dict(recurse_array,no_replace)+list(append)" + filename = "docker" + } } data "cloudinit_config" "oci_core_instance" { @@ -33,13 +38,13 @@ data "cloudinit_config" "oci_core_instance" { part { content = templatefile( - "${path.module}/templates/boinc-client.oci-core-instance.yaml.tftpl", + "${path.module}/templates/docker-ce.yaml.tftpl", { user = "opc" } ) content_type = "text/cloud-config" merge_type = "dict(recurse_array,no_replace)+list(append)" - filename = "n-th.yaml" + filename = "docker" } } diff --git a/terraform/multi-part cloud-init/templates/boinc-client.oci-core-instance.yaml.tftpl b/terraform/multi-part cloud-init/templates/boinc-client.oci-core-instance.yaml.tftpl deleted file mode 100644 index 917d708..0000000 --- a/terraform/multi-part cloud-init/templates/boinc-client.oci-core-instance.yaml.tftpl +++ /dev/null @@ -1,6 +0,0 @@ -#cloud-config - -packages: - - boinc-client - -# Something about user ${user} diff --git a/terraform/multi-part cloud-init/templates/docker-ce.yaml.tftpl b/terraform/multi-part cloud-init/templates/docker-ce.yaml.tftpl new file mode 100644 index 0000000..493025b --- /dev/null +++ b/terraform/multi-part cloud-init/templates/docker-ce.yaml.tftpl @@ -0,0 +1,20 @@ +#cloud-config + +packages: + - docker-ce + +runcmd: + + # Give the user permissions to use Docker without `sudo`ing. + # The 'users' module overrode *both* the SSH keys *and* group assignments in + # previous tests. (┛◉Д◉)┛彡┻━┻ + - grep -qE '^docker:' /etc/group && usermod -a -G docker ${user} || true + +yum_repos: + docker-ce: + name: Docker CE Stable - $basearch + enabled: true + baseurl: https://download.docker.com/linux/rhel/$releasever/$basearch/stable + priority: 1 + gpgcheck: true + gpgkey: https://download.docker.com/linux/rhel/gpg