Skip to content

Commit

Permalink
move to tofu
Browse files Browse the repository at this point in the history
Bug: T352528
  • Loading branch information
vivian-rook committed Dec 1, 2023
1 parent 168a7b1 commit 547699a
Show file tree
Hide file tree
Showing 10 changed files with 82 additions and 87 deletions.
32 changes: 0 additions & 32 deletions .github/workflows/terraform-fmt.yaml

This file was deleted.

27 changes: 27 additions & 0 deletions .github/workflows/tofu-fmt.yaml
Original file line number Diff line number Diff line change
@@ -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
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <eqiad1|codfw1dev>
0 0 * * * cd /root/tf-infra-test ; /bin/bash /root/tf-infra-test/tofu-test.sh <eqiad1|codfw1dev>
```

This can also be run manually by running
```
terraform init
terraform apply -var datacenter=<eqiad1|codfw1dev>
terraform destroy -var datacenter=<eqiad1|codfw1dev>
tofu init
tofu apply -var datacenter=<eqiad1|codfw1dev>
tofu destroy -var datacenter=<eqiad1|codfw1dev>
```

# Tests at time of writing
Expand Down
2 changes: 1 addition & 1 deletion floating-ip.tf
Original file line number Diff line number Diff line change
@@ -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" {
Expand Down
File renamed without changes.
8 changes: 4 additions & 4 deletions hiera.tf
Original file line number Diff line number Diff line change
@@ -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")
}
4 changes: 2 additions & 2 deletions security_group.tf
Original file line number Diff line number Diff line change
@@ -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
Expand Down
42 changes: 0 additions & 42 deletions terraform-test.sh

This file was deleted.

42 changes: 42 additions & 0 deletions tofu-test.sh
Original file line number Diff line number Diff line change
@@ -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} <eqiad1|codfw1dev>"
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
2 changes: 1 addition & 1 deletion volume.tf
Original file line number Diff line number Diff line change
@@ -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
}

Expand Down

0 comments on commit 547699a

Please sign in to comment.