diff --git a/.github/workflows/terraform-fmt.yaml b/.github/workflows/terraform-fmt.yaml deleted file mode 100644 index 6f54e5e..0000000 --- a/.github/workflows/terraform-fmt.yaml +++ /dev/null @@ -1,32 +0,0 @@ ---- - -name: "terraform fmt" - -'on': - pull_request: - -jobs: - tf-fmt: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - - name: install terraform - run: | - sudo apt-get update && sudo apt-get install -y gnupg software-properties-common - wget -O- https://apt.releases.hashicorp.com/gpg | \ - gpg --dearmor | \ - sudo tee /usr/share/keyrings/hashicorp-archive-keyring.gpg - echo "deb [signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] \ - https://apt.releases.hashicorp.com $(lsb_release -cs) main" | \ - sudo tee /etc/apt/sources.list.d/hashicorp.list - sudo apt update - sudo apt-get install -y terraform - - name: terraform fmt - run: | - shopt -s extglob - if ! terraform fmt -check -diff !(secrets).tf ; then - echo "please update your terraform code to match the above."; - echo 'or run `terraform fmt` to have terraform reformat it.'; - exit 1; - fi diff --git a/.github/workflows/tofu-fmt.yaml b/.github/workflows/tofu-fmt.yaml new file mode 100644 index 0000000..fdae505 --- /dev/null +++ b/.github/workflows/tofu-fmt.yaml @@ -0,0 +1,27 @@ +--- + +name: "tofu fmt" + +'on': + pull_request: + +jobs: + tf-fmt: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + + - name: install tofu + run: | + sudo apt-get update && sudo apt-get install -y gnupg software-properties-common + curl -s https://packagecloud.io/install/repositories/opentofu/tofu/script.deb.sh?any=true -o /tmp/tofu-repository-setup.sh + sudo bash /tmp/tofu-repository-setup.sh + sudo apt install tofu + - name: tofu fmt + run: | + shopt -s extglob + if ! tofu fmt -check -diff !(secrets).tf ; then + echo "please update your tofu code to match the above."; + echo 'or run `tofu fmt` to have tofu reformat it.'; + exit 1; + fi diff --git a/README.md b/README.md index 79de812..aa67e38 100644 --- a/README.md +++ b/README.md @@ -3,18 +3,18 @@ This code can be used to test that we can deploy all the infrastructure that we expect to be able to. # Usage -The terraform-test.sh script should be referenced from a cron that has write access to /var/lib/prometheus/node.d/ +The tofu-test.sh script should be referenced from a cron that has write access to /var/lib/prometheus/node.d/ Example: ``` -0 0 * * * cd /root/tf-infra-test ; /bin/bash /root/tf-infra-test/terraform-test.sh +0 0 * * * cd /root/tf-infra-test ; /bin/bash /root/tf-infra-test/tofu-test.sh ``` This can also be run manually by running ``` -terraform init -terraform apply -var datacenter= -terraform destroy -var datacenter= +tofu init +tofu apply -var datacenter= +tofu destroy -var datacenter= ``` # Tests at time of writing diff --git a/floating-ip.tf b/floating-ip.tf index d744a76..7715bd8 100644 --- a/floating-ip.tf +++ b/floating-ip.tf @@ -1,6 +1,6 @@ resource "openstack_networking_floatingip_v2" "floating_ip" { pool = var.floating-ip-pool[var.datacenter] - description = "terraform test IP" + description = "tofu test IP" } resource "openstack_compute_floatingip_associate_v2" "floating_ip" { diff --git a/hiera-terraform.yaml b/hiera-tofu.yaml similarity index 100% rename from hiera-terraform.yaml rename to hiera-tofu.yaml diff --git a/hiera.tf b/hiera.tf index cd7b9a1..140ca95 100644 --- a/hiera.tf +++ b/hiera.tf @@ -1,9 +1,9 @@ -resource "cloudvps_puppet_prefix" "terraform" { - name = "terraform-" +resource "cloudvps_puppet_prefix" "tofu" { + name = "tofu-" roles = [ - "profile::terraform::tf" + "profile::tofu::tf" ] - hiera = file("hiera-terraform.yaml") + hiera = file("hiera-tofu.yaml") } diff --git a/security_group.tf b/security_group.tf index ec2cc55..5ff420b 100644 --- a/security_group.tf +++ b/security_group.tf @@ -1,6 +1,6 @@ resource "openstack_compute_secgroup_v2" "secgroup" { - name = "terraform-test" - description = "security group deployed by terraform" + name = "tofu-test" + description = "security group deployed by tofu" rule { from_port = 22 diff --git a/terraform-test.sh b/terraform-test.sh deleted file mode 100755 index 93cb3fa..0000000 --- a/terraform-test.sh +++ /dev/null @@ -1,42 +0,0 @@ -#!/bin/bash - -cd $(dirname "$0") - -terraform init - -if [ "${1}" = 'eqiad1' ] -then - datacenter=${1} -elif [ "${1}" = 'codfw1dev' ] -then - datacenter=${1} -else - echo "Please enter datacenter." - echo "Usage:" - echo "${0} " - exit -fi - -if terraform apply -var datacenter=${datacenter} -auto-approve; then - tf_apply=0 -else - tf_apply=1 -fi - -cat << EOF > /var/lib/prometheus/node.d/terraform-apply.prom -# HELP terraform_apply 0 if successful -# TYPE terraform_apply untyped -terraform_apply ${tf_apply} -EOF - -if terraform destroy -var datacenter=${datacenter} -auto-approve; then - tf_destroy=0 -else - tf_destroy=1 -fi - -cat << EOF > /var/lib/prometheus/node.d/terraform-destroy.prom -# HELP terraform_destroy 0 if successful -# TYPE terraform_destroy untyped -terraform_destroy ${tf_destroy} -EOF diff --git a/tofu-test.sh b/tofu-test.sh new file mode 100755 index 0000000..7833d89 --- /dev/null +++ b/tofu-test.sh @@ -0,0 +1,42 @@ +#!/bin/bash + +cd $(dirname "$0") + +tofu init + +if [ "${1}" = 'eqiad1' ] +then + datacenter=${1} +elif [ "${1}" = 'codfw1dev' ] +then + datacenter=${1} +else + echo "Please enter datacenter." + echo "Usage:" + echo "${0} " + exit +fi + +if tofu apply -var datacenter=${datacenter} -auto-approve; then + tf_apply=0 +else + tf_apply=1 +fi + +cat << EOF > /var/lib/prometheus/node.d/tofu-apply.prom +# HELP tofu_apply 0 if successful +# TYPE tofu_apply untyped +tofu_apply ${tf_apply} +EOF + +if tofu destroy -var datacenter=${datacenter} -auto-approve; then + tf_destroy=0 +else + tf_destroy=1 +fi + +cat << EOF > /var/lib/prometheus/node.d/tofu-destroy.prom +# HELP tofu_destroy 0 if successful +# TYPE tofu_destroy untyped +tofu_destroy ${tf_destroy} +EOF diff --git a/volume.tf b/volume.tf index d30d214..d48e69f 100644 --- a/volume.tf +++ b/volume.tf @@ -1,7 +1,7 @@ resource "openstack_blockstorage_volume_v3" "volume" { region = var.region[var.datacenter] name = "volume_tf" - description = "test volume deployed with terraform" + description = "test volume deployed with tofu" size = 3 }