Skip to content

Commit

Permalink
[terraform] remove deprecated template_file
Browse files Browse the repository at this point in the history
  • Loading branch information
rustielin authored and davidiw committed Mar 3, 2022
1 parent c49be2d commit 62327e8
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 30 deletions.
13 changes: 6 additions & 7 deletions terraform/validator/aws/cluster.tf
Original file line number Diff line number Diff line change
Expand Up @@ -53,20 +53,19 @@ locals {
}
}

data "template_file" "user_data" {
for_each = local.pools
template = file("${path.module}/templates/eks_user_data.sh")

vars = {
taints = each.value.taint ? "diem.org/nodepool=${each.key}:NoExecute" : ""
locals {
user_data = { for pool in local.pools :
pool => templatefile("${path.module}/templates/eks_user_data.sh", {
taints = each.value.taint ? "diem.org/nodepool=${pool.key}:NoExecute" : ""
})
}
}

resource "aws_launch_template" "nodes" {
for_each = local.pools
name = "diem-${local.workspace_name}/${each.key}"
instance_type = each.value.instance_type
user_data = base64encode(data.template_file.user_data[each.key].rendered)
user_data = base64encode(local.user_data[each.key])

tag_specifications {
resource_type = "instance"
Expand Down
10 changes: 4 additions & 6 deletions terraform/validator/aws/vault.tf
Original file line number Diff line number Diff line change
Expand Up @@ -272,10 +272,8 @@ resource "aws_instance" "bastion" {
})
}

data "template_file" "vault_user_data" {
template = file("${path.module}/templates/vault_user_data.sh")

vars = {
locals {
vault_user_data = templatefile("${path.module}/templates/vault_user_data.sh", {
region = var.region
vault_version = "1.8.1"
vault_sha256 = "bb411f2bbad79c2e4f0640f1d3d5ef50e2bda7d4f40875a56917c95ff783c2db"
Expand Down Expand Up @@ -310,7 +308,7 @@ data "template_file" "vault_user_data" {
disable_hostname = true
}
})
}
})
}

resource "aws_launch_template" "vault" {
Expand All @@ -319,7 +317,7 @@ resource "aws_launch_template" "vault" {
instance_type = "c5.large"
key_name = aws_key_pair.diem.key_name
vpc_security_group_ids = [aws_security_group.vault.id]
user_data = base64encode(data.template_file.vault_user_data.rendered)
user_data = base64encode(local.vault_user_data)

iam_instance_profile {
arn = aws_iam_instance_profile.vault.arn
Expand Down
3 changes: 0 additions & 3 deletions terraform/validator/aws/versions.tf
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ terraform {
random = {
source = "hashicorp/random"
}
template = {
source = "hashicorp/template"
}
time = {
source = "hashicorp/time"
}
Expand Down
14 changes: 6 additions & 8 deletions terraform/validator/azure/vault.tf
Original file line number Diff line number Diff line change
Expand Up @@ -192,10 +192,8 @@ resource "azurerm_linux_virtual_machine" "bastion" {
}
}

data "template_file" "vault_user_data" {
template = file("${path.module}/templates/vault_user_data.sh")

vars = {
locals {
vault_user_data = templatefile("${path.module}/templates/vault_user_data.sh", {
vault_version = "1.8.1"
vault_sha256 = "bb411f2bbad79c2e4f0640f1d3d5ef50e2bda7d4f40875a56917c95ff783c2db"
vault_ca = tls_self_signed_cert.ca.cert_pem
Expand Down Expand Up @@ -233,7 +231,7 @@ data "template_file" "vault_user_data" {
disable_hostname = true
}
})
}
})
}

resource "azurerm_linux_virtual_machine_scale_set" "vault" {
Expand All @@ -243,7 +241,7 @@ resource "azurerm_linux_virtual_machine_scale_set" "vault" {
sku = "Standard_F2s_v2"
instances = var.vault_num
admin_username = "az-user"
custom_data = base64encode(data.template_file.vault_user_data.rendered)
custom_data = base64encode(local.vault_user_data)

admin_ssh_key {
username = "az-user"
Expand Down Expand Up @@ -295,8 +293,8 @@ resource "azurerm_lb" "vault" {
}

resource "azurerm_lb_backend_address_pool" "vault" {
name = "vault"
loadbalancer_id = azurerm_lb.vault.id
name = "vault"
loadbalancer_id = azurerm_lb.vault.id
}

resource "azurerm_lb_probe" "vault" {
Expand Down
10 changes: 4 additions & 6 deletions terraform/validator/gcp/vault.tf
Original file line number Diff line number Diff line change
Expand Up @@ -214,10 +214,8 @@ resource "google_compute_instance" "bastion" {
metadata_startup_script = file("${path.module}/templates/bastion_user_data.sh")
}

data "template_file" "vault_user_data" {
template = file("${path.module}/templates/vault_user_data.sh")

vars = {
locals {
vault_user_data = templatefile("${path.module}/templates/vault_user_data.sh", {
vault_version = "1.8.1"
vault_sha256 = "bb411f2bbad79c2e4f0640f1d3d5ef50e2bda7d4f40875a56917c95ff783c2db"
vault_ca = tls_self_signed_cert.ca.cert_pem
Expand Down Expand Up @@ -255,7 +253,7 @@ data "template_file" "vault_user_data" {
disable_hostname = true
}
})
}
})
}

resource "google_compute_instance_template" "vault" {
Expand All @@ -282,7 +280,7 @@ resource "google_compute_instance_template" "vault" {
ssh-keys = join("\n", [for user, sshkey in var.ssh_keys : "${user}:${sshkey}"])
}

metadata_startup_script = data.template_file.vault_user_data.rendered
metadata_startup_script = local.vault_user_data

lifecycle {
create_before_destroy = true
Expand Down

0 comments on commit 62327e8

Please sign in to comment.