mirror of
https://github.com/opentofu/opentofu.git
synced 2025-01-13 09:32:24 -06:00
terraform: warn if the name has special characters
This commit is contained in:
parent
50e5eacc15
commit
36f4a644b6
@ -1049,6 +1049,16 @@ func (c *walkContext) validateWalkFn() depgraph.WalkFunc {
|
||||
return nil
|
||||
}
|
||||
|
||||
// If the resouce name doesn't match the name regular
|
||||
// expression, show a warning.
|
||||
if !config.NameRegexp.Match([]byte(rn.Config.Name)) {
|
||||
l.Lock()
|
||||
meta.Warns = append(meta.Warns, fmt.Sprintf(
|
||||
"'%s' warning: name can't contain special characters",
|
||||
rn.Resource.Id))
|
||||
l.Unlock()
|
||||
}
|
||||
|
||||
log.Printf("[INFO] Validating resource: %s", rn.Resource.Id)
|
||||
ws, es := rn.Resource.Provider.ValidateResource(
|
||||
rn.Resource.Info.Type, rn.Resource.Config)
|
||||
|
@ -312,6 +312,25 @@ func TestContextValidate_resourceConfig_good(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestContextValidate_resourceNameSymbol(t *testing.T) {
|
||||
p := testProvider("aws")
|
||||
m := testModule(t, "validate-resource-name-symbol")
|
||||
c := testContext(t, &ContextOpts{
|
||||
Module: m,
|
||||
Providers: map[string]ResourceProviderFactory{
|
||||
"aws": testProviderFuncFixed(p),
|
||||
},
|
||||
})
|
||||
|
||||
w, e := c.Validate()
|
||||
if len(w) == 0 {
|
||||
t.Fatalf("bad: %#v", w)
|
||||
}
|
||||
if len(e) > 0 {
|
||||
t.Fatalf("bad: %#v", e)
|
||||
}
|
||||
}
|
||||
|
||||
func TestContextValidate_requiredVar(t *testing.T) {
|
||||
m := testModule(t, "validate-required-var")
|
||||
c := testContext(t, &ContextOpts{
|
||||
|
@ -0,0 +1,3 @@
|
||||
resource "aws_instance" "foo bar" {
|
||||
num = "2"
|
||||
}
|
Loading…
Reference in New Issue
Block a user