Skip to content

Commit 3a0c386

Browse files
authored
Merge pull request #20 from rhythmictech/v1.X
Refactor to use AWS Provider instead of CloudFormation
2 parents ca86e70 + d141ad0 commit 3a0c386

File tree

7 files changed

+55
-102
lines changed

7 files changed

+55
-102
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
repos:
22
- repo: https://github.com/antonbabenko/pre-commit-terraform
3-
rev: v1.31.0
3+
rev: v1.77.0
44
hooks:
55
- id: terraform_docs
66
always_run: true
7-
args:
8-
- --args=--sort-by-required
97
- id: terraform_fmt
108
- id: terraform_tflint
119
alias: terraform_tflint_deep

README.md

Lines changed: 34 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ Template repository for terraform modules. Good for any cloud and any provider.
88
[![pre-commit-check](https://github.com/rhythmictech/terraform-aws-imagebuilder-component-ansible/workflows/pre-commit-check/badge.svg?branch=master&event=push)](https://github.com/rhythmictech/terraform-aws-imagebuilder-component-ansible/actions?query=workflow%3Apre-commit-check+event%3Apush+branch%3Amaster)
99
<a href="https://twitter.com/intent/follow?screen_name=RhythmicTech"><img src="https://img.shields.io/twitter/follow/RhythmicTech?style=social&logo=twitter" alt="follow on Twitter"></a>
1010

11-
Terraform module that creates EC2 Image Builder components with CloudFormation
12-
11+
Terraform module that creates EC2 Image Builder components using ansible
1312
## Example
1413
```hcl
1514
data "aws_caller_identity" "current" {
@@ -89,48 +88,60 @@ module "test_pipeline" {
8988
```
9089

9190
## About
92-
This module bridges the gap allowing Terraform to create EC2 Image Builder components (especially with Ansible) until native support is added to Terraform
91+
This module allows creation of an Ansible Playbook component for use in EC2 Image Builder Recipes.
9392

9493
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
9594
## Requirements
9695

9796
| Name | Version |
9897
|------|---------|
99-
| terraform | >= 0.12.28 |
100-
| aws | >= 2.44, < 4.0.0 |
98+
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 0.13 |
99+
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 4.22.0 |
101100

102101
## Providers
103102

104103
| Name | Version |
105104
|------|---------|
106-
| aws | >= 2.44, < 4.0.0 |
105+
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 4.22.0 |
106+
107+
## Modules
108+
109+
No modules.
110+
111+
## Resources
112+
113+
| Name | Type |
114+
|------|------|
115+
| [aws_imagebuilder_component.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/imagebuilder_component) | resource |
116+
| [aws_caller_identity.current](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/caller_identity) | data source |
117+
| [aws_region.current](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/region) | data source |
118+
| [aws_secretsmanager_secret.ssh_key](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/secretsmanager_secret) | data source |
107119

108120
## Inputs
109121

110122
| Name | Description | Type | Default | Required |
111123
|------|-------------|------|---------|:--------:|
112-
| component\_version | Version of the component | `string` | n/a | yes |
113-
| name | name to use for component | `string` | n/a | yes |
114-
| playbook\_repo | git url for repo where ansible code lives with provisioning playbook and requirements file<br>can append with `-b BRANCH_NAME` to clone a specific branch | `string` | n/a | yes |
115-
| change\_description | description of changes since last version | `string` | `null` | no |
116-
| cloudformation\_timeout | How long to wait (in minutes) for CFN to apply before giving up | `number` | `10` | no |
117-
| data\_uri | Use this to override the component document with one at a particualar URL endpoint | `string` | `null` | no |
118-
| description | description of component | `string` | `null` | no |
119-
| kms\_key\_id | KMS key to use for encryption | `string` | `null` | no |
120-
| platform | platform of component (Linux or Windows) | `string` | `"Linux"` | no |
121-
| playbook\_dir | directory where playbook and requirements are found (if not root of repo) | `string` | `null` | no |
122-
| playbook\_file | path to playbook file, relative to `playbook_dir` | `string` | `"provision.yml"` | no |
123-
| ssh\_key\_secret\_arn | ARN of a secretsmanager secret containing an SSH key (use arn OR name, not both) | `string` | `null` | no |
124-
| ssh\_key\_secret\_name | Name of a secretsmanager secret containing an SSH key (use arn OR name, not both) | `string` | `null` | no |
125-
| tags | map of tags to use for CFN stack and component | `map(string)` | `{}` | no |
124+
| <a name="input_change_description"></a> [change\_description](#input\_change\_description) | description of changes since last version | `string` | `null` | no |
125+
| <a name="input_component_version"></a> [component\_version](#input\_component\_version) | Version of the component | `string` | n/a | yes |
126+
| <a name="input_data_uri"></a> [data\_uri](#input\_data\_uri) | Use this to override the component document with one at a particualar URL endpoint | `string` | `null` | no |
127+
| <a name="input_description"></a> [description](#input\_description) | description of component | `string` | `null` | no |
128+
| <a name="input_kms_key_id"></a> [kms\_key\_id](#input\_kms\_key\_id) | KMS key to use for encryption | `string` | `null` | no |
129+
| <a name="input_name"></a> [name](#input\_name) | name to use for component | `string` | n/a | yes |
130+
| <a name="input_platform"></a> [platform](#input\_platform) | platform of component (Linux or Windows) | `string` | `"Linux"` | no |
131+
| <a name="input_playbook_dir"></a> [playbook\_dir](#input\_playbook\_dir) | directory where playbook and requirements are found (if not root of repo) | `string` | `null` | no |
132+
| <a name="input_playbook_file"></a> [playbook\_file](#input\_playbook\_file) | path to playbook file, relative to `playbook_dir` | `string` | `"provision.yml"` | no |
133+
| <a name="input_playbook_repo"></a> [playbook\_repo](#input\_playbook\_repo) | git url for repo where ansible code lives with provisioning playbook and requirements file<br>can append with `-b BRANCH_NAME` to clone a specific branch | `string` | n/a | yes |
134+
| <a name="input_ssh_key_secret_arn"></a> [ssh\_key\_secret\_arn](#input\_ssh\_key\_secret\_arn) | ARN of a secretsmanager secret containing an SSH key (use arn OR name, not both) | `string` | `null` | no |
135+
| <a name="input_ssh_key_secret_name"></a> [ssh\_key\_secret\_name](#input\_ssh\_key\_secret\_name) | Name of a secretsmanager secret containing an SSH key (use arn OR name, not both) | `string` | `null` | no |
136+
| <a name="input_supported_os_versions"></a> [supported\_os\_versions](#input\_supported\_os\_versions) | A set of operating system versions supported by the component. If the OS information is available, a prefix match is performed against the base image OS version during image recipe creation. | `set(string)` | `null` | no |
137+
| <a name="input_tags"></a> [tags](#input\_tags) | map of tags to use for CFN stack and component | `map(string)` | `{}` | no |
126138

127139
## Outputs
128140

129141
| Name | Description |
130142
|------|-------------|
131-
| component\_arn | ARN of the EC2 Image Builder Component |
132-
| latest\_minor\_version\_arn | ARN of the EC2 Image Builder Component |
133-
143+
| <a name="output_component_arn"></a> [component\_arn](#output\_component\_arn) | ARN of the EC2 Image Builder Component |
144+
| <a name="output_latest_minor_version_arn"></a> [latest\_minor\_version\_arn](#output\_latest\_minor\_version\_arn) | ARN of the EC2 Image Builder Component |
134145
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
135146

136147
## The Giants underneath this module

cloudformation.yml.tpl

Lines changed: 0 additions & 31 deletions
This file was deleted.

main.tf

Lines changed: 11 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -29,37 +29,20 @@ data "aws_secretsmanager_secret" "ssh_key" {
2929
name = var.ssh_key_secret_name
3030
}
3131

32-
resource "aws_cloudformation_stack" "this" {
33-
name = "${var.name}-${uuid()}"
34-
on_failure = "ROLLBACK"
35-
timeout_in_minutes = var.cloudformation_timeout
32+
resource "aws_imagebuilder_component" "this" {
33+
name = var.name
34+
version = var.component_version
35+
36+
change_description = var.change_description
37+
data = var.data_uri == null ? local.data : null
38+
description = var.description
39+
kms_key_id = var.kms_key_id
40+
platform = var.platform
41+
supported_os_versions = var.supported_os_versions
42+
uri = var.data_uri
3643

3744
tags = merge(
3845
var.tags,
3946
{ Name : "${var.name}-stack" }
4047
)
41-
42-
template_body = templatefile("${path.module}/cloudformation.yml.tpl", {
43-
change_description = var.change_description
44-
data = local.data
45-
description = var.description
46-
kms_key_id = var.kms_key_id
47-
name = var.name
48-
platform = var.platform
49-
uri = var.data_uri
50-
version = var.component_version
51-
52-
tags = merge(
53-
var.tags,
54-
{ Name : var.name }
55-
)
56-
})
57-
58-
lifecycle {
59-
create_before_destroy = true
60-
61-
ignore_changes = [
62-
name
63-
]
64-
}
6548
}

outputs.tf

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,10 @@ locals {
88

99
output "component_arn" {
1010
description = "ARN of the EC2 Image Builder Component"
11-
value = "arn:aws:imagebuilder:${local.region}:${local.account_id}:component/${lower(var.name)}/${var.component_version}/1"
12-
13-
depends_on = [
14-
aws_cloudformation_stack.this
15-
]
11+
value = aws_imagebuilder_component.this.arn
1612
}
1713

1814
output "latest_minor_version_arn" {
1915
description = "ARN of the EC2 Image Builder Component"
2016
value = "arn:aws:imagebuilder:${local.region}:${local.account_id}:component/${lower(var.name)}/${local.latest_component_minor_version}"
21-
22-
depends_on = [
23-
aws_cloudformation_stack.this
24-
]
2517
}

variables.tf

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,6 @@ variable "change_description" {
44
type = string
55
}
66

7-
variable "cloudformation_timeout" {
8-
default = 10
9-
description = "How long to wait (in minutes) for CFN to apply before giving up"
10-
type = number
11-
}
12-
137
variable "component_version" {
148
description = "Version of the component"
159
type = string
@@ -77,6 +71,12 @@ variable "ssh_key_secret_name" {
7771
type = string
7872
}
7973

74+
variable "supported_os_versions" {
75+
default = null
76+
description = "A set of operating system versions supported by the component. If the OS information is available, a prefix match is performed against the base image OS version during image recipe creation."
77+
type = set(string)
78+
}
79+
8080
variable "tags" {
8181
default = {}
8282
description = "map of tags to use for CFN stack and component"

versions.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
terraform {
2-
required_version = ">= 0.12.28"
2+
required_version = ">= 0.14"
33

44
required_providers {
55
aws = {
66
source = "hashicorp/aws",
7-
version = ">= 2.44, < 4.0.0"
7+
version = ">= 4.22.0"
88
}
99
}
1010
}

0 commit comments

Comments
 (0)