Created
November 3, 2021 14:13
-
-
Save naumvd95/e1310569f7136674c2811445601e21ea to your computer and use it in GitHub Desktop.
Simple example using etcdv3 as DB for tf states + locks (paxos comes in play ;))
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -ex | |
# brew install etcd | |
etcd & | |
# check etcd | |
ETCDCTL_API=3 etcdctl put foo bar | |
ETCDCTL_API=3 etcdctl get foo | |
# prepare tf main | |
cat <<EOF > main.tf | |
terraform { | |
backend "etcdv3" { | |
endpoints = ["0.0.0.0:2379"] | |
lock = true | |
prefix = "terraform-state/" | |
} | |
} | |
data "terraform_remote_state" "tf_remote_etcd" { | |
backend = "etcdv3" | |
config = { | |
endpoints = ["0.0.0.0:2379"] | |
lock = true | |
prefix = "terraform-state/" | |
} | |
} | |
resource "local_file" "my_file" { | |
filename = "test-file.txt" | |
content = "Hey, its a test file" | |
} | |
EOF | |
# brew install terraform | |
terraform init | |
terraform fmt | |
terraform validate | |
terraform plan | |
terraform apply | |
# check remote state | |
ETCDCTL_API=3 etcdctl get --prefix "terraform-state/" | |
# do not forget to shut down etcd, ps aux | grep etcd ->> kill -9 PID |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment