Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Terraform module to create an EC2 Image Builder Pipeline

License

NotificationsYou must be signed in to change notification settings

rhythmictech/terraform-aws-imagebuilder-pipeline

Repository files navigation

tflinttfsecyamllintmisspellpre-commit-checkfollow on Twitter

Terraform module for creating EC2 Image Builder Pipelines

Example

Here's what using the module will look like. Note that this module needs at least one recipe and component to be useful. Seeexamples for details.

module"test_pipeline" {source="rhythmictech/imagebuilder-pipeline/aws"description="Testing pipeline"name="test-pipeline"recipe_arn=module.test_recipe.recipe_arnpublic=false}

About

Allows the creation of EC2 Image Builder Pipelines

Build Scheduling

Builds are scheduled by a cron pattern. The pipeline takes a schedule argument as follows:

schedule_cron="cron(0 0 * * mon)"schedule_pipeline_execution_start_condition="EXPRESSION_MATCH_AND_DEPENDENCY_UPDATES_AVAILABLE"

The default expects an upstream AMI as a parent image and will build weeklyonly if an updated image is found upstream. By settingschedule_pipeline_execution_start_condition = "EXPRESSION_MATCH_ONLY", the build pipeline will always run.

When scheduling linked jobs, it is important to be mindful of the cron schedules. If both pipelines run withschedule_cron = "cron(0 0 * * mon)", the downstream build will always run one week late. Due to the testing phase and startup/teardown time, even a short EC2 Image Builder process can take over 15 minutes to run end to end. Complex test suites can take much longer.

See Amazon'sEC2 Image Builder API Reference for further details.

Providing Launch Template configurations

If you want to update launch configurations as part of the Image Build process, you can provide them with the launch_template_configurations variable. It accepts a map of regions, where each region is a list of launch template configuration maps (one per account) for that region. It will look like this:

launch_template_configurations={"us-east-1"= [      {        launch_template_id="lt-0f1aedef76c015126"        account_id="123456789012"      },      {        launch_template_id="lt-0f1aedef86c049140"        account_id="234567890123"        default="false"      }    ]"us-west-1"= [      {        launch_template_id="lt-0f1aedef76c015113"        account_id="123456789012"      }    ]  }

Note that you do not have to provide a launch template configuration for every account and region you build AMIs in. You will also need to set up IAM permissions in the destination accounts perhttps://docs.aws.amazon.com/imagebuilder/latest/userguide/cross-account-dist.html. (You will need to set similar permissions viaadditional_iam_policy_arns for your own image builder pipeline if it is writing to your own account)

Providing your own Distribution Configuration

By default this module will try to handle the aws_imagebuilder_distribution_configuration configuration by itself. This works for more simple builds that only need to create EC2 images, but it may not be suitable for all users. Thecustom_distribution_configs aims to handle this by allowing users to provide a list of distribution configuration blocks, based off of the terraform described athttps://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/imagebuilder_distribution_configuration#distribution. Where additional configuration blocks are present, they must be replaced with a map of the same name. An example of this is:

custom_distribution_configs=[    {      region="us-east-1",      ami_distribution_configuration= {        name="example-build-{{ imagebuilder:buildDate }}"        launch_permission= {          user_ids= ["123456789012"]        }      }      launch_template_configuration= {        launch_template_id="lt-0123456789abcde"      }    },    {      region="us-west-1"      ami_distribution_configuration= {        name="example-build-{{ imagebuilder:buildDate }}"      }...    }  ]

Requirements

NameVersion
terraform>= 0.14
aws>= 4.22.0

Providers

NameVersion
aws4.66.0

Modules

No modules.

Resources

NameType
aws_iam_instance_profile.thisresource
aws_iam_policy.log_writeresource
aws_iam_policy.secret_readresource
aws_iam_role.thisresource
aws_iam_role_policy_attachment.additionalresource
aws_iam_role_policy_attachment.coreresource
aws_iam_role_policy_attachment.log_writeresource
aws_iam_role_policy_attachment.secret_readresource
aws_imagebuilder_distribution_configuration.thisresource
aws_imagebuilder_image_pipeline.thisresource
aws_imagebuilder_infrastructure_configuration.thisresource
aws_iam_policy_document.assumedata source
aws_iam_policy_document.log_writedata source
aws_iam_policy_document.secret_readdata source
aws_secretsmanager_secret.ssh_keydata source

Inputs

NameDescriptionTypeDefaultRequired
additional_iam_policy_arnsList of ARN policies for addional builder permissionslist(string)[]no
container_recipe_arnARN of the container recipe to use. Must change with Recipe versionstringnullno
custom_distribution_configsTo use your own distribution configurations for the ImageBuilder Distribution Configuration, supply a list of distribution configuration blocks as defined athttps://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/imagebuilder_distribution_configuration#distributionany[]no
descriptiondescription of componentstringnullno
enabledWhether pipeline is ENABLED or DISABLEDbooltrueno
enhanced_image_metadata_enabledWhether additional information about the image being created is collected. Default is true.booltrueno
image_nameThe name prefix given to the AMI created by the pipeline (a timestamp will be added to the end)string""no
image_recipe_arnARN of the image recipe to use. Must change with Recipe versionstringnullno
image_tests_enabledWhether to run tests during image creationbooltrueno
image_tests_timeout_minutesMaximum time to allow for image tests to runnumber60no
instance_key_pairEC2 key pair to add to the default user on the builderstringnullno
instance_metadata_http_put_hop_limitThe number of hops that an instance can traverse to reach its metadata.numbernullno
instance_metadata_http_tokensWhether a signed token is required for instance metadata retrieval requests. Valid values: required, optional.string"optional"no
instance_typesInstance types to create images from. It's unclear why this is a list. Possibly because different types can result in different images (like ARM instances)list(string)
[
"t3.medium"
]
no
kms_key_idKMS Key ID to use when encrypting the distributed AMI, if applicablestringnullno
launch_template_configurationsA map of regions, where each region is a list of launch template configuration maps (one per account) for that region. Not used when custom_distribution_configs is in use.any{}no
license_config_arnsIf you're using License Manager, your ARNs go hereset(string)nullno
log_bucketBucket to store logs in. If this is ommited logs will not be storedstringnullno
log_prefixS3 prefix to store logs at. Recommended if sharing bucket with other pipelinesstringnullno
namename to use for componentstringn/ayes
publicWhether resulting AMI should be publicboolfalseno
regionsRegions that AMIs will be available inlist(string)
[
"us-east-1",
"us-east-2",
"us-west-1",
"us-west-2",
"ca-central-1"
]
no
resource_tagsKey-value map of tags to apply to resources created by this pipelinemap(string)nullno
schedule_cronSchedule (in cron) for when pipeline should run automaticallyhttps://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-imagebuilder-imagepipeline-schedule.htmlstring""no
schedule_pipeline_execution_start_conditionStart Condition Expression for when pipeline should run automaticallyhttps://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-imagebuilder-imagepipeline-schedule.htmlstring"EXPRESSION_MATCH_AND_DEPENDENCY_UPDATES_AVAILABLE"no
schedule_timezoneTimezone (in IANA timezone format) that scheduled builds, as specified by schedule_cron, run onstring"Etc/UTC"no
security_group_idsSecurity group IDs for the Image Builderlist(string)nullno
shared_account_idsAWS accounts to share AMIs with. If this is left null AMIs will be publicset(string)[]no
shared_organization_arnsSet of AWS Organization ARNs to allow access to the created AMIset(string)nullno
shared_ou_arnsSet of AWS Organizational Unit ARNs to allow access to the created AMIset(string)nullno
sns_topic_arnSNS topic to notify when new images are createdstringnullno
ssh_key_secret_arnIf your ImageBuilder Components need to use an SSH Key (private repos, etc.), specify the ARN of the secretsmanager secret containing the SSH key to add access permissions (use arn OR name, not both)stringnullno
ssh_key_secret_nameIf your ImageBuilder Components need to use an SSH Key (private repos, etc.), specify the Name of the secretsmanager secret containing the SSH key to add access permissions (use arn OR name, not both)stringnullno
subnetSubnet ID to use for builderstringnullno
tagsmap of tags to use for componentmap(string){}no
terminate_on_failureChange to false if you want to connect to a builder for debugging after failurebooltrueno

Outputs

NameDescription
pipeline_arnARN of EC2 Image Builder Pipeline
role_nameThe name of the IAM role for use if additional permissions are needed.

The Giants underneath this module

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

[8]ページ先頭

©2009-2025 Movatter.jp