mirror of
https://github.com/hashicorp/packer.git
synced 2026-09-18 22:11:39 -04:00
hcl2template: don't error on empty bucket slug
When a user defines a `hcp_packer_registry` block in their `build` without a `bucket_name`, but they define it in their environment, Packer should not report the bucket_name being wrong.
This commit is contained in:
@@ -0,0 +1,11 @@
|
||||
source "null" "test" {
|
||||
communicator = "none"
|
||||
}
|
||||
|
||||
build {
|
||||
name = "bucket-slug"
|
||||
hcp_packer_registry {
|
||||
}
|
||||
|
||||
sources = ["null.test"]
|
||||
}
|
||||
@@ -54,7 +54,12 @@ func (p *Parser) decodeHCPRegistry(block *hcl.Block, cfg *PackerConfig) (*HCPPac
|
||||
return nil, diags
|
||||
}
|
||||
|
||||
if !bucketNameRegexp.MatchString(b.Slug) {
|
||||
// No need to check the bucket name here if it's empty, since it can
|
||||
// be set through the `HCP_PACKER_BUCKET_NAME` environment var.
|
||||
//
|
||||
// If both are unset, creating the build on HCP Packer will fail, and
|
||||
// so will the packer build command.
|
||||
if b.Slug != "" && !bucketNameRegexp.MatchString(b.Slug) {
|
||||
diags = diags.Append(&hcl.Diagnostic{
|
||||
Severity: hcl.DiagError,
|
||||
Summary: fmt.Sprintf("%s.bucket_name can only contain between 3 and 36 ASCII letters, numbers and hyphens", buildHCPPackerRegistryLabel),
|
||||
|
||||
@@ -20,6 +20,47 @@ func Test_ParseHCPPackerRegistryBlock(t *testing.T) {
|
||||
defaultParser := getBasicParser()
|
||||
|
||||
tests := []parseTest{
|
||||
{"bucket_name left empty",
|
||||
defaultParser,
|
||||
parseTestArgs{"testdata/hcp_par/empty_bucket.pkr.hcl", nil, nil},
|
||||
&PackerConfig{
|
||||
CorePackerVersionString: lockedVersion,
|
||||
Basedir: filepath.Join("testdata", "hcp_par"),
|
||||
Sources: map[SourceRef]SourceBlock{
|
||||
refNull: {
|
||||
Type: "null",
|
||||
Name: "test",
|
||||
block: &hcl.Block{
|
||||
Type: "source",
|
||||
},
|
||||
},
|
||||
},
|
||||
Builds: Builds{
|
||||
{
|
||||
Name: "bucket-slug",
|
||||
HCPPackerRegistry: &HCPPackerRegistryBlock{Slug: ""},
|
||||
Sources: []SourceUseBlock{
|
||||
{
|
||||
SourceRef: refNull,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
false, false,
|
||||
[]packersdk.Build{
|
||||
&packer.CoreBuild{
|
||||
BuildName: "bucket-slug",
|
||||
Type: "null.test",
|
||||
Builder: &null.Builder{},
|
||||
Provisioners: []packer.CoreBuildProvisioner{},
|
||||
PostProcessors: [][]packer.CoreBuildPostProcessor{},
|
||||
Prepared: true,
|
||||
BuilderType: "null",
|
||||
},
|
||||
},
|
||||
false,
|
||||
},
|
||||
{"bucket_name as variable",
|
||||
defaultParser,
|
||||
parseTestArgs{"testdata/hcp_par/variable-for-bucket_name.pkr.hcl", nil, nil},
|
||||
|
||||
Reference in New Issue
Block a user