terraform: warn if the name has special characters

This commit is contained in:
Mitchell Hashimoto 2014-10-08 15:59:50 -07:00
parent 50e5eacc15
commit 36f4a644b6
3 changed files with 32 additions and 0 deletions

View File

@ -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)

View File

@ -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{

View File

@ -0,0 +1,3 @@
resource "aws_instance" "foo bar" {
num = "2"
}