Skip to content

Commit 4d7f3d8

Browse files
feat!: Add support for user_data_replace_on_change, and updated AWS provider to v4.7+ (#272)
1 parent 94f02f6 commit 4d7f3d8

File tree

8 files changed

+24
-11
lines changed

8 files changed

+24
-11
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,13 +168,13 @@ The following combinations are supported to conditionally create resources:
168168
| Name | Version |
169169
|------|---------|
170170
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 0.13.1 |
171-
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 3.72 |
171+
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 4.7 |
172172

173173
## Providers
174174

175175
| Name | Version |
176176
|------|---------|
177-
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 3.72 |
177+
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 4.7 |
178178

179179
## Modules
180180

@@ -240,6 +240,7 @@ No modules.
240240
| <a name="input_timeouts"></a> [timeouts](#input\_timeouts) | Define maximum timeout for creating, updating, and deleting EC2 instance resources | `map(string)` | `{}` | no |
241241
| <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; see user\_data\_base64 instead. | `string` | `null` | no |
242242
| <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 |
243+
| <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. Defaults to false if not set. | `bool` | `false` | no |
243244
| <a name="input_volume_tags"></a> [volume\_tags](#input\_volume\_tags) | A mapping of tags to assign to the devices created by the instance at launch time | `map(string)` | `{}` | no |
244245
| <a name="input_vpc_security_group_ids"></a> [vpc\_security\_group\_ids](#input\_vpc\_security\_group\_ids) | A list of security group IDs to associate with | `list(string)` | `null` | no |
245246

examples/complete/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@ Note that this example may create resources which can cost money. Run `terraform
2020
| Name | Version |
2121
|------|---------|
2222
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 0.13.1 |
23-
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 3.72 |
23+
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 4.7 |
2424

2525
## Providers
2626

2727
| Name | Version |
2828
|------|---------|
29-
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 3.72 |
29+
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 4.7 |
3030

3131
## Modules
3232

examples/complete/main.tf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,8 @@ module "ec2_complete" {
100100
hibernation = true
101101
# enclave_options_enabled = true
102102

103-
user_data_base64 = base64encode(local.user_data)
103+
user_data_base64 = base64encode(local.user_data)
104+
user_data_replace_on_change = true
104105

105106
cpu_core_count = 2 # default 4
106107
cpu_threads_per_core = 1 # default 2

examples/complete/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 = ">= 3.72"
7+
version = ">= 4.7"
88
}
99
}
1010
}

main.tf

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,12 @@ resource "aws_instance" "this" {
1111
instance_type = var.instance_type
1212
cpu_core_count = var.cpu_core_count
1313
cpu_threads_per_core = var.cpu_threads_per_core
14-
user_data = var.user_data
15-
user_data_base64 = var.user_data_base64
1614
hibernation = var.hibernation
1715

16+
user_data = var.user_data
17+
user_data_base64 = var.user_data_base64
18+
user_data_replace_on_change = var.user_data_replace_on_change
19+
1820
availability_zone = var.availability_zone
1921
subnet_id = var.subnet_id
2022
vpc_security_group_ids = var.vpc_security_group_ids
@@ -144,10 +146,12 @@ resource "aws_spot_instance_request" "this" {
144146
instance_type = var.instance_type
145147
cpu_core_count = var.cpu_core_count
146148
cpu_threads_per_core = var.cpu_threads_per_core
147-
user_data = var.user_data
148-
user_data_base64 = var.user_data_base64
149149
hibernation = var.hibernation
150150

151+
user_data = var.user_data
152+
user_data_base64 = var.user_data_base64
153+
user_data_replace_on_change = var.user_data_replace_on_change
154+
151155
availability_zone = var.availability_zone
152156
subnet_id = var.subnet_id
153157
vpc_security_group_ids = var.vpc_security_group_ids

variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,12 @@ variable "user_data_base64" {
208208
default = null
209209
}
210210

211+
variable "user_data_replace_on_change" {
212+
description = "When used in combination with user_data or user_data_base64 will trigger a destroy and recreate when set to true. Defaults to false if not set."
213+
type = bool
214+
default = false
215+
}
216+
211217
variable "volume_tags" {
212218
description = "A mapping of tags to assign to the devices created by the instance at launch time"
213219
type = map(string)

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 = ">= 3.72"
7+
version = ">= 4.7"
88
}
99
}
1010
}

wrappers/main.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ module "wrapper" {
3838
tenancy = try(each.value.tenancy, var.defaults.tenancy, null)
3939
user_data = try(each.value.user_data, var.defaults.user_data, null)
4040
user_data_base64 = try(each.value.user_data_base64, var.defaults.user_data_base64, null)
41+
user_data_replace_on_change = try(each.value.user_data_replace_on_change, var.defaults.user_data_replace_on_change, false)
4142
volume_tags = try(each.value.volume_tags, var.defaults.volume_tags, {})
4243
enable_volume_tags = try(each.value.enable_volume_tags, var.defaults.enable_volume_tags, true)
4344
vpc_security_group_ids = try(each.value.vpc_security_group_ids, var.defaults.vpc_security_group_ids, null)

0 commit comments

Comments
 (0)