-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7056b2e
commit 4d55796
Showing
10 changed files
with
287 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// starts resources to provision them. | ||
build { | ||
name = "bucket-slug" | ||
hcp_packer_registry { | ||
description = "" | ||
labels = { | ||
"foo" = "bar" | ||
} | ||
} | ||
hcp_packer_registry {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// starts resources to provision them. | ||
build { | ||
name = "bucket-slug" | ||
hcp_packer_registry {} | ||
|
||
sources = [ | ||
"source.virtualbox-iso.ubuntu-1204", | ||
] | ||
} | ||
|
||
source "virtualbox-iso" "ubuntu-1204" { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
// starts resources to provision them. | ||
build { | ||
name = "bucket-slug" | ||
hcp_packer_registry { | ||
labels = "" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// starts resources to provision them. | ||
build { | ||
name = "bucket-slug" | ||
hcp_packer_registry { | ||
description = <<EOT | ||
This is a super super super super super super super super super super super super super super super super super super | ||
super super super super super super super super super super super super super super super super super super super super | ||
super super super long description | ||
EOT | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,212 @@ | ||
package hcl2template | ||
|
||
import ( | ||
"path/filepath" | ||
"testing" | ||
|
||
packersdk "github.com/hashicorp/packer-plugin-sdk/packer" | ||
"github.com/hashicorp/packer/internal/packer_registry" | ||
"github.com/hashicorp/packer/packer" | ||
) | ||
|
||
func Test_ParseHCPPackerRegistryBlock(t *testing.T) { | ||
defaultParser := getBasicParser() | ||
|
||
tests := []parseTest{ | ||
{"complete working build with hcp_packer_registry block", | ||
defaultParser, | ||
parseTestArgs{"testdata/hcp_par/complete.pkr.hcl", nil, nil}, | ||
&PackerConfig{ | ||
CorePackerVersionString: lockedVersion, | ||
Basedir: filepath.Join("testdata", "hcp_par"), | ||
Sources: map[SourceRef]SourceBlock{ | ||
refVBIsoUbuntu1204: {Type: "virtualbox-iso", Name: "ubuntu-1204"}, | ||
refAWSEBSUbuntu1604: {Type: "amazon-ebs", Name: "ubuntu-1604"}, | ||
}, | ||
Builds: Builds{ | ||
&BuildBlock{ | ||
Name: "bucket-slug", | ||
HCPPackerRegistry: &HCPPackerRegistryBlock{ | ||
Description: "Some description\n", | ||
Labels: map[string]string{"foo": "bar"}, | ||
}, | ||
Sources: []SourceUseBlock{ | ||
{ | ||
SourceRef: refVBIsoUbuntu1204, | ||
}, | ||
{ | ||
SourceRef: SourceRef{Type: "amazon-ebs", Name: "ubuntu-1604"}, | ||
LocalName: "aws-ubuntu-16.04", | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
false, false, | ||
[]packersdk.Build{ | ||
&packer.CoreBuild{ | ||
BuildName: "bucket-slug", | ||
Type: "virtualbox-iso.ubuntu-1204", | ||
Prepared: true, | ||
Builder: &packer.RegistryBuilder{ | ||
Name: "virtualbox-iso.ubuntu-1204", | ||
Builder: emptyMockBuilder, | ||
ArtifactMetadataPublisher: &packer_registry.Bucket{ | ||
Slug: "bucket-slug", | ||
Description: "Some description\n", | ||
Labels: map[string]string{"foo": "bar"}, | ||
Iteration: &packer_registry.Iteration{ | ||
Fingerprint: "ignored-fingerprint", // this will be different everytime so it's ignored | ||
}, | ||
}, | ||
}, | ||
Provisioners: []packer.CoreBuildProvisioner{}, | ||
PostProcessors: [][]packer.CoreBuildPostProcessor{ | ||
{ | ||
{ | ||
PostProcessor: &packer.RegistryPostProcessor{ | ||
BuilderType: "virtualbox-iso.ubuntu-1204", | ||
ArtifactMetadataPublisher: &packer_registry.Bucket{ | ||
Slug: "bucket-slug", | ||
Description: "Some description\n", | ||
Labels: map[string]string{"foo": "bar"}, | ||
Iteration: &packer_registry.Iteration{ | ||
Fingerprint: "ignored-fingerprint", | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
&packer.CoreBuild{ | ||
BuildName: "bucket-slug", | ||
Type: "amazon-ebs.aws-ubuntu-16.04", | ||
Prepared: true, | ||
Builder: &packer.RegistryBuilder{ | ||
Name: "amazon-ebs.aws-ubuntu-16.04", | ||
Builder: emptyMockBuilder, | ||
ArtifactMetadataPublisher: &packer_registry.Bucket{ | ||
Slug: "bucket-slug", | ||
Description: "Some description\n", | ||
Labels: map[string]string{"foo": "bar"}, | ||
Iteration: &packer_registry.Iteration{ | ||
Fingerprint: "ignored-fingerprint", // this will be different everytime so it's ignored | ||
}, | ||
}, | ||
}, | ||
Provisioners: []packer.CoreBuildProvisioner{}, | ||
PostProcessors: [][]packer.CoreBuildPostProcessor{ | ||
{ | ||
{ | ||
PostProcessor: &packer.RegistryPostProcessor{ | ||
BuilderType: "amazon-ebs.aws-ubuntu-16.04", | ||
ArtifactMetadataPublisher: &packer_registry.Bucket{ | ||
Slug: "bucket-slug", | ||
Description: "Some description\n", | ||
Labels: map[string]string{"foo": "bar"}, | ||
Iteration: &packer_registry.Iteration{ | ||
Fingerprint: "ignored-fingerprint", | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
false, | ||
}, | ||
{"duplicate hcp_packer_registry blocks", | ||
defaultParser, | ||
parseTestArgs{"testdata/hcp_par/duplicate.pkr.hcl", nil, nil}, | ||
&PackerConfig{ | ||
CorePackerVersionString: lockedVersion, | ||
Basedir: filepath.Join("testdata", "hcp_par"), | ||
}, | ||
true, true, | ||
nil, | ||
false, | ||
}, | ||
{"empty hcp_packer_registry block", | ||
defaultParser, | ||
parseTestArgs{"testdata/hcp_par/empty.pkr.hcl", nil, nil}, | ||
&PackerConfig{ | ||
CorePackerVersionString: lockedVersion, | ||
Basedir: filepath.Join("testdata", "hcp_par"), | ||
Sources: map[SourceRef]SourceBlock{ | ||
refVBIsoUbuntu1204: {Type: "virtualbox-iso", Name: "ubuntu-1204"}, | ||
}, | ||
Builds: Builds{ | ||
&BuildBlock{ | ||
Name: "bucket-slug", | ||
HCPPackerRegistry: &HCPPackerRegistryBlock{}, | ||
Sources: []SourceUseBlock{ | ||
{ | ||
SourceRef: refVBIsoUbuntu1204, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
false, false, | ||
[]packersdk.Build{ | ||
&packer.CoreBuild{ | ||
BuildName: "bucket-slug", | ||
Type: "virtualbox-iso.ubuntu-1204", | ||
Prepared: true, | ||
Builder: &packer.RegistryBuilder{ | ||
Name: "virtualbox-iso.ubuntu-1204", | ||
Builder: emptyMockBuilder, | ||
ArtifactMetadataPublisher: &packer_registry.Bucket{ | ||
Slug: "bucket-slug", | ||
Iteration: &packer_registry.Iteration{ | ||
Fingerprint: "ignored-fingerprint", // this will be different everytime so it's ignored | ||
}, | ||
}, | ||
}, | ||
Provisioners: []packer.CoreBuildProvisioner{}, | ||
PostProcessors: [][]packer.CoreBuildPostProcessor{ | ||
{ | ||
{ | ||
PostProcessor: &packer.RegistryPostProcessor{ | ||
BuilderType: "virtualbox-iso.ubuntu-1204", | ||
ArtifactMetadataPublisher: &packer_registry.Bucket{ | ||
Slug: "bucket-slug", | ||
Iteration: &packer_registry.Iteration{ | ||
Fingerprint: "ignored-fingerprint", | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
false, | ||
}, | ||
{"invalid hcp_packer_registry config", | ||
defaultParser, | ||
parseTestArgs{"testdata/hcp_par/invalid.pkr.hcl", nil, nil}, | ||
&PackerConfig{ | ||
CorePackerVersionString: lockedVersion, | ||
Basedir: filepath.Join("testdata", "hcp_par"), | ||
}, | ||
true, true, | ||
nil, | ||
false, | ||
}, | ||
{"long hcp_packer_registry.description", | ||
defaultParser, | ||
parseTestArgs{"testdata/hcp_par/long-description.pkr.hcl", nil, nil}, | ||
&PackerConfig{ | ||
CorePackerVersionString: lockedVersion, | ||
Basedir: filepath.Join("testdata", "hcp_par"), | ||
}, | ||
true, true, | ||
nil, | ||
false, | ||
}, | ||
} | ||
testParse(t, tests) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters