Skip to content

Commit

Permalink
Remote template_file provider
Browse files Browse the repository at this point in the history
  • Loading branch information
sdickenson committed Dec 18, 2023
1 parent e486be3 commit 4bd4e6b
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,17 @@ data "aws_ami" "ondemand" {

data "aws_region" "current" {}

data "template_file" "userdata" {
template = file("${path.module}/userdata.tpl")
vars = {
bucket = var.config_bucket_name
region = var.config_bucket_region == "" ? data.aws_region.current.name : var.config_bucket_region
license = var.use_byol ? var.config_bucket_license_file : ""
config_file = var.config_bucket_config_file
}
}

locals {
latest_ami = var.use_byol ? data.aws_ami.byol.id : data.aws_ami.ondemand.id
ami = coalesce(var.override_ami, local.latest_ami)
userdata = templatefile("${path.module}/userdata.tpl",
{
bucket = var.config_bucket_name
region = var.config_bucket_region == "" ? data.aws_region.current.name : var.config_bucket_region
license = var.use_byol ? var.config_bucket_license_file : ""
config_file = var.config_bucket_config_file
}
)
}

module "fortigate_password" {
Expand Down Expand Up @@ -71,7 +69,7 @@ resource "aws_instance" "this" {
var.tags, {
"Name" = var.name
})
user_data = var.enable_auto_config ? data.template_file.userdata.rendered : ""
user_data = var.enable_auto_config ? local.userdata : ""
vpc_security_group_ids = [aws_security_group.internal.id]

depends_on = [aws_s3_bucket_object.default_config]
Expand Down

0 comments on commit 4bd4e6b

Please sign in to comment.