Skip to content

Commit 7f8fc52

Browse files
feat: replace template provider with templatefile function (#95)
Co-authored-by: cloudpossebot <[email protected]>
1 parent 3f203ee commit 7f8fc52

File tree

5 files changed

+6
-26
lines changed

5 files changed

+6
-26
lines changed

README.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,14 +104,12 @@ Available targets:
104104
|------|---------|
105105
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 0.13.0 |
106106
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 2.55 |
107-
| <a name="requirement_template"></a> [template](#requirement\_template) | >= 2.1 |
108107

109108
## Providers
110109

111110
| Name | Version |
112111
|------|---------|
113112
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 2.55 |
114-
| <a name="provider_template"></a> [template](#provider\_template) | >= 2.1 |
115113

116114
## Modules
117115

@@ -135,7 +133,6 @@ Available targets:
135133
| [aws_iam_policy_document.main](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source |
136134
| [aws_region.default](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/region) | data source |
137135
| [aws_route53_zone.domain](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/route53_zone) | data source |
138-
| [template_file.user_data](https://registry.terraform.io/providers/hashicorp/template/latest/docs/data-sources/file) | data source |
139136

140137
## Inputs
141138

docs/terraform.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,12 @@
55
|------|---------|
66
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 0.13.0 |
77
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 2.55 |
8-
| <a name="requirement_template"></a> [template](#requirement\_template) | >= 2.1 |
98

109
## Providers
1110

1211
| Name | Version |
1312
|------|---------|
1413
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 2.55 |
15-
| <a name="provider_template"></a> [template](#provider\_template) | >= 2.1 |
1614

1715
## Modules
1816

@@ -36,7 +34,6 @@
3634
| [aws_iam_policy_document.main](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source |
3735
| [aws_region.default](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/region) | data source |
3836
| [aws_route53_zone.domain](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/route53_zone) | data source |
39-
| [template_file.user_data](https://registry.terraform.io/providers/hashicorp/template/latest/docs/data-sources/file) | data source |
4037

4138
## Inputs
4239

examples/complete/versions.tf

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,5 @@ terraform {
66
source = "hashicorp/aws"
77
version = ">= 2.55"
88
}
9-
template = {
10-
source = "hashicorp/template"
11-
version = ">= 2.1"
12-
}
139
}
1410
}

main.tf

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ locals {
88
replace(join("", aws_eip.default.*.public_ip), ".", "-"),
99
data.aws_region.default.name == "us-east-1" ? "compute-1" : format("%s.compute", data.aws_region.default.name)
1010
) : null
11+
user_data_templated = templatefile("${path.module}/${var.user_data_template}", {
12+
user_data = join("\n", var.user_data)
13+
ssm_enabled = var.ssm_enabled
14+
ssh_user = var.ssh_user
15+
})
1116
}
1217

1318
data "aws_region" "default" {}
@@ -46,24 +51,13 @@ data "aws_route53_zone" "domain" {
4651
zone_id = var.zone_id
4752
}
4853

49-
data "template_file" "user_data" {
50-
count = module.this.enabled ? 1 : 0
51-
template = file("${path.module}/${var.user_data_template}")
52-
53-
vars = {
54-
user_data = join("\n", var.user_data)
55-
ssm_enabled = var.ssm_enabled
56-
ssh_user = var.ssh_user
57-
}
58-
}
59-
6054
resource "aws_instance" "default" {
6155
#bridgecrew:skip=BC_AWS_PUBLIC_12: Skipping `EC2 Should Not Have Public IPs` check. NAT instance requires public IP.
6256
#bridgecrew:skip=BC_AWS_GENERAL_31: Skipping `Ensure Instance Metadata Service Version 1 is not enabled` check until BridgeCrew support condition evaluation. See https://github.com/bridgecrewio/checkov/issues/793
6357
count = module.this.enabled ? 1 : 0
6458
ami = coalesce(var.ami, join("", data.aws_ami.default.*.id))
6559
instance_type = var.instance_type
66-
user_data = length(var.user_data_base64) > 0 ? var.user_data_base64 : data.template_file.user_data[0].rendered
60+
user_data = length(var.user_data_base64) > 0 ? var.user_data_base64 : local.user_data_templated
6761
vpc_security_group_ids = compact(concat(module.security_group.*.id, var.security_groups))
6862
iam_instance_profile = local.instance_profile
6963
associate_public_ip_address = var.associate_public_ip_address

versions.tf

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,5 @@ terraform {
66
source = "hashicorp/aws"
77
version = ">= 2.55"
88
}
9-
template = {
10-
source = "hashicorp/template"
11-
version = ">= 2.1"
12-
}
139
}
1410
}

0 commit comments

Comments
 (0)