Skip to content

Commit

Permalink
Merge pull request #13 from rhythmictech/ENG-1058-as-an-engineer-i-d-…
Browse files Browse the repository at this point in the history
…like-to-be-able-to-install-and

move Ansible setup and teardown to separate components
  • Loading branch information
smiller171 authored Sep 22, 2020
2 parents bd067a8 + f79e0b4 commit b4de5eb
Show file tree
Hide file tree
Showing 12 changed files with 186 additions and 53 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/pre-commit.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ jobs:
uses: actions/setup-python@v2
- name: Install prerequisites
run: ./bin/install-ubuntu.sh
- name: Setup Terraform
uses: hashicorp/setup-terraform@v1
with:
terraform_version: ~0.12.29
- name: initialize Terraform
run: terraform init --backend=false
- name: pre-commit
Expand Down
8 changes: 6 additions & 2 deletions .github/workflows/pullRequest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ jobs:
uses: actions/setup-python@v2
- name: Install prerequisites
run: ./bin/install-ubuntu.sh
- name: Setup Terraform
uses: hashicorp/setup-terraform@v1
with:
terraform_version: ~0.12.29
- name: initialize Terraform
run: terraform init --backend=false
- name: pre-commit
Expand Down Expand Up @@ -40,7 +44,7 @@ jobs:
- name: setup Terraform
uses: hashicorp/setup-terraform@v1
with:
terraform_version: 0.12.26
terraform_version: ~0.12.29
- name: Terraform init
run: terraform init --backend=false
- name: tflint
Expand All @@ -58,7 +62,7 @@ jobs:
- name: setup Terraform
uses: hashicorp/setup-terraform@v1
with:
terraform_version: 0.12.26
terraform_version: ~0.12.29
- name: Terraform init
run: terraform init --backend=false
- name: tfsec
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/tflint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
- name: setup Terraform
uses: hashicorp/setup-terraform@v1
with:
terraform_version: 0.12.26
terraform_version: ~0.12.29
- name: Terraform init
run: terraform init --backend=false
- name: tflint
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/tfsec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
- name: setup Terraform
uses: hashicorp/setup-terraform@v1
with:
terraform_version: 0.12.26
terraform_version: ~0.12.29
- name: Terraform init
run: terraform init --backend=false
- name: tfsec
Expand Down
1 change: 1 addition & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ repos:
cd $(dirname "$FILE")
terraform init --backend=false
terraform validate .
cd ..
done
'
language: system
Expand Down
93 changes: 78 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,28 +1,91 @@
# terraform-aws-imagebuilder-component-ansible

[![tflint](https://github.com/rhythmictech/terraform-aws-imagebuilder-component-ansible/workflows/tflint/badge.svg?branch=master&event=push)](https://github.com/rhythmictech/terraform-aws-imagebuilder-component-ansible/actions?query=workflow%3Atflint+event%3Apush+branch%3Amaster)
[![tfsec](https://github.com/rhythmictech/terraform-aws-imagebuilder-component-ansible/workflows/tfsec/badge.svg?branch=master&event=push)](https://github.com/rhythmictech/terraform-aws-imagebuilder-component-ansible/actions?query=workflow%3Atfsec+event%3Apush+branch%3Amaster)
[![yamllint](https://github.com/rhythmictech/terraform-aws-imagebuilder-component-ansible/workflows/yamllint/badge.svg?branch=master&event=push)](https://github.com/rhythmictech/terraform-aws-imagebuilder-component-ansible/actions?query=workflow%3Ayamllint+event%3Apush+branch%3Amaster)
[![misspell](https://github.com/rhythmictech/terraform-aws-imagebuilder-component-ansible/workflows/misspell/badge.svg?branch=master&event=push)](https://github.com/rhythmictech/terraform-aws-imagebuilder-component-ansible/actions?query=workflow%3Amisspell+event%3Apush+branch%3Amaster)
[![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)
# terraform-aws-component-ansible
Template repository for terraform modules. Good for any cloud and any provider.

[![tflint](https://github.com/rhythmictech/terraform-aws-component-ansible/workflows/tflint/badge.svg?branch=master&event=push)](https://github.com/rhythmictech/terraform-aws-component-ansible/actions?query=workflow%3Atflint+event%3Apush+branch%3Amaster)
[![tfsec](https://github.com/rhythmictech/terraform-aws-component-ansible/workflows/tfsec/badge.svg?branch=master&event=push)](https://github.com/rhythmictech/terraform-aws-component-ansible/actions?query=workflow%3Atfsec+event%3Apush+branch%3Amaster)
[![yamllint](https://github.com/rhythmictech/terraform-aws-component-ansible/workflows/yamllint/badge.svg?branch=master&event=push)](https://github.com/rhythmictech/terraform-aws-component-ansible/actions?query=workflow%3Ayamllint+event%3Apush+branch%3Amaster)
[![misspell](https://github.com/rhythmictech/terraform-aws-component-ansible/workflows/misspell/badge.svg?branch=master&event=push)](https://github.com/rhythmictech/terraform-aws-component-ansible/actions?query=workflow%3Amisspell+event%3Apush+branch%3Amaster)
[![pre-commit-check](https://github.com/rhythmictech/terraform-aws-component-ansible/workflows/pre-commit-check/badge.svg?branch=master&event=push)](https://github.com/rhythmictech/terraform-aws-component-ansible/actions?query=workflow%3Apre-commit-check+event%3Apush+branch%3Amaster)
<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>


Terraform module that creates EC2 Image Builder components with CloudFormation

## Example
```hcl
module "test_component" {
data "aws_caller_identity" "current" {
}
locals {
account_id = data.aws_caller_identity.current.account_id
tags = module.tags.tags_no_name
}
module "tags" {
source = "git::https://github.com/rhythmictech/terraform-terraform-tags.git?ref=v1.0.0"
names = [
"smiller",
"imagebuilder-test"
]
tags = merge({
"Env" = "test"
"Namespace" = "smiller"
"notes" = "Testing only - Can be safely deleted"
"Owner" = var.owner
}, var.additional_tags)
}
module "component_ansible_setup" {
source = "rhythmictech/imagebuilder-component-ansible-setup/aws"
version = "~> 1.0.0-rc1"
component_version = "1.0.0"
description = "Testing ansible setup"
name = "testing-setup-component"
tags = local.tags
}
module "component_ansible" {
source = "rhythmictech/imagebuilder-component-ansible/aws"
version = "~> 0.2.0"
version = "~> 2.0.0-rc1"
component_version = "1.0.0"
description = "Testing component"
name = "testing-component"
playbook_dir = "packer-generic-images/base"
playbook_repo = "https://github.com/rhythmictech/packer-generic-images.git"
tags = local.tags
}
module "test_recipe" {
source = "rhythmictech/imagebuilder-recipe/aws"
version = "~> 0.2.0"
description = "Testing recipe"
name = "test-recipe"
parent_image = "arn:aws:imagebuilder:us-east-1:aws:image/amazon-linux-2-x86/x.x.x"
recipe_version = "1.0.0"
tags = local.tags
update = true
component_arns = [
module.component_ansible_setup.component_arn,
module.component_ansible.component_arn,
"arn:aws:imagebuilder:us-east-1:aws:component/simple-boot-test-linux/1.0.0/1",
"arn:aws:imagebuilder:us-east-1:aws:component/reboot-test-linux/1.0.0/1"
]
}
module "test_pipeline" {
source = "rhythmictech/imagebuilder-pipeline/aws"
version = "~> 0.3.0"
description = "Testing pipeline"
name = "test-pipeline"
tags = local.tags
recipe_arn = module.test_recipe.recipe_arn
public = false
}
```

## About
Expand All @@ -33,14 +96,14 @@ This module bridges the gap allowing Terraform to create EC2 Image Builder compo

| Name | Version |
|------|---------|
| terraform | >= 0.12.20 |
| aws | ~> 2.44 |
| terraform | >= 0.12.28 |
| aws | >= 2.44, < 4.0.0 |

## Providers

| Name | Version |
|------|---------|
| aws | ~> 2.44 |
| aws | >= 2.44, < 4.0.0 |

## Inputs

Expand Down
4 changes: 2 additions & 2 deletions bin/install-macos.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ git config --global init.templateDir ~/.git-template
pre-commit init-templatedir ~/.git-template

echo 'installing terraform with tfenv'
tfenv install min-required
tfenv use min-required
tfenv install latest:^0.12
tfenv use latest:^0.12
4 changes: 2 additions & 2 deletions bin/install-ubuntu.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ git config --global init.templateDir ~/.git-template
pre-commit init-templatedir ~/.git-template

echo 'installing terraform with tfenv'
tfenv install min-required
tfenv use min-required
tfenv install latest:^0.12
tfenv use latest:^0.12
18 changes: 0 additions & 18 deletions component.yml.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,6 @@ schemaVersion: 1.0
phases:
- name: build
steps:
- name: ansible-install
action: ExecuteBash
inputs:
commands:
# Install Ansible dependencies
- sudo yum install -y python python3 python-pip python3-pip git ${additional_pkgs}
# Enable Ansible repository
- sudo amazon-linux-extras enable ansible2
# Install Ansible
- sudo yum install -y ansible
- name: get-playbook
action: ExecuteBash
inputs:
Expand Down Expand Up @@ -60,11 +50,3 @@ phases:
- while [ ! -f /var/lib/cloud/instance/boot-finished ]; do echo 'Waiting for cloud-init...'; sleep 1; done
# Run playbook
- ansible-playbook ${playbook_file}
- name: cleanup
action: ExecuteBash
inputs:
commands:
- sudo yum remove -y ansible
- sudo yum autoremove -y
- sudo rm -rf ansible-repo
- sudo rm -rf ~/.ansible/roles /usr/share/ansible/roles /etc/ansible/roles
73 changes: 69 additions & 4 deletions examples/basic/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,82 @@ A basic example for this repository

## Code
```hcl
module "test_component" {
data "aws_caller_identity" "current" {
}
locals {
account_id = data.aws_caller_identity.current.account_id
tags = module.tags.tags_no_name
}
module "tags" {
source = "rhythmictech/tags"
version = "~> 1.1.0"
names = [
"smiller",
"imagebuilder-test"
]
tags = merge({
"Env" = "test"
"Namespace" = "smiller"
"notes" = "Testing only - Can be safely deleted"
"Owner" = var.owner
}, var.additional_tags)
}
module "component_ansible_setup" {
source = "rhythmictech/imagebuilder-component-ansible-setup/aws"
version = "~> 1.0.0-rc1"
component_version = "1.0.0"
description = "Testing ansible setup"
name = "testing-setup-component"
tags = local.tags
}
module "component_ansible" {
source = "rhythmictech/imagebuilder-component-ansible/aws"
version = "~> 0.2.0"
version = "~> 2.0.0-rc1"
component_version = "1.0.0"
description = "Testing component"
name = "testing-component"
playbook_dir = "packer-generic-images/base"
playbook_repo = "https://github.com/rhythmictech/packer-generic-images.git"
tags = local.tags
}
module "test_recipe" {
source = "rhythmictech/imagebuilder-recipe/aws"
version = "~> 0.2.0"
description = "Testing recipe"
name = "test-recipe"
parent_image = "arn:aws:imagebuilder:us-east-1:aws:image/amazon-linux-2-x86/x.x.x"
recipe_version = "1.0.0"
tags = local.tags
update = true
component_arns = [
module.component_ansible_setup.component_arn,
module.component_ansible.component_arn,
"arn:aws:imagebuilder:us-east-1:aws:component/simple-boot-test-linux/1.0.0/1",
"arn:aws:imagebuilder:us-east-1:aws:component/reboot-test-linux/1.0.0/1"
]
}
module "test_pipeline" {
source = "rhythmictech/imagebuilder-pipeline/aws"
version = "~> 0.3.0"
description = "Testing pipeline"
name = "test-pipeline"
tags = local.tags
recipe_arn = module.test_recipe.recipe_arn
public = false
}
```

## Applying
Expand Down
23 changes: 17 additions & 6 deletions examples/basic/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ locals {
}

module "tags" {
source = "git::https://github.com/rhythmictech/terraform-terraform-tags.git?ref=v1.0.0"
source = "rhythmictech/tags"
version = "~> 1.1.0"


names = [
"smiller",
Expand All @@ -22,15 +24,23 @@ module "tags" {
}, var.additional_tags)
}

module "test_component" {
module "component_ansible_setup" {
source = "rhythmictech/imagebuilder-component-ansible-setup/aws"
version = "~> 1.0.0-rc1"

component_version = "1.0.0"
description = "Testing ansible setup"
name = "testing-setup-component"
tags = local.tags
}

module "component_ansible" {
source = "rhythmictech/imagebuilder-component-ansible/aws"
version = "~> 0.2.0"
version = "~> 2.0.0-rc1"

component_version = "1.0.0"
description = "Testing component"
name = "testing-component"
playbook_dir = "packer-generic-images/base"
playbook_repo = "https://github.com/rhythmictech/packer-generic-images.git"
tags = local.tags
}

Expand All @@ -46,7 +56,8 @@ module "test_recipe" {
update = true

component_arns = [
module.test_component.component_arn,
module.component_ansible_setup.component_arn,
module.component_ansible.component_arn,
"arn:aws:imagebuilder:us-east-1:aws:component/simple-boot-test-linux/1.0.0/1",
"arn:aws:imagebuilder:us-east-1:aws:component/reboot-test-linux/1.0.0/1"
]
Expand Down
7 changes: 5 additions & 2 deletions versions.tf
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
terraform {
required_version = ">= 0.12.20"
required_version = ">= 0.12.28"

required_providers {
aws = "~> 2.44"
aws = {
source = "hashicorp/aws",
version = ">= 2.44, < 4.0.0"
}
}
}

0 comments on commit b4de5eb

Please sign in to comment.