Skip to content

Commit a8a3214

Browse files
Add user_data_replace_on_change (cloudposse#188)
* Add user_data_replace_on_change * Skip check * rebuild readme * Update readme --------- Co-authored-by: Joe Niland <joe@originalmind.com.au>
1 parent 5dd574d commit a8a3214

File tree

5 files changed

+16
-6
lines changed

5 files changed

+16
-6
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,14 +162,14 @@ Available targets:
162162
| Name | Version |
163163
|------|---------|
164164
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.0 |
165-
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 2.0 |
165+
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 4.7.0 |
166166
| <a name="requirement_null"></a> [null](#requirement\_null) | >= 2.0 |
167167

168168
## Providers
169169

170170
| Name | Version |
171171
|------|---------|
172-
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 2.0 |
172+
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 4.7.0 |
173173
| <a name="provider_null"></a> [null](#provider\_null) | >= 2.0 |
174174

175175
## Modules
@@ -295,6 +295,7 @@ Available targets:
295295
| <a name="input_tenant"></a> [tenant](#input\_tenant) | ID element \_(Rarely used, not included by default)\_. A customer identifier, indicating who this instance of a resource is for | `string` | `null` | no |
296296
| <a name="input_user_data"></a> [user\_data](#input\_user\_data) | The user data to provide when launching the instance. Do not pass gzip-compressed data via this argument; use `user_data_base64` instead | `string` | `null` | no |
297297
| <a name="input_user_data_base64"></a> [user\_data\_base64](#input\_user\_data\_base64) | Can be used instead of `user_data` to pass base64-encoded binary data directly. Use this instead of `user_data` whenever the value is not a valid UTF-8 string. For example, gzip-encoded user data must be base64-encoded and passed via this argument to avoid corruption | `string` | `null` | no |
298+
| <a name="input_user_data_replace_on_change"></a> [user\_data\_replace\_on\_change](#input\_user\_data\_replace\_on\_change) | When used in combination with user\_data or user\_data\_base64 will trigger a destroy and recreate when set to true. | `bool` | `false` | no |
298299
| <a name="input_volume_tags_enabled"></a> [volume\_tags\_enabled](#input\_volume\_tags\_enabled) | Whether or not to copy instance tags to root and EBS volumes | `bool` | `true` | no |
299300
| <a name="input_vpc_id"></a> [vpc\_id](#input\_vpc\_id) | The ID of the VPC that the instance security group belongs to | `string` | n/a | yes |
300301

docs/terraform.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44
| Name | Version |
55
|------|---------|
66
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.0 |
7-
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 2.0 |
7+
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 4.7.0 |
88
| <a name="requirement_null"></a> [null](#requirement\_null) | >= 2.0 |
99

1010
## Providers
1111

1212
| Name | Version |
1313
|------|---------|
14-
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 2.0 |
14+
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 4.7.0 |
1515
| <a name="provider_null"></a> [null](#provider\_null) | >= 2.0 |
1616

1717
## Modules
@@ -137,6 +137,7 @@
137137
| <a name="input_tenant"></a> [tenant](#input\_tenant) | ID element \_(Rarely used, not included by default)\_. A customer identifier, indicating who this instance of a resource is for | `string` | `null` | no |
138138
| <a name="input_user_data"></a> [user\_data](#input\_user\_data) | The user data to provide when launching the instance. Do not pass gzip-compressed data via this argument; use `user_data_base64` instead | `string` | `null` | no |
139139
| <a name="input_user_data_base64"></a> [user\_data\_base64](#input\_user\_data\_base64) | Can be used instead of `user_data` to pass base64-encoded binary data directly. Use this instead of `user_data` whenever the value is not a valid UTF-8 string. For example, gzip-encoded user data must be base64-encoded and passed via this argument to avoid corruption | `string` | `null` | no |
140+
| <a name="input_user_data_replace_on_change"></a> [user\_data\_replace\_on\_change](#input\_user\_data\_replace\_on\_change) | When used in combination with user\_data or user\_data\_base64 will trigger a destroy and recreate when set to true. | `bool` | `false` | no |
140141
| <a name="input_volume_tags_enabled"></a> [volume\_tags\_enabled](#input\_volume\_tags\_enabled) | Whether or not to copy instance tags to root and EBS volumes | `bool` | `true` | no |
141142
| <a name="input_vpc_id"></a> [vpc\_id](#input\_vpc\_id) | The ID of the VPC that the instance security group belongs to | `string` | n/a | yes |
142143

main.tf

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ resource "aws_iam_role" "default" {
103103

104104
resource "aws_instance" "default" {
105105
#bridgecrew:skip=BC_AWS_GENERAL_31: Skipping `Ensure Instance Metadata Service Version 1 is not enabled` check until BridgeCrew supports conditional evaluation. See https://github.com/bridgecrewio/checkov/issues/793
106+
#bridgecrew:skip=BC_AWS_GENERAL_68: Skipping ebs_optimized check for `true`
106107
#bridgecrew:skip=BC_AWS_NETWORKING_47: Skiping `Ensure AWS EC2 instance is configured with VPC` because it is incorrectly flagging that this instance does not belong to a VPC even though subnet_id is configured.
107108
count = local.instance_count
108109
ami = local.ami
@@ -112,7 +113,8 @@ resource "aws_instance" "default" {
112113
disable_api_termination = var.disable_api_termination
113114
user_data = var.user_data
114115
user_data_base64 = var.user_data_base64
115-
iam_instance_profile = var.instance_profile_enabled ? local.instance_profile : ""
116+
user_data_replace_on_change = var.user_data_replace_on_change
117+
iam_instance_profile = local.instance_profile
116118
instance_initiated_shutdown_behavior = var.instance_initiated_shutdown_behavior
117119
associate_public_ip_address = var.external_network_interface_enabled ? null : var.associate_public_ip_address
118120
key_name = var.ssh_key_pair

variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ variable "user_data_base64" {
2828
default = null
2929
}
3030

31+
variable "user_data_replace_on_change" {
32+
type = bool
33+
description = "When used in combination with user_data or user_data_base64 will trigger a destroy and recreate when set to true."
34+
default = false
35+
}
36+
3137
variable "instance_type" {
3238
type = string
3339
description = "The type of the instance"

versions.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ terraform {
44
required_providers {
55
aws = {
66
source = "hashicorp/aws"
7-
version = ">= 2.0"
7+
version = ">= 4.7.0"
88
}
99
null = {
1010
source = "hashicorp/null"

0 commit comments

Comments
 (0)