Skip to content

Commit

Permalink
Update HCL2 and JSON example for amazon builders (hashicorp#10645)
Browse files Browse the repository at this point in the history
* move hcl2 example up over json to amazon-ebs
* switch hcl and json templates for all amazon builders
* fix json format
  • Loading branch information
sylviamoss authored Feb 17, 2021
1 parent 6ea7edf commit 201869d
Show file tree
Hide file tree
Showing 14 changed files with 747 additions and 721 deletions.
20 changes: 10 additions & 10 deletions builder/amazon/common/access_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,16 @@ type AccessConfig struct {
// credential types) and GetFederationToken (for federation\_token
// credential types) for more details.
//
// HCL2 example:
//
// ```hcl
// vault_aws_engine {
// name = "myrole"
// role_arn = "myarn"
// ttl = "3600s"
// }
// ```
//
// JSON example:
//
// ```json
Expand All @@ -185,16 +195,6 @@ type AccessConfig struct {
// }
// }
// ```
//
// HCL2 example:
//
// ```hcl
// vault_aws_engine {
// name = "myrole"
// role_arn = "myarn"
// ttl = "3600s"
// }
// ```
VaultAWSEngine VaultAWSEngineOptions `mapstructure:"vault_aws_engine" required:"false"`
// [Polling configuration](#polling-configuration) for the AWS waiter. Configures the waiter that checks
// resource state.
Expand Down
21 changes: 10 additions & 11 deletions builder/amazon/common/block_device.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,17 @@ const (
// The following mapping will tell Packer to encrypt the root volume of the
// build instance at launch using a specific non-default kms key:
//
// JSON example:
// HCL2 example:
//
// ```hcl
// launch_block_device_mappings {
// device_name = "/dev/sda1"
// encrypted = true
// kms_key_id = "1a2b3c4d-5e6f-1a2b-3c4d-5e6f1a2b3c4d"
// }
// ```
//
// JSON example:
// ```json
// launch_block_device_mappings: [
// {
Expand All @@ -42,16 +51,6 @@ const (
// ]
// ```
//
// HCL2 example:
//
// ```hcl
// launch_block_device_mappings {
// device_name = "/dev/sda1"
// encrypted = true
// kms_key_id = "1a2b3c4d-5e6f-1a2b-3c4d-5e6f1a2b3c4d"
// }
// ```
//
// Please note that the kms_key_id option in this example exists for
// launch_block_device_mappings but not ami_block_device_mappings.
//
Expand Down
128 changes: 72 additions & 56 deletions builder/amazon/common/run_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,21 @@ type RunConfig struct {
// Whether or not to check if the IAM instance profile exists. Defaults to false
SkipProfileValidation bool `mapstructure:"skip_profile_validation" required:"false"`
// Temporary IAM instance profile policy document
// If IamInstanceProfile is specified it will be used instead. Example:
// If IamInstanceProfile is specified it will be used instead.
//
// HCL2 example:
// ```hcl
//temporary_iam_instance_profile_policy_document {
// Statement {
// Action = ["logs:*"]
// Effect = "Allow"
// Resource = "*"
// }
// Version = "2012-10-17"
//}
// ```
//
// JSON example:
// ```json
//{
// "Version": "2012-10-17",
Expand All @@ -157,17 +170,7 @@ type RunConfig struct {
// The EC2 instance type to use while building the
// AMI, such as t2.small.
InstanceType string `mapstructure:"instance_type" required:"true"`
// Filters used to populate the `security_group_ids` field. JSON Example:
//
// ```json
// {
// "security_group_filter": {
// "filters": {
// "tag:Class": "packer"
// }
// }
// }
// ```
// Filters used to populate the `security_group_ids` field.
//
// HCL2 Example:
//
Expand All @@ -179,6 +182,17 @@ type RunConfig struct {
// }
// ```
//
// JSON Example:
// ```json
// {
// "security_group_filter": {
// "filters": {
// "tag:Class": "packer"
// }
// }
// }
// ```
//
// This selects the SG's with tag `Class` with the value `packer`.
//
// - `filters` (map of strings) - filters used to select a
Expand Down Expand Up @@ -213,8 +227,24 @@ type RunConfig struct {
// AMI with a root volume snapshot that you have access to.
SourceAmi string `mapstructure:"source_ami" required:"true"`
// Filters used to populate the `source_ami`
// field. JSON Example:
// field.
//
// HCL2 example:
// ```hcl
// source "amazon-ebs" "basic-example" {
// 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
// }
// }
// ```
//
// JSON Example:
// ```json
// "builders" [
// {
Expand All @@ -231,21 +261,6 @@ type RunConfig struct {
// }
// ]
// ```
// HCL2 example:
//
// ```hcl
// source "amazon-ebs" "basic-example" {
// 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
// }
// }
// ```
//
// This selects the most recent Ubuntu 16.04 HVM EBS AMI from Canonical. NOTE:
// This will fail unless *exactly* one AMI is returned. In the above example,
Expand Down Expand Up @@ -313,8 +328,22 @@ type RunConfig struct {
// will allow you to create those programatically.
SpotTag config.KeyValues `mapstructure:"spot_tag" required:"false"`
// Filters used to populate the `subnet_id` field.
// JSON Example:
//
// HCL2 example:
//
// ```hcl
// source "amazon-ebs" "basic-example" {
// subnet_filter {
// filters = {
// "tag:Class": "build"
// }
// most_free = true
// random = false
// }
// }
// ```
//
// JSON Example:
// ```json
// "builders" [
// {
Expand All @@ -329,19 +358,6 @@ type RunConfig struct {
// }
// ]
// ```
// HCL2 example:
//
// ```hcl
// source "amazon-ebs" "basic-example" {
// subnet_filter {
// filters = {
// "tag:Class": "build"
// }
// most_free = true
// random = false
// }
// }
// ```
//
// This selects the Subnet with tag `Class` with the value `build`, which has
// the most free IP addresses. NOTE: This will fail unless *exactly* one
Expand Down Expand Up @@ -388,8 +404,21 @@ type RunConfig struct {
// data when launching the instance.
UserDataFile string `mapstructure:"user_data_file" required:"false"`
// Filters used to populate the `vpc_id` field.
// JSON Example:
//
// HCL2 example:
// ```hcl
// source "amazon-ebs" "basic-example" {
// vpc_filter {
// filters = {
// "tag:Class": "build",
// "isDefault": "false",
// "cidr": "/24"
// }
// }
// }
// ```
//
// JSON Example:
// ```json
// "builders" [
// {
Expand All @@ -404,19 +433,6 @@ type RunConfig struct {
// }
// ]
// ```
// HCL2 example:
//
// ```hcl
// source "amazon-ebs" "basic-example" {
// vpc_filter {
// filters = {
// "tag:Class": "build",
// "isDefault": "false",
// "cidr": "/24"
// }
// }
// }
// ```
//
// This selects the VPC with tag `Class` with the value `build`, which is not
// the default VPC, and have a IPv4 CIDR block of `/24`. NOTE: This will fail
Expand Down
18 changes: 8 additions & 10 deletions builder/amazon/common/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,24 +42,22 @@ type StateChangeConf struct {

// Polling configuration for the AWS waiter. Configures the waiter for resources creation or actions like attaching
// volumes or importing image.
// Usage example:
//
// In JSON:
// ```json
// "aws_polling" : {
// "delay_seconds": 30,
// "max_attempts": 50
// }
// ```
//
// In HCL2:
// HCL2 example:
// ```hcl
// aws_polling {
// delay_seconds = 30
// max_attempts = 50
// }
// ```
//
// JSON example:
// ```json
// "aws_polling" : {
// "delay_seconds": 30,
// "max_attempts": 50
// }
// ```
type AWSPollingConfig struct {
// Specifies the maximum number of attempts the waiter will check for resource state.
// This value can also be set via the AWS_MAX_ATTEMPTS.
Expand Down
Loading

0 comments on commit 201869d

Please sign in to comment.