Added SourceAMICreationDate

This commit is contained in:
nitrocode 2020-05-22 07:17:38 -04:00
parent 688ed63edf
commit 6d29ec956b
7 changed files with 26 additions and 17 deletions

View File

@ -8,12 +8,13 @@ import (
) )
type BuildInfoTemplate struct { type BuildInfoTemplate struct {
BuildRegion string BuildRegion string
SourceAMI string SourceAMI string
SourceAMIName string SourceAMICreationDate string
SourceAMIOwner string SourceAMIName string
SourceAMIOwnerName string SourceAMIOwner string
SourceAMITags map[string]string SourceAMIOwnerName string
SourceAMITags map[string]string
} }
func extractBuildInfo(region string, state multistep.StateBag, generatedData *builder.GeneratedData) *BuildInfoTemplate { func extractBuildInfo(region string, state multistep.StateBag, generatedData *builder.GeneratedData) *BuildInfoTemplate {
@ -31,12 +32,13 @@ func extractBuildInfo(region string, state multistep.StateBag, generatedData *bu
} }
buildInfoTemplate := &BuildInfoTemplate{ buildInfoTemplate := &BuildInfoTemplate{
BuildRegion: region, BuildRegion: region,
SourceAMI: aws.StringValue(sourceAMI.ImageId), SourceAMI: aws.StringValue(sourceAMI.ImageId),
SourceAMIName: aws.StringValue(sourceAMI.Name), SourceAMICreationDate: aws.StringValue(sourceAMI.CreationDate),
SourceAMIOwner: aws.StringValue(sourceAMI.OwnerId), SourceAMIName: aws.StringValue(sourceAMI.Name),
SourceAMIOwnerName: aws.StringValue(sourceAMI.ImageOwnerAlias), SourceAMIOwner: aws.StringValue(sourceAMI.OwnerId),
SourceAMITags: sourceAMITags, SourceAMIOwnerName: aws.StringValue(sourceAMI.ImageOwnerAlias),
SourceAMITags: sourceAMITags,
} }
generatedData.Put("SourceAMIName", buildInfoTemplate.SourceAMIName) generatedData.Put("SourceAMIName", buildInfoTemplate.SourceAMIName)
return buildInfoTemplate return buildInfoTemplate

View File

@ -13,6 +13,7 @@ import (
func testImage() *ec2.Image { func testImage() *ec2.Image {
return &ec2.Image{ return &ec2.Image{
ImageId: aws.String("ami-abcd1234"), ImageId: aws.String("ami-abcd1234"),
CreationDate: aws.String("ami_test_creation_date"),
Name: aws.String("ami_test_name"), Name: aws.String("ami_test_name"),
OwnerId: aws.String("ami_test_owner_id"), OwnerId: aws.String("ami_test_owner_id"),
ImageOwnerAlias: aws.String("ami_test_owner_alias"), ImageOwnerAlias: aws.String("ami_test_owner_alias"),
@ -59,11 +60,12 @@ func TestInterpolateBuildInfo_extractBuildInfo_withSourceImage(t *testing.T) {
buildInfo := extractBuildInfo("foo", state, &generatedData) buildInfo := extractBuildInfo("foo", state, &generatedData)
expected := BuildInfoTemplate{ expected := BuildInfoTemplate{
BuildRegion: "foo", BuildRegion: "foo",
SourceAMI: "ami-abcd1234", SourceAMI: "ami-abcd1234",
SourceAMIName: "ami_test_name", SourceAMICreationDate: "ami_test_creation_date",
SourceAMIOwner: "ami_test_owner_id", SourceAMIName: "ami_test_name",
SourceAMIOwnerName: "ami_test_owner_alias", SourceAMIOwner: "ami_test_owner_id",
SourceAMIOwnerName: "ami_test_owner_alias",
SourceAMITags: map[string]string{ SourceAMITags: map[string]string{
"key-1": "value-1", "key-1": "value-1",
"key-2": "value-2", "key-2": "value-2",

View File

@ -289,6 +289,7 @@ variables are available:
building the AMI. building the AMI.
- `SourceAMI` - The source AMI ID (for example `ami-a2412fcd`) used to build - `SourceAMI` - The source AMI ID (for example `ami-a2412fcd`) used to build
the AMI. the AMI.
- `SourceAMICreationDate` - The source AMI creation date (for example `"2020-05-14T19:26:34.000Z"`).
- `SourceAMIName` - The source AMI Name (for example - `SourceAMIName` - The source AMI Name (for example
`ubuntu/images/ebs-ssd/ubuntu-xenial-16.04-amd64-server-20180306`) used to `ubuntu/images/ebs-ssd/ubuntu-xenial-16.04-amd64-server-20180306`) used to
build the AMI. build the AMI.

View File

@ -193,6 +193,7 @@ variables are available:
building the AMI. building the AMI.
- `SourceAMI` - The source AMI ID (for example `ami-a2412fcd`) used to build - `SourceAMI` - The source AMI ID (for example `ami-a2412fcd`) used to build
the AMI. the AMI.
- `SourceAMICreationDate` - The source AMI creation date (for example `"2020-05-14T19:26:34.000Z"`).
- `SourceAMIName` - The source AMI Name (for example - `SourceAMIName` - The source AMI Name (for example
`ubuntu/images/ebs-ssd/ubuntu-xenial-16.04-amd64-server-20180306`) used to `ubuntu/images/ebs-ssd/ubuntu-xenial-16.04-amd64-server-20180306`) used to
build the AMI. build the AMI.

View File

@ -155,6 +155,7 @@ variables are available:
building the AMI. building the AMI.
- `SourceAMI` - The source AMI ID (for example `ami-a2412fcd`) used to build - `SourceAMI` - The source AMI ID (for example `ami-a2412fcd`) used to build
the AMI. the AMI.
- `SourceAMICreationDate` - The source AMI creation date (for example `"2020-05-14T19:26:34.000Z"`).
- `SourceAMIName` - The source AMI Name (for example - `SourceAMIName` - The source AMI Name (for example
`ubuntu/images/ebs-ssd/ubuntu-xenial-16.04-amd64-server-20180306`) used to `ubuntu/images/ebs-ssd/ubuntu-xenial-16.04-amd64-server-20180306`) used to
build the AMI. build the AMI.

View File

@ -176,6 +176,7 @@ variables are available:
building the AMI. building the AMI.
- `SourceAMI` - The source AMI ID (for example `ami-a2412fcd`) used to build - `SourceAMI` - The source AMI ID (for example `ami-a2412fcd`) used to build
the AMI. the AMI.
- `SourceAMICreationDate` - The source AMI creation date (for example `"2020-05-14T19:26:34.000Z"`).
- `SourceAMIName` - The source AMI Name (for example - `SourceAMIName` - The source AMI Name (for example
`ubuntu/images/ebs-ssd/ubuntu-xenial-16.04-amd64-server-20180306`) used to `ubuntu/images/ebs-ssd/ubuntu-xenial-16.04-amd64-server-20180306`) used to
build the AMI. build the AMI.

View File

@ -161,6 +161,7 @@ variables are available:
building the AMI. building the AMI.
- `SourceAMI` - The source AMI ID (for example `ami-a2412fcd`) used to build - `SourceAMI` - The source AMI ID (for example `ami-a2412fcd`) used to build
the AMI. the AMI.
- `SourceAMICreationDate` - The source AMI creation date (for example `"2020-05-14T19:26:34.000Z"`).
- `SourceAMIName` - The source AMI Name (for example - `SourceAMIName` - The source AMI Name (for example
`ubuntu/images/ebs-ssd/ubuntu-xenial-16.04-amd64-server-20180306`) used to `ubuntu/images/ebs-ssd/ubuntu-xenial-16.04-amd64-server-20180306`) used to
build the AMI. build the AMI.