Skip to content

Commit 0962452

Browse files
committed
Added launch_template_configurations variable and functionality
1 parent e0e0685 commit 0962452

File tree

3 files changed

+43
-2
lines changed

3 files changed

+43
-2
lines changed

Diff for: README.md

+27-1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,31 @@ When scheduling linked jobs, it is important to be mindful of the cron schedules
4040

4141
See Amazon's [EC2 Image Builder API Reference](https://docs.aws.amazon.com/imagebuilder/latest/APIReference/API_Schedule.html) for further details.
4242

43+
## Providing Launch Template configurations
44+
If you want to update launch configurations as part of the Image Build process, you can provide them with the launch_template_configurations variable. It accepts a map of regions, where each region is a list of launch template configuration maps (one per account) for that region. It will look like this:
45+
```hcl
46+
launch_template_configurations = {
47+
"us-east-1" = [
48+
{
49+
launch_template_id = "lt-0f1aedef76c015126"
50+
account_id = "123456789012"
51+
},
52+
{
53+
launch_template_id = "lt-0f1aedef86c049140"
54+
account_id = "234567890123"
55+
default = "false"
56+
}
57+
]
58+
"us-west-1" = [
59+
{
60+
launch_template_id = "lt-0f1aedef76c015113"
61+
account_id = "123456789012"
62+
}
63+
]
64+
}
65+
```
66+
Note that you do not have to provide a launch template configuration for every account and region you build AMIs in. You will also need to set up IAM permissions in the destination accounts per https://docs.aws.amazon.com/imagebuilder/latest/userguide/cross-account-dist.html. (You will need to set similar permissions via `additional_iam_policy_arns` for your own image builder pipeline if it is writing to your own account)
67+
4368
## Providing your own Distribution Configuration
4469
By default this module will try to handle the aws_imagebuilder_distribution_configuration configuration by itself. This works for more simple builds that only need to create EC2 images, but it may not be suitable for all users. The `custom_distribution_configs` aims to handle this by allowing users to provide a list of distribution configuration blocks, based off of the terraform described at https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/imagebuilder_distribution_configuration#distribution. Where additional configuration blocks are present, they must be replaced with a map of the same name. An example of this is:
4570
```hcl
@@ -78,7 +103,7 @@ By default this module will try to handle the aws_imagebuilder_distribution_conf
78103

79104
| Name | Version |
80105
|------|---------|
81-
| <a name="provider_aws"></a> [aws](#provider\_aws) | 4.49.0 |
106+
| <a name="provider_aws"></a> [aws](#provider\_aws) | 4.66.0 |
82107

83108
## Modules
84109

@@ -123,6 +148,7 @@ No modules.
123148
| <a name="input_instance_metadata_http_tokens"></a> [instance\_metadata\_http\_tokens](#input\_instance\_metadata\_http\_tokens) | Whether a signed token is required for instance metadata retrieval requests. Valid values: required, optional. | `string` | `"optional"` | no |
124149
| <a name="input_instance_types"></a> [instance\_types](#input\_instance\_types) | Instance types to create images from. It's unclear why this is a list. Possibly because different types can result in different images (like ARM instances) | `list(string)` | <pre>[<br> "t3.medium"<br>]</pre> | no |
125150
| <a name="input_kms_key_id"></a> [kms\_key\_id](#input\_kms\_key\_id) | KMS Key ID to use when encrypting the distributed AMI, if applicable | `string` | `null` | no |
151+
| <a name="input_launch_template_configurations"></a> [launch\_template\_configurations](#input\_launch\_template\_configurations) | A map of regions, where each region is a list of launch template configuration maps (one per account) for that region. Not used when custom\_distribution\_configs is in use. | `any` | `{}` | no |
126152
| <a name="input_license_config_arns"></a> [license\_config\_arns](#input\_license\_config\_arns) | If you're using License Manager, your ARNs go here | `set(string)` | `null` | no |
127153
| <a name="input_log_bucket"></a> [log\_bucket](#input\_log\_bucket) | Bucket to store logs in. If this is ommited logs will not be stored | `string` | `null` | no |
128154
| <a name="input_log_prefix"></a> [log\_prefix](#input\_log\_prefix) | S3 prefix to store logs at. Recommended if sharing bucket with other pipelines | `string` | `null` | no |

Diff for: main.tf

+9
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,15 @@ resource "aws_imagebuilder_distribution_configuration" "this" {
207207
user_ids = var.shared_account_ids
208208
}
209209
}
210+
211+
dynamic "launch_template_configuration" {
212+
for_each = lookup(var.launch_template_configurations, distribution.value, [])
213+
content {
214+
default = lookup(launch_template_configuration.value, "default", null)
215+
account_id = lookup(launch_template_configuration.value, "account_id", null)
216+
launch_template_id = lookup(launch_template_configuration.value, "launch_template_id", null)
217+
}
218+
}
210219
}
211220
}
212221
# Here be dragons. This is for specifying a custom set of distribution configurations as a parameter to the module.

Diff for: variables.tf

+7-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ variable "container_recipe_arn" {
88
default = null
99
description = "ARN of the container recipe to use. Must change with Recipe version"
1010
type = string
11-
1211
}
1312

1413
variable "custom_distribution_configs" {
@@ -89,6 +88,12 @@ variable "kms_key_id" {
8988
type = string
9089
}
9190

91+
variable "launch_template_configurations" {
92+
default = {}
93+
description = "A map of regions, where each region is a list of launch template configuration maps (one per account) for that region. Not used when custom_distribution_configs is in use."
94+
type = any
95+
}
96+
9297
variable "license_config_arns" {
9398
default = null
9499
description = "If you're using License Manager, your ARNs go here"
@@ -151,6 +156,7 @@ variable "schedule_pipeline_execution_start_condition" {
151156
variable "schedule_timezone" {
152157
default = "Etc/UTC"
153158
description = "Timezone (in IANA timezone format) that scheduled builds, as specified by schedule_cron, run on"
159+
type = string
154160
}
155161

156162
variable "security_group_ids" {

0 commit comments

Comments
 (0)