Last active
October 30, 2024 16:16
-
-
Save michaelkosir/32e2b1392331fe83cd023e29e97bb2d0 to your computer and use it in GitHub Desktop.
This is an example Terraform configuration to automatically initialize Vault and unseal it through Terraform. NOTE: This will store unseal keys and root token in the Terraform state. Highly recommend manually rotating unseal keys and root token after additional Vault configs have been deployed.
This file contains hidden or 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
terraform { | |
required_providers { | |
terracurl = { | |
source = "devops-rob/terracurl" | |
version = "~> 1.2" | |
} | |
} | |
} | |
provider "terracurl" {} | |
variable "address" { | |
type = string | |
default = "http://localhost:8200" | |
} | |
variable "keys" { | |
type = number | |
default = 3 | |
} | |
variable "threshold" { | |
type = number | |
default = 2 | |
} | |
resource "terracurl_request" "init" { | |
name = "init" | |
url = "${var.address}/v1/sys/init" | |
method = "POST" | |
request_body = jsonencode({ | |
secret_shares = var.keys | |
secret_threshold = var.threshold | |
}) | |
response_codes = [200] | |
} | |
resource "terracurl_request" "unseal" { | |
count = var.threshold | |
name = "unseal-${count.index}" | |
url = "${var.address}/v1/sys/unseal" | |
method = "POST" | |
request_body = jsonencode({ | |
key = jsondecode(terracurl_request.init.response).keys[count.index] | |
}) | |
response_codes = [200] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment