Skip to content

Commit 1efe640

Browse files
authored
Merge pull request #4 from rhythmictech/ami-name
Add image_name parameter
2 parents 4fd34c8 + 7fc1a8f commit 1efe640

File tree

4 files changed

+44
-31
lines changed

4 files changed

+44
-31
lines changed

Diff for: README.md

+30-29
Original file line numberDiff line numberDiff line change
@@ -22,47 +22,48 @@ Allows the creation of EC2 Image Builder Pipelines with Cloudformation until nat
2222
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
2323
## Requirements
2424

25-
| Name | Version |
26-
|-----------|-----------|
25+
| Name | Version |
26+
|------|---------|
2727
| terraform | >= 0.12.2 |
28-
| aws | ~> 2.44 |
28+
| aws | ~> 2.44 |
2929

3030
## Providers
3131

3232
| Name | Version |
3333
|------|---------|
34-
| aws | ~> 2.44 |
34+
| aws | ~> 2.44 |
3535

3636
## Inputs
3737

38-
| Name | Description | Type | Default | Required |
39-
|-------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------|:--------:|
40-
| name | name to use for component | `string` | n/a | yes |
41-
| recipe\_arn | ARN of the recipe to use. Must change with Recipe version | `string` | n/a | yes |
42-
| additional\_iam\_policy\_arns | List of ARN policies for addional builder permissions | `list(string)` | `[]` | no |
43-
| cloudformation\_timeout | How long to wait (in minutes) for CFN to apply before giving up | `number` | `10` | no |
44-
| description | description of component | `string` | `null` | no |
45-
| enabled | Whether pipeline is ENABLED or DISABLED | `bool` | `true` | no |
46-
| 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 |
47-
| key\_pair | EC2 key pair to add to the default user on the builder | `string` | `null` | no |
48-
| license\_config\_arns | If you're using License Manager, your ARNs go here | `list(string)` | `null` | no |
49-
| log\_bucket | Bucket to store logs in. If this is ommited logs will not be stored | `string` | `null` | no |
50-
| log\_prefix | S3 prefix to store logs at. Recommended if sharing bucket with other pipelines | `string` | `null` | no |
51-
| public | Whether resulting AMI should be public | `bool` | `false` | no |
52-
| regions | Regions that AMIs will be available in | `list(string)` | <pre>[<br> "us-east-1",<br> "us-east-2",<br> "us-west-1",<br> "us-west-2",<br> "ca-central-1"<br>]</pre> | no |
53-
| schedule | Schedule expression for when pipeline should run automatically https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-imagebuilder-imagepipeline-schedule.html | <pre>object({<br> PipelineExecutionStartCondition = string<br> ScheduleExpression = string<br> })</pre> | <pre>{<br> "PipelineExecutionStartCondition": "EXPRESSION_MATCH_AND_DEPENDENCY_UPDATES_AVAILABLE",<br> "ScheduleExpression": "cron(0 0 * * mon)"<br>}</pre> | no |
54-
| security\_group\_ids | Security group IDs for the Image Builder | `list(string)` | `null` | no |
55-
| shared\_account\_ids | AWS accounts to share AMIs with. If this is left null AMIs will be public | `list(string)` | `[]` | no |
56-
| sns\_topic\_arn | SNS topic to notify when new images are created | `string` | `null` | no |
57-
| subnet | Subnet ID to use for builder | `string` | `null` | no |
58-
| tags | map of tags to use for CFN stack and component | `map(string)` | `{}` | no |
59-
| terminate\_on\_failure | Change to false if you want to ssh into a builder for debugging after failure | `bool` | `true` | no |
60-
| test\_config | Whether to run tests during image creation and maximum time to allow tests to run | <pre>object({<br> ImageTestsEnabled = bool<br> TimeoutMinutes = number<br> })</pre> | <pre>{<br> "ImageTestsEnabled": true,<br> "TimeoutMinutes": 60<br>}</pre> | no |
38+
| Name | Description | Type | Default | Required |
39+
|------|-------------|------|---------|:--------:|
40+
| name | name to use for component | `string` | n/a | yes |
41+
| recipe\_arn | ARN of the recipe to use. Must change with Recipe version | `string` | n/a | yes |
42+
| additional\_iam\_policy\_arns | List of ARN policies for addional builder permissions | `list(string)` | `[]` | no |
43+
| cloudformation\_timeout | How long to wait (in minutes) for CFN to apply before giving up | `number` | `10` | no |
44+
| description | description of component | `string` | `null` | no |
45+
| enabled | Whether pipeline is ENABLED or DISABLED | `bool` | `true` | no |
46+
| image\_name | The name prefix given to the AMI created by the pipeline (a timestamp will be added to the end) | `string` | `""` | no |
47+
| 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 |
48+
| key\_pair | EC2 key pair to add to the default user on the builder | `string` | `null` | no |
49+
| license\_config\_arns | If you're using License Manager, your ARNs go here | `list(string)` | `null` | no |
50+
| log\_bucket | Bucket to store logs in. If this is ommited logs will not be stored | `string` | `null` | no |
51+
| log\_prefix | S3 prefix to store logs at. Recommended if sharing bucket with other pipelines | `string` | `null` | no |
52+
| public | Whether resulting AMI should be public | `bool` | `false` | no |
53+
| regions | Regions that AMIs will be available in | `list(string)` | <pre>[<br> "us-east-1",<br> "us-east-2",<br> "us-west-1",<br> "us-west-2",<br> "ca-central-1"<br>]</pre> | no |
54+
| schedule | Schedule expression for when pipeline should run automatically https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-imagebuilder-imagepipeline-schedule.html | <pre>object({<br> PipelineExecutionStartCondition = string<br> ScheduleExpression = string<br> })</pre> | <pre>{<br> "PipelineExecutionStartCondition": "EXPRESSION_MATCH_AND_DEPENDENCY_UPDATES_AVAILABLE",<br> "ScheduleExpression": "cron(0 0 * * mon)"<br>}</pre> | no |
55+
| security\_group\_ids | Security group IDs for the Image Builder | `list(string)` | `null` | no |
56+
| shared\_account\_ids | AWS accounts to share AMIs with. If this is left null AMIs will be public | `list(string)` | `[]` | no |
57+
| sns\_topic\_arn | SNS topic to notify when new images are created | `string` | `null` | no |
58+
| subnet | Subnet ID to use for builder | `string` | `null` | no |
59+
| tags | map of tags to use for CFN stack and component | `map(string)` | `{}` | no |
60+
| terminate\_on\_failure | Change to false if you want to ssh into a builder for debugging after failure | `bool` | `true` | no |
61+
| test\_config | Whether to run tests during image creation and maximum time to allow tests to run | <pre>object({<br> ImageTestsEnabled = bool<br> TimeoutMinutes = number<br> })</pre> | <pre>{<br> "ImageTestsEnabled": true,<br> "TimeoutMinutes": 60<br>}</pre> | no |
6162

6263
## Outputs
6364

64-
| Name | Description |
65-
|---------------|-----------------------------------|
65+
| Name | Description |
66+
|------|-------------|
6667
| pipeline\_arn | ARN of EC2 Image Builder Pipeline |
6768

6869
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->

Diff for: cloudformation.yml.tpl

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Resources:
99
Distributions:
1010
%{~ for region in regions ~}
1111
- AmiDistributionConfiguration:
12-
Name: '${name} - ${region} - AmiCopyConfiguration - {{ imagebuilder:buildDate }}'
12+
Name: '${image_name}-{{ imagebuilder:buildDate }}'
1313
%{~ if description != null ~}
1414
Description: ${description}
1515
%{~ endif ~}

Diff for: main.tf

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
locals {
2+
image_name = coalesce(
3+
var.image_name,
4+
var.name
5+
)
6+
27
log_prefix_computed = (
38
var.log_prefix != null
49
? replace("/${var.log_prefix}/*", "//{2,}/", "/")
@@ -85,14 +90,15 @@ resource "aws_cloudformation_stack" "this" {
8590
)
8691

8792
template_body = templatefile("${path.module}/cloudformation.yml.tpl", {
93+
name = var.name
8894
description = var.description
95+
image_name = local.image_name
8996
instance_profile = aws_iam_instance_profile.this.name
9097
instance_types = var.instance_types
9198
key_pair = var.key_pair
9299
license_config_arns = var.license_config_arns
93100
log_bucket = var.log_bucket
94101
log_prefix = var.log_prefix
95-
name = var.name
96102
public = var.public
97103
recipe_arn = var.recipe_arn
98104
regions = var.regions

Diff for: variables.tf

+6
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ variable "enabled" {
2222
type = bool
2323
}
2424

25+
variable "image_name" {
26+
default = ""
27+
description = "The name prefix given to the AMI created by the pipeline (a timestamp will be added to the end)"
28+
type = string
29+
}
30+
2531
variable "instance_types" {
2632
default = ["t3.medium"]
2733
description = "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)"

0 commit comments

Comments
 (0)