Skip to content

rhythmictech/terraform-aws-imagebuilder-recipe

Repository files navigation

terraform-aws-imagebuilder-recipe follow on Twitter

Creates EC2 Image Builder recipes

Example

Here's what using the module will look like

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.test_component.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"
  ]
}

About

Creates EC2 Image Builder recipes

Component Parameters (experimental)

In our experience we haven't needed to provide parameters to the components we include in an Image Builder recipe, so the easiest use case has been to simply include a list of ARNs (component_arns variable). If you need to provide parameters, you can use the separate component_parameters map, e.g.

  component_arns = [
    module.test_component.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"
  ]

  component_parameters = [
    { 
      module.test_component.component_arn = [
        { "param1" = "value1"},
        { "param2" = "value2"}
      ],
    },
    { 
      "arn:aws:imagebuilder:us-east-1:aws:component/simple-boot-test-linux/1.0.0/1" = [
        { "param1" = "value1"}
      ],
    }
  ]

Requirements

Name Version
terraform >= 0.12.2
aws >= 2.44

Providers

Name Version
aws 4.49.0

Modules

No modules.

Resources

Name Type
aws_imagebuilder_image_recipe.this resource
aws_region.current data source

Inputs

Name Description Type Default Required
block_device_mappings List of Maps of EBS volumes to mount See examples for further usage tips. list(any) null no
cloudformation_timeout How long to wait (in minutes) for CFN to apply before giving up number 10 no
component_arns List of component ARNs to use in recipe. Order matters list(string) n/a yes
component_parameters A map of component arns (as specified in component_arns) that contains a list of maps of parameters (each parameter contains a name and a value) to apply to the component map(list(map(string))) {} no
description description of component string null no
name name to use for component string n/a yes
parent_image Image that the recipe should start with. SemVers is ok (and encouraged) string n/a yes
platform Platform of Recipe (Linux or Windows) string "Linux" no
recipe_version Version of the recipe string n/a yes
systems_manager_agent_uninstall_after_build Boolean value for whether or not the systems manager agent should be uninstall from the image after it is built bool false no
tags Map of tags to use for CFN stack and component map(string) {} no
update Whether recipe should include the update-$platform recipe before running other components bool true no
user_data_base64 Base64 Encoded user-data to provide when spinning up the build instance. string null no
working_directory Working directory to use in the build instance. ImageBuilder uses /tmp by default on Linux, which can be an issue when working with CIS-hardened images. string null no

Outputs

Name Description
latest_image_arn ARN of the wildcard representing the latest EC2 Image Builder Image
recipe_arn ARN of the EC2 Image Builder Recipe

The Giants underneath this module

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