Skip to content

Commit

Permalink
Merge pull request #95 from rackspace-infrastructure-automation/MPCSU…
Browse files Browse the repository at this point in the history
…PENG-3862

Remove deprecated `template_file` usage
  • Loading branch information
stevengorrell authored Apr 18, 2022
2 parents 4aa5896 + fb0e1b3 commit e7491c8
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 24 deletions.
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ New variable `ssm_bootstrap_list` was added to allow setting the SSM association
|------|---------|
| aws | >= 2.7.0 |
| null | n/a |
| template | n/a |

## Modules

Expand Down Expand Up @@ -89,7 +88,6 @@ New variable `ssm_bootstrap_list` was added to allow setting the SSM association
| [aws_ssm_document](https://registry.terraform.io/providers/hashicorp/aws/2.7.0/docs/resources/ssm_document) |
| [aws_ssm_parameter](https://registry.terraform.io/providers/hashicorp/aws/2.7.0/docs/resources/ssm_parameter) |
| [null_data_source](https://registry.terraform.io/providers/hashicorp/null/latest/docs/data-sources/data_source) |
| [template_file](https://registry.terraform.io/providers/hashicorp/template/latest/docs/data-sources/file) |

## Inputs

Expand Down
20 changes: 9 additions & 11 deletions examples/custom_cw_agent_config.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
locals {
cwagent_vars = {
application_log_group_name = "custom_app_log_group_name"
system_log_group_name = "custom_system_log_group_name"
}
}

provider "aws" {
version = "~> 2.7"
version = "~> 3.0"
region = "us-west-2"
}

Expand Down Expand Up @@ -59,14 +66,5 @@ resource "aws_ssm_parameter" "custom_cwagentparam" {
name = "custom_cw_param-${random_string.res_name.result}"
description = "Custom Cloudwatch Agent configuration"
type = "String"
value = data.template_file.custom_cwagentparam.rendered
}

data "template_file" "custom_cwagentparam" {
template = file("./text/linux_cw_agent_param.json")

vars = {
application_log_group_name = "custom_app_log_group_name"
system_log_group_name = "custom_system_log_group_name"
}
value = templatefile("./text/linux_cw_agent_param.json", local.cwagent_vars)
}
20 changes: 9 additions & 11 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@
* New variable `ssm_bootstrap_list` was added to allow setting the SSM association steps using objects instead of strings, allowing easier linting and formatting of these lines. The `additional_ssm_bootstrap_list` variable will continue to work, but will be deprecated in a future release.
*/

locals {
user_data_vars = {
initial_commands = var.initial_userdata_commands
final_commands = var.final_userdata_commands
}
}

terraform {
required_version = ">= 0.12"

Expand Down Expand Up @@ -348,15 +355,6 @@ data "aws_ami" "ar_ami" {
}
}

data "template_file" "user_data" {
template = file("${path.module}/text/${local.user_data_map[local.ec2_os]}")

vars = {
initial_commands = var.initial_userdata_commands
final_commands = var.final_userdata_commands
}
}

data "aws_region" "current_region" {}

data "aws_caller_identity" "current_account" {}
Expand Down Expand Up @@ -719,7 +717,7 @@ resource "aws_instance" "mod_ec2_instance_no_secondary_ebs" {
subnet_id = element(var.subnets, count.index)
tags = merge(var.tags, local.tags, local.tags_ec2, { Name = "${var.name}${var.instance_count > 1 ? format("-%03d", count.index + 1) : ""}" })
tenancy = var.tenancy
user_data_base64 = base64encode(data.template_file.user_data.rendered)
user_data_base64 = base64encode(templatefile("${path.module}/text/${local.user_data_map[local.ec2_os]}", local.user_data_vars))
volume_tags = var.ebs_volume_tags
vpc_security_group_ids = var.security_groups

Expand Down Expand Up @@ -767,7 +765,7 @@ resource "aws_instance" "mod_ec2_instance_with_secondary_ebs" {
subnet_id = element(var.subnets, count.index)
tags = merge(var.tags, local.tags, local.tags_ec2, { Name = "${var.name}${var.instance_count > 1 ? format("-%03d", count.index + 1) : ""}" })
tenancy = var.tenancy
user_data_base64 = base64encode(data.template_file.user_data.rendered)
user_data_base64 = base64encode(templatefile("${path.module}/text/${local.user_data_map[local.ec2_os]}", local.user_data_vars))
volume_tags = var.ebs_volume_tags
vpc_security_group_ids = var.security_groups

Expand Down

0 comments on commit e7491c8

Please sign in to comment.