Skip to content

rhythmictech/terraform-aws-imagebuilder-component-ansible

Repository files navigation

terraform-aws-imagebuilder-component-ansible

Template repository for terraform modules. Good for any cloud and any provider.

tflint tfsec yamllint misspell pre-commit-check follow on Twitter

Terraform module that creates EC2 Image Builder components using ansible

Example

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 = "~> 2.0.0-rc1"

  component_version = "1.0.0"
  description       = "Testing component"
  name              = "testing-component"
  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

This module allows creation of an Ansible Playbook component for use in EC2 Image Builder Recipes.

Requirements

Name Version
terraform >= 0.14
aws >= 4.22.0

Providers

Name Version
aws >= 4.22.0

Modules

No modules.

Resources

Name Type
aws_imagebuilder_component.this resource
aws_caller_identity.current data source
aws_region.current data source
aws_secretsmanager_secret.ssh_key data source

Inputs

Name Description Type Default Required
ansible_use_venv Whether or not ansible should be run in a virtual environment bool true no
ansible_venv_path Path at which to create the ansible virtual environment string "/var/tmp/ansible_venv/" no
change_description description of changes since last version string null no
component_version Version of the component string n/a yes
data_uri Use this to override the component document with one at a particualar URL endpoint string null no
description description of component string null no
kms_key_id KMS key to use for encryption string null no
name name to use for component string n/a yes
platform platform of component (Linux or Windows) string "Linux" no
playbook_dir directory where playbook and requirements are found (if not root of repo) string null no
playbook_file path to playbook file, relative to playbook_dir string "provision.yml" no
playbook_repo git url for repo where ansible code lives with provisioning playbook and requirements file
can append with -b BRANCH_NAME to clone a specific branch
string n/a yes
ssh_key_secret_arn ARN of a secretsmanager secret containing an SSH key (use arn OR name, not both) string null no
ssh_key_secret_name Name of a secretsmanager secret containing an SSH key (use arn OR name, not both) string null no
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
tags map of tags to use for CFN stack and component map(string) {} no

Outputs

Name Description
component_arn ARN of the EC2 Image Builder Component
latest_minor_version_arn ARN of the EC2 Image Builder Component

The Giants underneath this module

  • pre-commit.com/
  • terraform.io/
  • github.com/tfutils/tfenv
  • github.com/segmentio/terraform-docs