From 4c5b078af24c4604d29fc1a3030b70847db902ed Mon Sep 17 00:00:00 2001 From: Peter Pouliot Date: Tue, 21 May 2024 15:26:46 -0400 Subject: [PATCH] trying to get to fedora coreos images --- README.md | 24 ++++- examples/debian12/cloud-init.yaml.tpl | 104 ++++++++++++++++++++++ examples/debian12/main.tf | 30 +++++++ examples/fedoracoreos/cloud-init.yaml.tpl | 4 + examples/fedoracoreos/main.tf | 30 +++++++ examples/rockylinux8/cloud-init.yaml.tpl | 50 +++++++++++ examples/rockylinux8/main.tf | 30 +++++++ examples/rockylinux9/cloud-init.yaml.tpl | 2 +- examples/ubuntu2204/main.tf | 2 +- examples/ubuntu2404/cloud-init.yaml.tpl | 38 ++++++++ examples/ubuntu2404/main.tf | 30 +++++++ images.tf | 2 +- main.tf | 17 ++++ virtual_machine.tf | 3 +- 14 files changed, 361 insertions(+), 5 deletions(-) create mode 100644 examples/debian12/cloud-init.yaml.tpl create mode 100644 examples/debian12/main.tf create mode 100644 examples/fedoracoreos/cloud-init.yaml.tpl create mode 100644 examples/fedoracoreos/main.tf create mode 100644 examples/rockylinux8/cloud-init.yaml.tpl create mode 100644 examples/rockylinux8/main.tf create mode 100644 examples/ubuntu2404/cloud-init.yaml.tpl create mode 100644 examples/ubuntu2404/main.tf diff --git a/README.md b/README.md index 3c02ab1..6e26796 100644 --- a/README.md +++ b/README.md @@ -45,6 +45,23 @@ This can also be used as a terraform module. The [examples](examples) director terraform init && terraform plan && terraform apply -auto-approve ``` +### Running OpenTofu + +``` +tofu init && tofu plan && tofu apply -auto-approve + +``` + +### Logging in + +Once everthing as executed, properly you'll need to login. Currently I successfully login via my google cloud email account in the following format. __ Where the "@" symbal and "." are replaces with underscores. + +for example: + +``` +ssh -i +``` + ## Providers @@ -99,4 +116,9 @@ terraform init && terraform plan && terraform apply -auto-approve | [gcp\_ssh\_pubic\_key](#output\_gcp\_ssh\_pubic\_key) | Output GCE SSH public key | | [my-email](#output\_my-email) | Output email address | | [random\_uuid](#output\_random\_uuid) | Output a randomly generated uuid | - \ No newline at end of file +<<<<<<< HEAD + +======= +| [startup\_script](#output\_startup\_script) | Output rendered startup script | + +>>>>>>> eec3121 (adding examples) diff --git a/examples/debian12/cloud-init.yaml.tpl b/examples/debian12/cloud-init.yaml.tpl new file mode 100644 index 0000000..087c158 --- /dev/null +++ b/examples/debian12/cloud-init.yaml.tpl @@ -0,0 +1,104 @@ +#cloud-config + +apt: + sources: + docker.list: + source: deb [arch=arm64] https://download.docker.com/linux/debian $RELEASE stable + keyserver: pgp.mit.edu + key: | + -----BEGIN PGP PUBLIC KEY BLOCK----- + + mQINBFit2ioBEADhWpZ8/wvZ6hUTiXOwQHXMAlaFHcPH9hAtr4F1y2+OYdbtMuth + lqqwp028AqyY+PRfVMtSYMbjuQuu5byyKR01BbqYhuS3jtqQmljZ/bJvXqnmiVXh + 38UuLa+z077PxyxQhu5BbqntTPQMfiyqEiU+BKbq2WmANUKQf+1AmZY/IruOXbnq + L4C1+gJ8vfmXQt99npCaxEjaNRVYfOS8QcixNzHUYnb6emjlANyEVlZzeqo7XKl7 + UrwV5inawTSzWNvtjEjj4nJL8NsLwscpLPQUhTQ+7BbQXAwAmeHCUTQIvvWXqw0N + cmhh4HgeQscQHYgOJjjDVfoY5MucvglbIgCqfzAHW9jxmRL4qbMZj+b1XoePEtht + ku4bIQN1X5P07fNWzlgaRL5Z4POXDDZTlIQ/El58j9kp4bnWRCJW0lya+f8ocodo + vZZ+Doi+fy4D5ZGrL4XEcIQP/Lv5uFyf+kQtl/94VFYVJOleAv8W92KdgDkhTcTD + G7c0tIkVEKNUq48b3aQ64NOZQW7fVjfoKwEZdOqPE72Pa45jrZzvUFxSpdiNk2tZ + XYukHjlxxEgBdC/J3cMMNRE1F4NCA3ApfV1Y7/hTeOnmDuDYwr9/obA8t016Yljj + q5rdkywPf4JF8mXUW5eCN1vAFHxeg9ZWemhBtQmGxXnw9M+z6hWwc6ahmwARAQAB + tCtEb2NrZXIgUmVsZWFzZSAoQ0Ug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Q0s9BhFJ/zU6AgQbIZE/hm1spsfgvtsD1frZfygXJ9f + irP+MSAI80xHSf91qSRZOj4Pl3ZJNbq4yYxv0b1pkMqeGdjdCYhLU+LZ4wbQmpCk + SVe2prlLureigXtmZfkqevRz7FrIZiu9ky8wnCAPwC7/zmS18rgP/17bOtL4/iIz + QhxAAoAMWVrGyJivSkjhSGx1uCojsWfsTAm11P7jsruIL61ZzMUVE2aM3Pmj5G+W + 9AcZ58Em+1WsVnAXdUR//bMmhyr8wL/G1YO1V3JEJTRdxsSxdYa4deGBBY/Adpsw + 24jxhOJR+lsJpqIUeb999+R8euDhRHG9eFO7DRu6weatUJ6suupoDTRWtr/4yGqe + dKxV3qQhNLSnaAzqW/1nA3iUB4k7kCaKZxhdhDbClf9P37qaRW467BLCVO/coL3y + Vm50dwdrNtKpMBh3ZpbB1uJvgi9mXtyBOMJ3v8RZeDzFiG8HdCtg9RvIt/AIFoHR + H3S+U79NT6i0KPzLImDfs8T7RlpyuMc4Ufs8ggyg9v3Ae6cN3eQyxcK3w0cbBwsh + /nQNfsA6uu+9H7NhbehBMhYnpNZyrHzCmzyXkauwRAqoCbGCNykTRwsur9gS41TQ + M8ssD1jFheOJf3hODnkKU+HKjvMROl1DK7zdmLdNzA1cvtZH/nCC9KPj1z8QC47S + xx+dTZSx4ONAhwbS/LN3PoKtn8LPjY9NP9uDWI+TWYquS2U+KHDrBDlsgozDbs/O + jCxcpDzNmXpWQHEtHU7649OXHP7UeNST1mCUCH5qdank0V1iejF6/CfTFU4MfcrG + YT90qFF93M3v01BbxP+EIY2/9tiIPbrd + =0YYh + -----END PGP PUBLIC KEY BLOCK----- +package_update: true +package_upgrade: true +packages: + - screen + - rsync + - git + - curl + - python3-pip + - python3-dev + - python3-selinux + - python3-setuptools + - python3-venv + - libffi-dev + - gcc + - libssl-dev + - apt-transport-https + - ca-certificates + - curl + - gnupg-agent + - software-properties-common + +groups: + - docker +system_info: + default_user: + groups: [docker] + +runcmd: + - curl -fsSL https://download.docker.com/linux/debian/gpg | sudo apt-key add - + - sudo apt-get update -y && apt-get install -y docker-ce docker-ce-cli + - docker run -d --name registry --restart=always -p 4000:5000 -v registry:/var/lib/registry registry:2 + - pip3 install -U pip + - pip3 install -U wheel + - echo 'GCE Tau T2A Instance Powered by AmpereĀ® Altra' >> /etc/motd diff --git a/examples/debian12/main.tf b/examples/debian12/main.tf new file mode 100644 index 0000000..cb2deb5 --- /dev/null +++ b/examples/debian12/main.tf @@ -0,0 +1,30 @@ +variable "project_id" {} +variable "location" {} + +locals { + cloud_init_template_path = "${path.cwd}/cloud-init.yaml.tpl" +} + +module "gcp-ampere-tau-t2a" { + source = "github.com/amperecomputing/terraform-gcp-ampere-tau-t2a" + project_id = var.project_id + # Optional + # virtual_network_name = var.virtual_network_name + # address_space = var.address_space + # subnet_prefix = var.subnet_prefix + location = "US" + region = "us-central1" + zone = "us-central1-a" + gcp_vm_count = 1 + gcp_os_image = "debian12" + instance_prefix = "ampere-t2a-debian12" + startup_script_template_file = null + cloud_init_template_file = local.cloud_init_template_path +} + +output "gcp_ampere_tau_t2a_private_ips" { + value = module.gcp-ampere-tau-t2a.ampere_taut2a_private_ips +} +output "gcp_ampere_tau_t2a_public_ips" { + value = module.gcp-ampere-tau-t2a.ampere_taut2a_public_ips +} diff --git a/examples/fedoracoreos/cloud-init.yaml.tpl b/examples/fedoracoreos/cloud-init.yaml.tpl new file mode 100644 index 0000000..b57f451 --- /dev/null +++ b/examples/fedoracoreos/cloud-init.yaml.tpl @@ -0,0 +1,4 @@ +#cloud-config + +runcmd: + - echo 'Ampere T2A FedoraCoreOS Example' >> /etc/motd diff --git a/examples/fedoracoreos/main.tf b/examples/fedoracoreos/main.tf new file mode 100644 index 0000000..06d28c9 --- /dev/null +++ b/examples/fedoracoreos/main.tf @@ -0,0 +1,30 @@ +variable "project_id" {} +variable "location" {} + +locals { + cloud_init_template_path = "${path.cwd}/cloud-init.yaml.tpl" +} + +module "gcp-ampere-tau-t2a" { + source = "github.com/amperecomputing/terraform-gcp-ampere-tau-t2a" + project_id = var.project_id + # Optional + # virtual_network_name = var.virtual_network_name + # address_space = var.address_space + # subnet_prefix = var.subnet_prefix + location = "US" + region = "us-central1" + zone = "us-central1-a" + gcp_vm_count = 1 + gcp_os_image = "fedoracoreos" + instance_prefix = "ampere-t2a-fedoracoreos" + startup_script_template_file = null + cloud_init_template_file = local.cloud_init_template_path +} + +output "gcp_ampere_tau_t2a_private_ips" { + value = module.gcp-ampere-tau-t2a.ampere_taut2a_private_ips +} +output "gcp_ampere_tau_t2a_public_ips" { + value = module.gcp-ampere-tau-t2a.ampere_taut2a_public_ips +} diff --git a/examples/rockylinux8/cloud-init.yaml.tpl b/examples/rockylinux8/cloud-init.yaml.tpl new file mode 100644 index 0000000..4094b4e --- /dev/null +++ b/examples/rockylinux8/cloud-init.yaml.tpl @@ -0,0 +1,50 @@ +#cloud-config + +package_update: true +package_upgrade: true + +packages: + - tmux + - rsync + - git + - curl + - python3 + - python39 + - python39-devel + - python39-pip + - python39-pip-wheel + - gcc + - gcc + - gcc-c++ + - nodejs + - rust + - gettext + - device-mapper-persistent-data + - lvm2 + - bzip2 + +groups: + - docker +system_info: + default_user: + groups: [docker] + +runcmd: + - alternatives --set python /usr/bin/python3 + - pip3 install -U pip + - pip3 install -U setuptools-rust + - pip3 install -U ansible + - dnf config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo + - dnf update -y + - dnf install docker-ce docker-ce-cli containerd.io -y + - curl -L https://github.com/docker/compose/releases/latest/download/docker-compose-linux-aarch64 -o /usr/local/bin/docker-compose-linux-aarch64 + - chmod -x /usr/local/bin/docker-compose-linux-aarch64 + - ln -s /usr/local/bin/docker-compose-linux-aarch64 /usr/bin/docker-compose + - docker-compose --version + - pip3 install -U docker-compose + - docker info + - systemctl enable docker + - systemctl start docker + - docker run -d --name registry --restart=always -p 4000:5000 -v registry:/var/lib/registry registry:2 + - docker info + - echo 'Ampere T2A RockyLinux 8 Example' >> /etc/motd diff --git a/examples/rockylinux8/main.tf b/examples/rockylinux8/main.tf new file mode 100644 index 0000000..f474536 --- /dev/null +++ b/examples/rockylinux8/main.tf @@ -0,0 +1,30 @@ +variable "project_id" {} +variable "location" {} + +locals { + cloud_init_template_path = "${path.cwd}/cloud-init.yaml.tpl" +} + +module "gcp-ampere-tau-t2a" { + source = "github.com/amperecomputing/terraform-gcp-ampere-tau-t2a" + project_id = var.project_id + # Optional + # virtual_network_name = var.virtual_network_name + # address_space = var.address_space + # subnet_prefix = var.subnet_prefix + location = "US" + region = "us-central1" + zone = "us-central1-a" + gcp_vm_count = 1 + gcp_os_image = "rockylinux8" + instance_prefix = "ampere-t2a-rockylinux8" + startup_script_template_file = null + cloud_init_template_file = local.cloud_init_template_path +} + +output "gcp_ampere_tau_t2a_private_ips" { + value = module.gcp-ampere-tau-t2a.ampere_taut2a_private_ips +} +output "gcp_ampere_tau_t2a_public_ips" { + value = module.gcp-ampere-tau-t2a.ampere_taut2a_public_ips +} diff --git a/examples/rockylinux9/cloud-init.yaml.tpl b/examples/rockylinux9/cloud-init.yaml.tpl index 13de94d..4591a98 100644 --- a/examples/rockylinux9/cloud-init.yaml.tpl +++ b/examples/rockylinux9/cloud-init.yaml.tpl @@ -47,4 +47,4 @@ runcmd: - systemctl start docker - docker run -d --name registry --restart=always -p 4000:5000 -v registry:/var/lib/registry registry:2 - docker info - - echo 'OCI Ampere A1 AlmaLinux 8 Example' >> /etc/motd + - echo 'Ampere T2A RockyLinux 9 Example' >> /etc/motd diff --git a/examples/ubuntu2204/main.tf b/examples/ubuntu2204/main.tf index 3e97ffe..ef5ff7e 100644 --- a/examples/ubuntu2204/main.tf +++ b/examples/ubuntu2204/main.tf @@ -17,7 +17,7 @@ module "gcp-ampere-tau-t2a" { zone = "us-central1-a" gcp_vm_count = 1 gcp_os_image = "ubuntu2204" - instance_prefix = "gcp-ampere-taut2a-ubuntu-2204" + instance_prefix = "ampere-t2a-ubuntu2204" startup_script_template_file = null cloud_init_template_file = local.cloud_init_template_path } diff --git a/examples/ubuntu2404/cloud-init.yaml.tpl b/examples/ubuntu2404/cloud-init.yaml.tpl new file mode 100644 index 0000000..5d7aafd --- /dev/null +++ b/examples/ubuntu2404/cloud-init.yaml.tpl @@ -0,0 +1,38 @@ +#cloud-config + +apt: + sources: + docker.list: + source: deb [arch=arm64] https://download.docker.com/linux/ubuntu $RELEASE stable + keyid: 9DC858229FC7DD38854AE2D88D81803C0EBFCD88 + +package_update: true +package_upgrade: true + +packages: + - screen + - rsync + - git + - curl + - docker-ce + - docker-ce-cli + - python3-pip + - python3-dev + - python3-selinux + - python3-setuptools + - python3-venv + - libffi-dev + - gcc + - libssl-dev + +groups: + - docker +system_info: + default_user: + groups: [docker] + +runcmd: + - docker run -d --name registry --restart=always -p 4000:5000 -v registry:/var/lib/registry registry:2 + - pip3 install -U pip + - pip3 install -U wheel + - echo 'GCE Tau T2A Instance Powered by AmpereĀ® Altra' >> /etc/motd diff --git a/examples/ubuntu2404/main.tf b/examples/ubuntu2404/main.tf new file mode 100644 index 0000000..868d92e --- /dev/null +++ b/examples/ubuntu2404/main.tf @@ -0,0 +1,30 @@ +variable "project_id" {} +variable "location" {} + +locals { + cloud_init_template_path = "${path.cwd}/cloud-init.yaml.tpl" +} + +module "gcp-ampere-tau-t2a" { + source = "github.com/amperecomputing/terraform-gcp-ampere-tau-t2a" + project_id = var.project_id + # Optional + # virtual_network_name = var.virtual_network_name + # address_space = var.address_space + # subnet_prefix = var.subnet_prefix + location = "US" + region = "us-central1" + zone = "us-central1-a" + gcp_vm_count = 1 + gcp_os_image = "ubuntu2404" + instance_prefix = "ampere-t2a-ubuntu2404" + startup_script_template_file = null + cloud_init_template_file = local.cloud_init_template_path +} + +output "gcp_ampere_tau_t2a_private_ips" { + value = module.gcp-ampere-tau-t2a.ampere_taut2a_private_ips +} +output "gcp_ampere_tau_t2a_public_ips" { + value = module.gcp-ampere-tau-t2a.ampere_taut2a_public_ips +} diff --git a/images.tf b/images.tf index 31a876c..1b7696d 100644 --- a/images.tf +++ b/images.tf @@ -22,7 +22,7 @@ locals { startup_script = file("${local.startup_script_template_file}") } fedoracoreos = { - os_image = "fedora-coreos-stable-arm64" + os_image = "fedora-coreos-cloud" default_os_user = "fedora" startup_script = null } diff --git a/main.tf b/main.tf index c0b0aa3..a019eac 100644 --- a/main.tf +++ b/main.tf @@ -7,6 +7,23 @@ locals { startup_script_template_file = coalesce(var.startup_script_template_file, "${path.module}/templates/startup-script.sh.tpl") } +data "cloudinit_config" "cloud_config" { + gzip = false + base64_encode = false + + part { + content_type = "text/cloud-config" +# content = template_file.cloud_config.rendered + content = "${file("${local.cloud_init_template_file}")}" + filename = "cloud.cfg" + } +} + + +output "cloud_config" { + value = data.cloudinit_config.cloud_config.rendered +} + # ssh keys resource "tls_private_key" "gcp" { algorithm = "RSA" diff --git a/virtual_machine.tf b/virtual_machine.tf index 2e3fdde..5a9db69 100644 --- a/virtual_machine.tf +++ b/virtual_machine.tf @@ -13,8 +13,9 @@ resource "google_compute_instance" "default" { enable-oslogin = true ssh-keys = "${split("@", data.google_client_openid_userinfo.me.email)[0]}:${replace(tls_private_key.gcp.public_key_openssh, "\n", "")} ${split("@", data.google_client_openid_userinfo.me.email)[0]}" # user-data = data.template_file.cloud_config.rendered + user-data = data.cloudinit_config.cloud_config.rendered # user_data = "${base64encode(file("${local.cloud_init_template_file}"))}" - user_data = "${file("${local.cloud_init_template_file}")}" +# user_data = "${file("${local.cloud_init_template_file}")}" startup-script = local.os_images[var.gcp_os_image].startup_script } boot_disk {