From f245ff4e3406f1070ec87e5c6f9354fd08415675 Mon Sep 17 00:00:00 2001 From: Megan Marsh Date: Fri, 17 Jul 2020 15:28:33 -0700 Subject: [PATCH] add hcl example for session manager --- .../partials/builders/aws-session-manager.mdx | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/website/pages/partials/builders/aws-session-manager.mdx b/website/pages/partials/builders/aws-session-manager.mdx index df2123937..14bf72219 100644 --- a/website/pages/partials/builders/aws-session-manager.mdx +++ b/website/pages/partials/builders/aws-session-manager.mdx @@ -15,6 +15,9 @@ To use the session manager as the connection interface for the SSH communicator - `session_manager_port`: A local port on the host machine that should be used as the local end of the session tunnel to the remote host. If not specified Packer will find an available port to use. - `temporary_iam_instance_profile_policy_document`: Creates a temporary instance profile policy document to grant Systems Manager permissions to the Ec2 instance. This is an alternative to using an existing `iam_instance_profile`. + + + ```json { "builders": [ @@ -48,6 +51,52 @@ To use the session manager as the connection interface for the SSH communicator } ``` + + + +```hcl +// In order to get these variables to read from the environment, +// set the environment variables to have the same name as the declared +// variables, with the prefix PKR_VAR_. + +// You could also hardcode them into the file, but we recommend that. + + +source "amazon-ebs" "ssm-example" { + ami_name = "packer_AWS {{timestamp}}" + instance_type = "t2.micro" + region = "us-east-1" + source_ami_filter { + filters = { + virtualization-type = "hvm" + name = "ubuntu/images/*ubuntu-xenial-16.04-amd64-server-*" + root-device-type = "ebs" + } + owners = ["099720109477"] + most_recent = true + } + ssh_username = "ubuntu" + ssh_interface = "session_manager" + communicator = "ssh" + iam_instance_profile = "myinstanceprofile" +} + +build { + sources = [ + "source.amazon-ebs.ssm-example" + ] + + provisioner "shell" { + inline = [ + "echo Connected via SSM at '${build.User}@${build.Host}:${build.Port}'" + ] + } +} +``` + + + + #### Session Manager Plugin Connectivity via the session manager requires the use of a session-manger-plugin, which needs to be installed alongside Packer, and an instance AMI that is capable of running the AWS ssm-agent - see [About SSM Agent](https://docs.aws.amazon.com/systems-manager/latest/userguide/prereqs-ssm-agent.html) for details on supported AMIs.