Skip to content

Commit 8234469

Browse files
authored
earlydecoder: Avoid producing diagnostics for unknown blocks (#238)
1 parent deddcbf commit 8234469

File tree

2 files changed

+29
-3
lines changed

2 files changed

+29
-3
lines changed

earlydecoder/backend.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,18 @@ func decodeBackendsBlock(block *hcl.Block) (backend.BackendData, hcl.Diagnostics
3232
}
3333

3434
func decodeCloudBlock(block *hcl.Block) (*backend.Cloud, hcl.Diagnostics) {
35-
attrs, diags := block.Body.JustAttributes()
35+
attrs, _ := block.Body.JustAttributes()
36+
// Ignore diagnostics which may complain about unknown blocks
3637

3738
// https://developer.hashicorp.com/terraform/language/settings/terraform-cloud#usage-example
3839
// Required for Terraform Enterprise
3940
// Defaults to app.terraform.io for Terraform Cloud
4041
if attr, ok := attrs["hostname"]; ok {
4142
val, vDiags := attr.Expr.Value(nil)
42-
diags = append(diags, vDiags...)
4343
if val.IsWhollyKnown() && val.Type() == cty.String {
4444
return &backend.Cloud{
4545
Hostname: val.AsString(),
46-
}, diags
46+
}, vDiags
4747
}
4848
}
4949

earlydecoder/decoder_test.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1046,6 +1046,32 @@ terraform {
10461046
},
10471047
nil,
10481048
},
1049+
{
1050+
"additional block",
1051+
`
1052+
terraform {
1053+
cloud {
1054+
hostname = "foo.com"
1055+
workspaces {
1056+
tags = ["app"]
1057+
}
1058+
}
1059+
}`,
1060+
&module.Meta{
1061+
Path: path,
1062+
Backend: nil,
1063+
Cloud: &backend.Cloud{
1064+
Hostname: "foo.com",
1065+
},
1066+
ProviderReferences: map[module.ProviderRef]tfaddr.Provider{},
1067+
ProviderRequirements: map[tfaddr.Provider]version.Constraints{},
1068+
Variables: map[string]module.Variable{},
1069+
Outputs: map[string]module.Output{},
1070+
Filenames: []string{"test.tf"},
1071+
ModuleCalls: map[string]module.DeclaredModuleCall{},
1072+
},
1073+
nil,
1074+
},
10491075
}
10501076

10511077
runTestCases(testCases, t, path)

0 commit comments

Comments
 (0)