Do not read temporary editor files, fixes #548
This fixes a bug where Terraform would error with the following: ``` Error loading config: Error reading /Users/rhenrichs/work/example/.#example.tf: open /Users/rhenrichs/work/example/.#example.tf: no such file or directory ``` The solution implemented here ignores the common emacs and vim temporary file formats. Note: the potential danger with merging this is that Terraform could quickly have requests to ignore other file formats.
This commit is contained in:
parent
f1cb297c59
commit
b40b7ce01a
|
@ -162,7 +162,7 @@ func dirFiles(dir string) ([]string, []string, error) {
|
|||
// Only care about files that are valid to load
|
||||
name := fi.Name()
|
||||
extValue := ext(name)
|
||||
if extValue == "" {
|
||||
if extValue == "" || isTemporaryFile(name) {
|
||||
continue
|
||||
}
|
||||
|
||||
|
@ -182,3 +182,12 @@ func dirFiles(dir string) ([]string, []string, error) {
|
|||
|
||||
return files, overrides, nil
|
||||
}
|
||||
|
||||
// isTemporaryFile returns true or false depending on whether the
|
||||
// provided file name is a temporary file for the following editors:
|
||||
// emacs or vim.
|
||||
func isTemporaryFile(name string) bool {
|
||||
return strings.HasSuffix(name, "~") || // vim
|
||||
strings.HasPrefix(name, ".#") || // emacs
|
||||
(strings.HasPrefix(name, "#") && strings.HasSuffix(name, "#")) // emacs
|
||||
}
|
||||
|
|
|
@ -383,6 +383,13 @@ func TestLoad_createBeforeDestroy(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestLoad_temporary_files(t *testing.T) {
|
||||
_, err := LoadDir(filepath.Join(fixtureDir, "dir-temporary-files"))
|
||||
if err == nil {
|
||||
t.Fatalf("Expected to see an error stating no config files found")
|
||||
}
|
||||
}
|
||||
|
||||
const basicOutputsStr = `
|
||||
web_ip
|
||||
vars
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
provider "do" {
|
||||
api_key = "${var.foo}"
|
||||
}
|
||||
|
||||
resource "aws_security_group" "firewall" {
|
||||
count = 5
|
||||
}
|
||||
|
||||
resource aws_instance "web" {
|
||||
ami = "${var.foo}"
|
||||
security_groups = [
|
||||
"foo",
|
||||
"${aws_security_group.firewall.foo}"
|
||||
]
|
||||
|
||||
network_interface {
|
||||
device_index = 0
|
||||
description = "Main network interface"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
variable "foo" {
|
||||
default = "bar"
|
||||
description = "bar"
|
||||
}
|
||||
|
||||
provider "aws" {
|
||||
access_key = "foo"
|
||||
secret_key = "bar"
|
||||
}
|
||||
|
||||
resource "aws_instance" "db" {
|
||||
security_groups = "${aws_security_group.firewall.*.id}"
|
||||
}
|
||||
|
||||
output "web_ip" {
|
||||
value = "${aws_instance.web.private_ip}"
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
variable "foo" {
|
||||
default = "bar"
|
||||
description = "bar"
|
||||
}
|
||||
|
||||
provider "aws" {
|
||||
access_key = "foo"
|
||||
secret_key = "bar"
|
||||
}
|
||||
|
||||
resource "aws_instance" "db" {
|
||||
security_groups = "${aws_security_group.firewall.*.id}"
|
||||
}
|
||||
|
||||
output "web_ip" {
|
||||
value = "${aws_instance.web.private_ip}"
|
||||
}
|
Loading…
Reference in New Issue