Skip to content

Commit a4fd449

Browse files
authored
Merge pull request #3 from rhythmictech/ENG-1058-as-an-engineer-i-d-like-to-be-able-to-install-and
ENG-1058: init
2 parents baa8ef6 + db13e77 commit a4fd449

9 files changed

Lines changed: 339 additions & 86 deletions

File tree

README.md

Lines changed: 94 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,126 @@
1-
# terraform-terraform-template
1+
# terraform-aws-component-ansible-setup
22
Template repository for terraform modules. Good for any cloud and any provider.
33

4-
[![tflint](https://github.com/rhythmictech/terraform-terraform-template/workflows/tflint/badge.svg?branch=master&event=push)](https://github.com/rhythmictech/terraform-terraform-template/actions?query=workflow%3Atflint+event%3Apush+branch%3Amaster)
5-
[![tfsec](https://github.com/rhythmictech/terraform-terraform-template/workflows/tfsec/badge.svg?branch=master&event=push)](https://github.com/rhythmictech/terraform-terraform-template/actions?query=workflow%3Atfsec+event%3Apush+branch%3Amaster)
6-
[![yamllint](https://github.com/rhythmictech/terraform-terraform-template/workflows/yamllint/badge.svg?branch=master&event=push)](https://github.com/rhythmictech/terraform-terraform-template/actions?query=workflow%3Ayamllint+event%3Apush+branch%3Amaster)
7-
[![misspell](https://github.com/rhythmictech/terraform-terraform-template/workflows/misspell/badge.svg?branch=master&event=push)](https://github.com/rhythmictech/terraform-terraform-template/actions?query=workflow%3Amisspell+event%3Apush+branch%3Amaster)
8-
[![pre-commit-check](https://github.com/rhythmictech/terraform-terraform-template/workflows/pre-commit-check/badge.svg?branch=master&event=push)](https://github.com/rhythmictech/terraform-terraform-template/actions?query=workflow%3Apre-commit-check+event%3Apush+branch%3Amaster)
4+
[![tflint](https://github.com/rhythmictech/terraform-aws-component-ansible-setup/workflows/tflint/badge.svg?branch=master&event=push)](https://github.com/rhythmictech/terraform-aws-component-ansible-setup/actions?query=workflow%3Atflint+event%3Apush+branch%3Amaster)
5+
[![tfsec](https://github.com/rhythmictech/terraform-aws-component-ansible-setup/workflows/tfsec/badge.svg?branch=master&event=push)](https://github.com/rhythmictech/terraform-aws-component-ansible-setup/actions?query=workflow%3Atfsec+event%3Apush+branch%3Amaster)
6+
[![yamllint](https://github.com/rhythmictech/terraform-aws-component-ansible-setup/workflows/yamllint/badge.svg?branch=master&event=push)](https://github.com/rhythmictech/terraform-aws-component-ansible-setup/actions?query=workflow%3Ayamllint+event%3Apush+branch%3Amaster)
7+
[![misspell](https://github.com/rhythmictech/terraform-aws-component-ansible-setup/workflows/misspell/badge.svg?branch=master&event=push)](https://github.com/rhythmictech/terraform-aws-component-ansible-setup/actions?query=workflow%3Amisspell+event%3Apush+branch%3Amaster)
8+
[![pre-commit-check](https://github.com/rhythmictech/terraform-aws-component-ansible-setup/workflows/pre-commit-check/badge.svg?branch=master&event=push)](https://github.com/rhythmictech/terraform-aws-component-ansible-setup/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 an EC2 Image Builder component with CloudFormation which installs Ansible on Amazon Linux 2
12+
1113
## Example
12-
Here's what using the module will look like
1314
```hcl
14-
module "example" {
15-
source = "rhythmictech/terraform-mycloud-mymodule
15+
data "aws_caller_identity" "current" {
16+
}
17+
18+
locals {
19+
account_id = data.aws_caller_identity.current.account_id
20+
tags = module.tags.tags_no_name
21+
}
22+
23+
module "tags" {
24+
source = "rhythmictech/tags"
25+
version = "~> 1.1.0"
26+
27+
names = [
28+
"smiller",
29+
"imagebuilder-test"
30+
]
31+
32+
tags = merge({
33+
"Env" = "test"
34+
"Namespace" = "smiller"
35+
"notes" = "Testing only - Can be safely deleted"
36+
"Owner" = var.owner
37+
}, var.additional_tags)
38+
}
39+
40+
module "component_ansible_setup" {
41+
source = "rhythmictech/imagebuilder-component-ansible-setup/aws"
42+
version = "~> 1.0.0-rc1"
43+
44+
component_version = "1.0.0"
45+
description = "Testing ansible setup"
46+
name = "testing-setup-component"
47+
tags = local.tags
1648
}
49+
50+
module "test_recipe" {
51+
source = "rhythmictech/imagebuilder-recipe/aws"
52+
version = "~> 0.2.0"
53+
54+
description = "Testing recipe"
55+
name = "test-recipe"
56+
parent_image = "arn:aws:imagebuilder:us-east-1:aws:image/amazon-linux-2-x86/x.x.x"
57+
recipe_version = "1.0.0"
58+
tags = local.tags
59+
update = true
60+
61+
component_arns = [
62+
module.component_ansible_setup.component_arn,
63+
"arn:aws:imagebuilder:us-east-1:aws:component/simple-boot-test-linux/1.0.0/1",
64+
"arn:aws:imagebuilder:us-east-1:aws:component/reboot-test-linux/1.0.0/1"
65+
]
66+
}
67+
68+
module "test_pipeline" {
69+
source = "rhythmictech/imagebuilder-pipeline/aws"
70+
version = "~> 0.3.0"
71+
72+
description = "Testing pipeline"
73+
name = "test-pipeline"
74+
tags = local.tags
75+
recipe_arn = module.test_recipe.recipe_arn
76+
public = false
77+
}
78+
1779
```
1880

1981
## About
20-
A bit about this module
82+
This module bridges the gap allowing Terraform to create an EC2 Image Builder component which installs Ansible on Amazon Linux 2 until native support for Image Builder is added to Terraform
2183

2284
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
2385
## Requirements
2486

2587
| Name | Version |
2688
|------|---------|
27-
| terraform | >= 0.12.14 |
89+
| terraform | >= 0.12.28 |
90+
| aws | >= 2.44, < 4.0.0 |
2891

2992
## Providers
3093

31-
No provider.
94+
| Name | Version |
95+
|------|---------|
96+
| aws | >= 2.44, < 4.0.0 |
3297

3398
## Inputs
3499

35100
| Name | Description | Type | Default | Required |
36101
|------|-------------|------|---------|:--------:|
37-
| name | Moniker to apply to all resources in the module | `string` | n/a | yes |
38-
| tags | User-Defined tags | `map(string)` | `{}` | no |
102+
| component\_version | Version of the component | `string` | n/a | yes |
103+
| name | name to use for component | `string` | n/a | yes |
104+
| change\_description | description of changes since last version | `string` | `null` | no |
105+
| cloudformation\_timeout | How long to wait (in minutes) for CFN to apply before giving up | `number` | `10` | no |
106+
| data\_uri | Use this to override the component document with one at a particualar URL endpoint | `string` | `null` | no |
107+
| description | description of component | `string` | `null` | no |
108+
| kms\_key\_id | KMS key to use for encryption | `string` | `null` | no |
109+
| platform | platform of component (Linux or Windows) | `string` | `"Linux"` | no |
110+
| ssh\_key\_secret\_arn | ARN of a secretsmanager secret containing an SSH key (use arn OR name, not both) | `string` | `null` | no |
111+
| ssh\_key\_secret\_name | Name of a secretsmanager secret containing an SSH key (use arn OR name, not both) | `string` | `null` | no |
112+
| tags | map of tags to use for CFN stack and component | `map(string)` | `{}` | no |
39113

40114
## Outputs
41115

42116
| Name | Description |
43117
|------|-------------|
44-
| tags\_module | Tags Module in it's entirety |
118+
| component\_arn | ARN of the EC2 Image Builder Component |
45119

46120
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
47121

48-
## The Giants Underneath this Module
49-
- [pre-commit.com](pre-commit.com)
50-
- [terraform.io](terraform.io)
51-
- [github.com/tfutils/tfenv](github.com/tfutils/tfenv)
52-
- [github.com/segmentio/terraform-docs](github.com/segmentio/terraform-docs)
122+
## The Giants underneath this module
123+
- pre-commit.com/
124+
- terraform.io/
125+
- github.com/tfutils/tfenv
126+
- github.com/segmentio/terraform-docs

cloudformation.yml.tpl

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
Resources:
2+
ImageBuildComponent:
3+
Type: AWS::ImageBuilder::Component
4+
# Retaining each component when updated because the old component can't be removed until the recipe is updated
5+
UpdateReplacePolicy: Retain
6+
Properties:
7+
Name: ${name}
8+
Version: ${version}
9+
%{~ if change_description != null ~}
10+
ChangeDescription: ${change_description}
11+
%{~ endif ~}
12+
%{~ if description != null ~}
13+
Description: ${description}
14+
%{~ endif ~}
15+
%{~ if kms_key_id != null ~}
16+
KmsKeyId: ${kms_key_id}
17+
%{~ endif ~}
18+
Platform: ${platform}
19+
Tags:
20+
${ indent(8, chomp(yamlencode(tags))) }
21+
%{~ if uri != null ~}
22+
Uri: ${uri}
23+
%{~ endif ~}
24+
%{~ if data != null ~}
25+
Data: |
26+
${indent(8, data)}
27+
%{~ endif ~}
28+
Outputs:
29+
ComponentArn:
30+
Description: ARN of the created component
31+
Value: !Ref "ImageBuildComponent"

component.yml.tpl

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: ${name}-document
2+
%{ if description != null ~}
3+
description: ${description}
4+
%{ endif ~}
5+
schemaVersion: 1.0
6+
phases:
7+
- name: build
8+
steps:
9+
- name: ansible-install
10+
action: ExecuteBash
11+
inputs:
12+
commands:
13+
# Install Ansible dependencies
14+
- sudo yum install -y python python3 python-pip python3-pip git
15+
# Enable Ansible repository
16+
- sudo amazon-linux-extras enable ansible2
17+
# Install Ansible
18+
# TODO: #1 Enable version selection
19+
- sudo yum install -y ansible

examples/basic/README.md

Lines changed: 14 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,19 @@
22
A basic example for this repository
33

44
## Code
5-
Look to [main.tf](./main.tf), or be helpful and copy/paste that code here.
5+
```hcl
6+
module "test_component" {
7+
source = "rhythmictech/imagebuilder-component-ansible/aws"
8+
version = "~> 0.2.0"
9+
10+
component_version = "1.0.0"
11+
description = "Testing component"
12+
name = "testing-component"
13+
playbook_dir = "packer-generic-images/base"
14+
playbook_repo = "https://github.com/rhythmictech/packer-generic-images.git"
15+
tags = local.tags
16+
}
17+
```
618

719
## Applying
820
```
@@ -12,47 +24,5 @@ Apply complete! Resources: 0 added, 0 changed, 0 destroyed.
1224
1325
Outputs:
1426
15-
example = {
16-
"tags_module" = {
17-
"name" = "TEST"
18-
"name32" = "TEST"
19-
"name6" = "TEST"
20-
"namenosymbols" = "TEST"
21-
"tags" = {
22-
"Name" = "TEST"
23-
"terraform_managed" = true
24-
"terraform_module" = "terraform-terraform-tags-1.0.0"
25-
"terraform_root_module" = "."
26-
"terraform_workspace" = "default"
27-
}
28-
"tags_as_list_of_maps" = [
29-
{
30-
"key" = "Name"
31-
"value" = "TEST"
32-
},
33-
{
34-
"key" = "terraform_managed"
35-
"value" = true
36-
},
37-
{
38-
"key" = "terraform_module"
39-
"value" = "terraform-terraform-tags-1.0.0"
40-
},
41-
{
42-
"key" = "terraform_root_module"
43-
"value" = "."
44-
},
45-
{
46-
"key" = "terraform_workspace"
47-
"value" = "default"
48-
},
49-
]
50-
"tags_no_name" = {
51-
"terraform_managed" = true
52-
"terraform_module" = "terraform-terraform-tags-1.0.0"
53-
"terraform_root_module" = "."
54-
"terraform_workspace" = "default"
55-
}
56-
}
57-
}
27+
component_arn = arn:aws:imagebuilder:us-east-1:000000000000:component/testing-component/1.0.0/1
5828
```

examples/basic/main.tf

Lines changed: 58 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,63 @@
1+
data "aws_caller_identity" "current" {
2+
}
3+
4+
locals {
5+
account_id = data.aws_caller_identity.current.account_id
6+
tags = module.tags.tags_no_name
7+
}
8+
9+
module "tags" {
10+
source = "rhythmictech/tags"
11+
version = "~> 1.1.0"
12+
13+
names = [
14+
"smiller",
15+
"imagebuilder-test"
16+
]
17+
18+
tags = merge({
19+
"Env" = "test"
20+
"Namespace" = "smiller"
21+
"notes" = "Testing only - Can be safely deleted"
22+
"Owner" = var.owner
23+
}, var.additional_tags)
24+
}
25+
26+
module "component_ansible_setup" {
27+
source = "rhythmictech/imagebuilder-component-ansible-setup/aws"
28+
version = "~> 1.0.0-rc1"
29+
30+
component_version = "1.0.0"
31+
description = "Testing ansible setup"
32+
name = "testing-setup-component"
33+
tags = local.tags
34+
}
35+
36+
module "test_recipe" {
37+
source = "rhythmictech/imagebuilder-recipe/aws"
38+
version = "~> 0.2.0"
139

2-
module "example" {
3-
source = "../.."
40+
description = "Testing recipe"
41+
name = "test-recipe"
42+
parent_image = "arn:aws:imagebuilder:us-east-1:aws:image/amazon-linux-2-x86/x.x.x"
43+
recipe_version = "1.0.0"
44+
tags = local.tags
45+
update = true
446

5-
name = "test"
47+
component_arns = [
48+
module.component_ansible_setup.component_arn,
49+
"arn:aws:imagebuilder:us-east-1:aws:component/simple-boot-test-linux/1.0.0/1",
50+
"arn:aws:imagebuilder:us-east-1:aws:component/reboot-test-linux/1.0.0/1"
51+
]
652
}
753

8-
output "example" {
9-
value = module.example
54+
module "test_pipeline" {
55+
source = "rhythmictech/imagebuilder-pipeline/aws"
56+
version = "~> 0.3.0"
57+
58+
description = "Testing pipeline"
59+
name = "test-pipeline"
60+
tags = local.tags
61+
recipe_arn = module.test_recipe.recipe_arn
62+
public = false
1063
}

0 commit comments

Comments
 (0)