diff --git a/command/apply.go b/command/apply.go index 3f61243b7c..94f7d129c6 100644 --- a/command/apply.go +++ b/command/apply.go @@ -296,8 +296,8 @@ Options: flag can be set multiple times. -var-file=foo Set variables in the Terraform configuration from - a file. If "terraform.tfvars" is present, it will be - automatically loaded if this flag is not specified. + a file. If "terraform.tfvars" or any ".auto.tfvars" + files are present, they will be automatically loaded. ` @@ -345,8 +345,8 @@ Options: flag can be set multiple times. -var-file=foo Set variables in the Terraform configuration from - a file. If "terraform.tfvars" is present, it will be - automatically loaded if this flag is not specified. + a file. If "terraform.tfvars" or any ".auto.tfvars" + files are present, they will be automatically loaded. ` diff --git a/command/console.go b/command/console.go index b5c37861c8..8235583112 100644 --- a/command/console.go +++ b/command/console.go @@ -146,8 +146,8 @@ Options: flag can be set multiple times. -var-file=foo Set variables in the Terraform configuration from - a file. If "terraform.tfvars" is present, it will be - automatically loaded if this flag is not specified. + a file. If "terraform.tfvars" or any ".auto.tfvars" + files are present, they will be automatically loaded. ` diff --git a/command/import.go b/command/import.go index 46728fdb9e..b1cc623e44 100644 --- a/command/import.go +++ b/command/import.go @@ -243,8 +243,8 @@ Options: with the "-config" flag. -var-file=foo Set variables in the Terraform configuration from - a file. If "terraform.tfvars" is present, it will be - automatically loaded if this flag is not specified. + a file. If "terraform.tfvars" or any ".auto.tfvars" + files are present, they will be automatically loaded. ` diff --git a/command/meta.go b/command/meta.go index be57951ef0..25d36a05ee 100644 --- a/command/meta.go +++ b/command/meta.go @@ -400,8 +400,19 @@ func (m *Meta) process(args []string, vars bool) ([]string, error) { return nil, err } - err = nil var preArgs []string + + if _, err = os.Stat(DefaultVarsFilename); err == nil { + m.autoKey = "var-file-default" + preArgs = append(preArgs, "-"+m.autoKey, DefaultVarsFilename) + } + + if _, err = os.Stat(DefaultVarsFilename + ".json"); err == nil { + m.autoKey = "var-file-default" + preArgs = append(preArgs, "-"+m.autoKey, DefaultVarsFilename+".json") + } + + err = nil for err != io.EOF { var fis []os.FileInfo fis, err = f.Readdir(128) @@ -412,7 +423,7 @@ func (m *Meta) process(args []string, vars bool) ([]string, error) { for _, fi := range fis { name := fi.Name() // Ignore directories, non-var-files, and ignored files - if fi.IsDir() || !isVarFile(name) || config.IsIgnoredFile(name) { + if fi.IsDir() || !isAutoVarFile(name) || config.IsIgnoredFile(name) { continue } @@ -570,8 +581,8 @@ func (m *Meta) SetWorkspace(name string) error { return nil } -// isVarFile determines if the file ends with .tfvars or .tfvars.json -func isVarFile(path string) bool { - return strings.HasSuffix(path, ".tfvars") || - strings.HasSuffix(path, ".tfvars.json") +// isAutoVarFile determines if the file ends with .auto.tfvars or .auto.tfvars.json +func isAutoVarFile(path string) bool { + return strings.HasSuffix(path, ".auto.tfvars") || + strings.HasSuffix(path, ".auto.tfvars.json") } diff --git a/command/meta_test.go b/command/meta_test.go index 77f78ebee9..ca53d13b82 100644 --- a/command/meta_test.go +++ b/command/meta_test.go @@ -339,17 +339,25 @@ func TestMeta_process(t *testing.T) { defer os.Chdir(cwd) // Create two vars files - file1 := "file1.tfvars" + defaultVarsfile := "terraform.tfvars" err = ioutil.WriteFile( - filepath.Join(d, file1), + filepath.Join(d, defaultVarsfile), []byte(""), 0644) if err != nil { t.Fatalf("err: %s", err) } - file2 := "file2.tfvars" + fileFirstAlphabetical := "a-file.auto.tfvars" err = ioutil.WriteFile( - filepath.Join(d, file2), + filepath.Join(d, fileFirstAlphabetical), + []byte(""), + 0644) + if err != nil { + t.Fatalf("err: %s", err) + } + fileLastAlphabetical := "z-file.auto.tfvars" + err = ioutil.WriteFile( + filepath.Join(d, fileLastAlphabetical), []byte(""), 0644) if err != nil { @@ -366,13 +374,19 @@ func TestMeta_process(t *testing.T) { if args[0] != "-var-file-default" { t.Fatalf("expected %q, got %q", "-var-file-default", args[0]) } - if args[1] != file1 { - t.Fatalf("expected %q, got %q", file1, args[1]) + if args[1] != defaultVarsfile { + t.Fatalf("expected %q, got %q", defaultVarsfile, args[3]) } if args[2] != "-var-file-default" { t.Fatalf("expected %q, got %q", "-var-file-default", args[0]) } - if args[3] != file2 { - t.Fatalf("expected %q, got %q", file2, args[3]) + if args[3] != fileFirstAlphabetical { + t.Fatalf("expected %q, got %q", fileFirstAlphabetical, args[1]) + } + if args[4] != "-var-file-default" { + t.Fatalf("expected %q, got %q", "-var-file-default", args[0]) + } + if args[5] != fileLastAlphabetical { + t.Fatalf("expected %q, got %q", fileLastAlphabetical, args[3]) } } diff --git a/command/plan.go b/command/plan.go index 8e27ff9236..f353651977 100644 --- a/command/plan.go +++ b/command/plan.go @@ -186,8 +186,8 @@ Options: flag can be set multiple times. -var-file=foo Set variables in the Terraform configuration from - a file. If "terraform.tfvars" is present, it will be - automatically loaded if this flag is not specified. + a file. If "terraform.tfvars" or any ".auto.tfvars" + files are present, they will be automatically loaded. ` return strings.TrimSpace(helpText) } diff --git a/command/push.go b/command/push.go index 79ae613b4b..bad5a7ac4e 100644 --- a/command/push.go +++ b/command/push.go @@ -381,8 +381,8 @@ Options: flag can be set multiple times. -var-file=foo Set variables in the Terraform configuration from - a file. If "terraform.tfvars" is present, it will be - automatically loaded if this flag is not specified. + a file. If "terraform.tfvars" or any ".auto.tfvars" + files are present, they will be automatically loaded. -vcs=true If true (default), push will upload only files committed to your VCS, if detected. diff --git a/command/refresh.go b/command/refresh.go index e90279fdc0..1949b54fe4 100644 --- a/command/refresh.go +++ b/command/refresh.go @@ -133,8 +133,8 @@ Options: flag can be set multiple times. -var-file=foo Set variables in the Terraform configuration from - a file. If "terraform.tfvars" is present, it will be - automatically loaded if this flag is not specified. + a file. If "terraform.tfvars" or any ".auto.tfvars" + files are present, they will be automatically loaded. ` return strings.TrimSpace(helpText) diff --git a/contrib/zsh-completion/_terraform b/contrib/zsh-completion/_terraform index 9f11933d8d..a4c356c0bc 100644 --- a/contrib/zsh-completion/_terraform +++ b/contrib/zsh-completion/_terraform @@ -27,7 +27,7 @@ __apply() { '-state=[(path) Path to read and save state (unless state-out is specified). Defaults to "terraform.tfstate".]' \ '-state-out=[(path) Path to write state to that is different than "-state". This can be used to preserve the old state.]' \ '-var[("foo=bar") Set a variable in the Terraform configuration. This flag can be set multiple times.]' \ - '-var-file=[(path) Set variables in the Terraform configuration from a file. If "terraform.tfvars" is present, it will be automatically loaded if this flag is not specified.]' + '-var-file=[(path) Set variables in the Terraform configuration from a file. If "terraform.tfvars" or any ".auto.tfvars" files are present, they will be automatically loaded.]' } __destroy() { @@ -39,7 +39,7 @@ __destroy() { '-state=[Path to read and save state (unless state-out is specified). Defaults to "terraform.tfstate".]' \ '-state-out=[Path to write state to that is different than "-state". This can be used to preserve the old state.]' \ '-var[("foo=bar") Set a variable in the Terraform configuration. This flag can be set multiple times.]' \ - '-var-file=[(path) Set variables in the Terraform configuration from a file. If "terraform.tfvars" is present, it will be automatically loaded if this flag is not specified.]' + '-var-file=[(path) Set variables in the Terraform configuration from a file. If "terraform.tfvars" or any ".auto.tfvars" files are present, they will be automatically loaded.]' } __get() { @@ -77,7 +77,7 @@ __plan() { '-refresh=[(true) Update state prior to checking for differences.]' \ '-state=[(statefile) Path to a Terraform state file to use to look up Terraform-managed resources. By default it will use the state "terraform.tfstate" if it exists.]' \ '-var[("foo=bar") Set a variable in the Terraform configuration. This flag can be set multiple times.]' \ - '-var-file=[(path) Set variables in the Terraform configuration from a file. If "terraform.tfvars" is present, it will be automatically loaded if this flag is not specified.]' + '-var-file=[(path) Set variables in the Terraform configuration from a file. If "terraform.tfvars" or any ".auto.tfvars" files are present, they will be automatically loaded.]' } __push() { @@ -93,7 +93,7 @@ __refresh() { '-state=[(path) Path to read and save state (unless state-out is specified). Defaults to "terraform.tfstate".]' \ '-state-out=[(path) Path to write state to that is different than "-state". This can be used to preserve the old state.]' \ '-var[("foo=bar") Set a variable in the Terraform configuration. This flag can be set multiple times.]' \ - '-var-file=[(path) Set variables in the Terraform configuration from a file. If "terraform.tfvars" is present, it will be automatically loaded if this flag is not specified.]' + '-var-file=[(path) Set variables in the Terraform configuration from a file. If "terraform.tfvars" or any ".auto.tfvars" files are present, they will be automatically loaded.]' } __taint() { diff --git a/examples/azure-2-vms-loadbalancer-lbrules/README.md b/examples/azure-2-vms-loadbalancer-lbrules/README.md index a6f2bb3345..5730f2ad95 100644 --- a/examples/azure-2-vms-loadbalancer-lbrules/README.md +++ b/examples/azure-2-vms-loadbalancer-lbrules/README.md @@ -14,9 +14,9 @@ This data is outputted when `terraform apply` is called, and can be queried usin Azure requires that an application is added to Azure Active Directory to generate the `client_id`, `client_secret`, and `tenant_id` needed by Terraform (`subscription_id` can be recovered from your Azure account details). Please go [here](https://www.terraform.io/docs/providers/azurerm/) for full instructions on how to create this to populate your `provider.tf` file. ## terraform.tfvars -If a `terraform.tfvars` file is present in the current directory, Terraform automatically loads it to populate variables. We don't recommend saving usernames and password to version control, but you can create a local secret variables file and use `-var-file` to load it. +If a `terraform.tfvars` or any `.auto.tfvars` files are present in the current directory, Terraform automatically loads them to populate variables. We don't recommend saving usernames and password to version control, but you can create a local secret variables file and use the `-var-file` flag or the `.auto.tfvars` extension to load it. If you are committing this template to source control, please insure that you add this file to your .gitignore file. ## variables.tf -The `variables.tf` file contains all of the input parameters that the user can specify when deploying this Terraform template. \ No newline at end of file +The `variables.tf` file contains all of the input parameters that the user can specify when deploying this Terraform template. diff --git a/examples/azure-cdn-with-storage-account/README.md b/examples/azure-cdn-with-storage-account/README.md index 53f83df743..047ca51513 100644 --- a/examples/azure-cdn-with-storage-account/README.md +++ b/examples/azure-cdn-with-storage-account/README.md @@ -20,11 +20,11 @@ This data is outputted when `terraform apply` is called, and can be queried usin Azure requires that an application is added to Azure Active Directory to generate the `client_id`, `client_secret`, and `tenant_id` needed by Terraform (`subscription_id` can be recovered from your Azure account details). Please go [here](https://www.terraform.io/docs/providers/azurerm/) for full instructions on how to create this to populate your `provider.tf` file. ## terraform.tfvars -If a `terraform.tfvars` file is present in the current directory, Terraform automatically loads it to populate variables. We don't recommend saving usernames and password to version control, but you can create a local secret variables file and use `-var-file` to load it. +If a `terraform.tfvars` or any `.auto.tfvars` files are present in the current directory, Terraform automatically loads them to populate variables. We don't recommend saving usernames and password to version control, but you can create a local secret variables file and use the `-var-file` flag or the `.auto.tfvars` extension to load it. If you are committing this template to source control, please insure that you add this file to your `.gitignore` file. ## variables.tf The `variables.tf` file contains all of the input parameters that the user can specify when deploying this Terraform template. -![graph](/examples/azure-cdn-with-storage-account/graph.png) \ No newline at end of file +![graph](/examples/azure-cdn-with-storage-account/graph.png) diff --git a/examples/azure-encrypt-running-linux-vm/README.md b/examples/azure-encrypt-running-linux-vm/README.md index 9ef27d9ee1..85ee3e0f75 100644 --- a/examples/azure-encrypt-running-linux-vm/README.md +++ b/examples/azure-encrypt-running-linux-vm/README.md @@ -34,11 +34,11 @@ You may leave the provider block in the `main.tf`, as it is in this template, or Azure requires that an application is added to Azure Active Directory to generate the `client_id`, `client_secret`, and `tenant_id` needed by Terraform (`subscription_id` can be recovered from your Azure account details). Please go [here](https://www.terraform.io/docs/providers/azurerm/) for full instructions on how to create this to populate your `provider.tf` file. ## terraform.tfvars -If a `terraform.tfvars` file is present in the current directory, Terraform automatically loads it to populate variables. We don't recommend saving usernames and password to version control, but you can create a local secret variables file and use `-var-file` to load it. +If a `terraform.tfvars` or any `.auto.tfvars` files are present in the current directory, Terraform automatically loads them to populate variables. We don't recommend saving usernames and password to version control, but you can create a local secret variables file and use the `-var-file` flag or the `.auto.tfvars` extension to load it. If you are committing this template to source control, please insure that you add this file to your .gitignore file. ## variables.tf The `variables.tf` file contains all of the input parameters that the user can specify when deploying this Terraform template. -![graph](/examples/azure-encrypt-running-linux-vm/graph.png) \ No newline at end of file +![graph](/examples/azure-encrypt-running-linux-vm/graph.png) diff --git a/examples/azure-search-create/README.md b/examples/azure-search-create/README.md index 268034a176..e23dc726d8 100644 --- a/examples/azure-search-create/README.md +++ b/examples/azure-search-create/README.md @@ -18,11 +18,11 @@ You may leave the provider block in the `main.tf`, as it is in this template, or Azure requires that an application is added to Azure Active Directory to generate the `client_id`, `client_secret`, and `tenant_id` needed by Terraform (`subscription_id` can be recovered from your Azure account details). Please go [here](https://www.terraform.io/docs/providers/azurerm/) for full instructions on how to create this to populate your `provider.tf` file. ## terraform.tfvars -If a `terraform.tfvars` file is present in the current directory, Terraform automatically loads it to populate variables. We don't recommend saving usernames and password to version control, but you can create a local secret variables file and use `-var-file` to load it. +If a `terraform.tfvars` or any `.auto.tfvars` files are present in the current directory, Terraform automatically loads them to populate variables. We don't recommend saving usernames and password to version control, but you can create a local secret variables file and use the `-var-file` flag or the `.auto.tfvars` extension to load it. If you are committing this template to source control, please insure that you add this file to your `.gitignore` file. ## variables.tf The `variables.tf` file contains all of the input parameters that the user can specify when deploying this Terraform template. -![graph](/examples/azure-search-create/graph.png) \ No newline at end of file +![graph](/examples/azure-search-create/graph.png) diff --git a/examples/azure-servicebus-create-topic-and-subscription/README.md b/examples/azure-servicebus-create-topic-and-subscription/README.md index 6234b7ccf2..99381dd202 100644 --- a/examples/azure-servicebus-create-topic-and-subscription/README.md +++ b/examples/azure-servicebus-create-topic-and-subscription/README.md @@ -12,11 +12,11 @@ This data is outputted when `terraform apply` is called, and can be queried usin Azure requires that an application is added to Azure Active Directory to generate the `client_id`, `client_secret`, and `tenant_id` needed by Terraform (`subscription_id` can be recovered from your Azure account details). Please go [here](https://www.terraform.io/docs/providers/azurerm/) for full instructions on how to create this to populate your `provider.tf` file. ## terraform.tfvars -If a `terraform.tfvars` file is present in the current directory, Terraform automatically loads it to populate variables. We don't recommend saving usernames and password to version control, but you can create a local secret variables file and use `-var-file` to load it. +If a `terraform.tfvars` or any `.auto.tfvars` files are present in the current directory, Terraform automatically loads them to populate variables. We don't recommend saving usernames and password to version control, but you can create a local secret variables file and use the `-var-file` flag or the `.auto.tfvars` extension to load it. If you are committing this template to source control, please insure that you add this file to your `.gitignore` file. ## variables.tf The `variables.tf` file contains all of the input parameters that the user can specify when deploying this Terraform template. -![graph](/examples/azure-servicebus-create-topic-and-subscription/graph.png) \ No newline at end of file +![graph](/examples/azure-servicebus-create-topic-and-subscription/graph.png) diff --git a/examples/azure-spark-and-cassandra-on-centos/README.md b/examples/azure-spark-and-cassandra-on-centos/README.md index 9d8492b08b..52d8494938 100644 --- a/examples/azure-spark-and-cassandra-on-centos/README.md +++ b/examples/azure-spark-and-cassandra-on-centos/README.md @@ -52,7 +52,7 @@ This data is outputted when `terraform apply` is called, and can be queried usin Azure requires that an application is added to Azure Active Directory to generate the `client_id`, `client_secret`, and `tenant_id` needed by Terraform (`subscription_id` can be recovered from your Azure account details). Please go [here](https://www.terraform.io/docs/providers/azurerm/) for full instructions on how to create this to populate your `provider.tf` file. ## terraform.tfvars -If a `terraform.tfvars` file is present in the current directory, Terraform automatically loads it to populate variables. We don't recommend saving usernames and password to version control, but you can create a local secret variables file and use `-var-file` to load it. +If a `terraform.tfvars` or any `.auto.tfvars` files are present in the current directory, Terraform automatically loads them to populate variables. We don't recommend saving usernames and password to version control, but you can create a local secret variables file and use the `-var-file` flag or the `.auto.tfvars` extension to load it. If you are committing this template to source control, please insure that you add this file to your `.gitignore` file. diff --git a/examples/azure-sql-database/README.md b/examples/azure-sql-database/README.md index dd0890061d..8adfce392a 100644 --- a/examples/azure-sql-database/README.md +++ b/examples/azure-sql-database/README.md @@ -14,9 +14,9 @@ This data is outputted when `terraform apply` is called, and can be queried usin Azure requires that an application is added to Azure Active Directory to generate the `client_id`, `client_secret`, and `tenant_id` needed by Terraform (`subscription_id` can be recovered from your Azure account details). Please go [here](https://www.terraform.io/docs/providers/azurerm/) for full instructions on how to create this to populate your `provider.tf` file. ## terraform.tfvars -If a `terraform.tfvars` file is present in the current directory, Terraform automatically loads it to populate variables. We don't recommend saving usernames and password to version control, but you can create a local secret variables file and use `-var-file` to load it. +If a `terraform.tfvars` or any `.auto.tfvars` files are present in the current directory, Terraform automatically loads them to populate variables. We don't recommend saving usernames and password to version control, but you can create a local secret variables file and use the `-var-file` flag or the `.auto.tfvars` extension to load it. ## variables.tf The `variables.tf` file contains all of the input parameters that the user can specify when deploying this Terraform template. -![graph](/examples/azure-sql-database/graph.png) \ No newline at end of file +![graph](/examples/azure-sql-database/graph.png) diff --git a/examples/azure-traffic-manager-vm/README.md b/examples/azure-traffic-manager-vm/README.md index 5fcc99aae2..2ffbf0a02b 100644 --- a/examples/azure-traffic-manager-vm/README.md +++ b/examples/azure-traffic-manager-vm/README.md @@ -19,7 +19,7 @@ This data is outputted when `terraform apply` is called, and can be queried usin Azure requires that an application is added to Azure Active Directory to generate the `client_id`, `client_secret`, and `tenant_id` needed by Terraform (`subscription_id` can be recovered from your Azure account details). Please go [here](https://www.terraform.io/docs/providers/azurerm/) for full instructions on how to create this to populate your `provider.tf` file. ## terraform.tfvars -If a `terraform.tfvars` file is present in the current directory, Terraform automatically loads it to populate variables. We don't recommend saving usernames and password to version control, but you can create a local secret variables file and use `-var-file` to load it. +If a `terraform.tfvars` or any `.auto.tfvars` files are present in the current directory, Terraform automatically loads them to populate variables. We don't recommend saving usernames and password to version control, but you can create a local secret variables file and use the `-var-file` flag or the `.auto.tfvars` extension to load it. If you are committing this template to source control, please insure that you add this file to your `.gitignore` file. diff --git a/examples/azure-vm-from-user-image/README.md b/examples/azure-vm-from-user-image/README.md index c3ed92de1a..c332b52e73 100644 --- a/examples/azure-vm-from-user-image/README.md +++ b/examples/azure-vm-from-user-image/README.md @@ -16,11 +16,11 @@ This data is outputted when `terraform apply` is called, and can be queried usin Azure requires that an application is added to Azure Active Directory to generate the `client_id`, `client_secret`, and `tenant_id` needed by Terraform (`subscription_id` can be recovered from your Azure account details). Please go [here](https://www.terraform.io/docs/providers/azurerm/) for full instructions on how to create this to populate your `provider.tf` file. ## terraform.tfvars -If a `terraform.tfvars` file is present in the current directory, Terraform automatically loads it to populate variables. We don't recommend saving usernames and password to version control, but you can create a local secret variables file and use `-var-file` to load it. +If a `terraform.tfvars` or any `.auto.tfvars` files are present in the current directory, Terraform automatically loads them to populate variables. We don't recommend saving usernames and password to version control, but you can create a local secret variables file and use the `-var-file` flag or the `.auto.tfvars` extension to load it. If you are committing this template to source control, please insure that you add this file to your `.gitignore` file. ## variables.tf The `variables.tf` file contains all of the input parameters that the user can specify when deploying this Terraform template. -![graph](/examples/azure-vm-from-user-image/graph.png) \ No newline at end of file +![graph](/examples/azure-vm-from-user-image/graph.png) diff --git a/examples/azure-vm-simple-linux-managed-disk/README.md b/examples/azure-vm-simple-linux-managed-disk/README.md index 42201eb445..4a6b2ef9b2 100644 --- a/examples/azure-vm-simple-linux-managed-disk/README.md +++ b/examples/azure-vm-simple-linux-managed-disk/README.md @@ -14,9 +14,9 @@ This data is outputted when `terraform apply` is called, and can be queried usin Azure requires that an application is added to Azure Active Directory to generate the `client_id`, `client_secret`, and `tenant_id` needed by Terraform (`subscription_id` can be recovered from your Azure account details). Please go [here](https://www.terraform.io/docs/providers/azurerm/) for full instructions on how to create this to populate your `provider.tf` file. ## terraform.tfvars -If a `terraform.tfvars` file is present in the current directory, Terraform automatically loads it to populate variables. We don't recommend saving usernames and password to version control, but you can create a local secret variables file and use `-var-file` to load it. +If a `terraform.tfvars` or any `.auto.tfvars` files are present in the current directory, Terraform automatically loads them to populate variables. We don't recommend saving usernames and password to version control, but you can create a local secret variables file and use the `-var-file` flag or the `.auto.tfvars` extension to load it. ## variables.tf The `variables.tf` file contains all of the input parameters that the user can specify when deploying this Terraform template. -![graph](/examples/azure-vm-simple-linux-managed-disk/graph.png) \ No newline at end of file +![graph](/examples/azure-vm-simple-linux-managed-disk/graph.png) diff --git a/examples/azure-vm-specialized-vhd-existing-vnet/README.md b/examples/azure-vm-specialized-vhd-existing-vnet/README.md index 9219798466..3afc0f8471 100644 --- a/examples/azure-vm-specialized-vhd-existing-vnet/README.md +++ b/examples/azure-vm-specialized-vhd-existing-vnet/README.md @@ -27,9 +27,9 @@ This data is outputted when `terraform apply` is called, and can be queried usin Azure requires that an application is added to Azure Active Directory to generate the `client_id`, `client_secret`, and `tenant_id` needed by Terraform (`subscription_id` can be recovered from your Azure account details). Please go [here](https://www.terraform.io/docs/providers/azurerm/) for full instructions on how to create this to populate your `provider.tf` file. ## terraform.tfvars -If a `terraform.tfvars` file is present in the current directory, Terraform automatically loads it to populate variables. We don't recommend saving usernames and password to version control, but you can create a local secret variables file and use `-var-file` to load it. +If a `terraform.tfvars` or any `.auto.tfvars` files are present in the current directory, Terraform automatically loads them to populate variables. We don't recommend saving usernames and password to version control, but you can create a local secret variables file and use the `-var-file` flag or the `.auto.tfvars` extension to load it. ## variables.tf The `variables.tf` file contains all of the input parameters that the user can specify when deploying this Terraform template. -![graph](/examples/azure-vm-specialized-vhd-existing-vnet/graph.png) \ No newline at end of file +![graph](/examples/azure-vm-specialized-vhd-existing-vnet/graph.png) diff --git a/examples/azure-vmss-ubuntu/README.md b/examples/azure-vmss-ubuntu/README.md index 794e42cb2d..f6208df843 100644 --- a/examples/azure-vmss-ubuntu/README.md +++ b/examples/azure-vmss-ubuntu/README.md @@ -14,9 +14,9 @@ You may leave the provider block in the `main.tf`, as it is in this template, or Azure requires that an application is added to Azure Active Directory to generate the `client_id`, `client_secret`, and `tenant_id` needed by Terraform (`subscription_id` can be recovered from your Azure account details). Please go [here](https://www.terraform.io/docs/providers/azurerm/) for full instructions on how to create this to populate your `provider.tf` file. ## terraform.tfvars -If a `terraform.tfvars` file is present in the current directory, Terraform automatically loads it to populate variables. We don't recommend saving usernames and password to version control, but you can create a local secret variables file and use `-var-file` to load it. +If a `terraform.tfvars` or any `.auto.tfvars` files are present in the current directory, Terraform automatically loads them to populate variables. We don't recommend saving usernames and password to version control, but you can create a local secret variables file and use the `-var-file` flag or the `.auto.tfvars` extension to load it. ## variables.tf The `variables.tf` file contains all of the input parameters that the user can specify when deploying this Terraform template. -![`terraform graph`](/examples/azure-vmss-ubuntu/graph.png) \ No newline at end of file +![`terraform graph`](/examples/azure-vmss-ubuntu/graph.png) diff --git a/examples/azure-vnet-to-vnet-peering/README.md b/examples/azure-vnet-to-vnet-peering/README.md index cf6318bb91..36a90a46ff 100644 --- a/examples/azure-vnet-to-vnet-peering/README.md +++ b/examples/azure-vnet-to-vnet-peering/README.md @@ -14,11 +14,11 @@ You may leave the provider block in the `main.tf`, as it is in this template, or Azure requires that an application is added to Azure Active Directory to generate the `client_id`, `client_secret`, and `tenant_id` needed by Terraform (`subscription_id` can be recovered from your Azure account details). Please go [here](https://www.terraform.io/docs/providers/azurerm/) for full instructions on how to create this to populate your `provider.tf` file. ## terraform.tfvars -If a `terraform.tfvars` file is present in the current directory, Terraform automatically loads it to populate variables. We don't recommend saving usernames and password to version control, but you can create a local secret variables file and use `-var-file` to load it. +If a `terraform.tfvars` or any `.auto.tfvars` files are present in the current directory, Terraform automatically loads them to populate variables. We don't recommend saving usernames and password to version control, but you can create a local secret variables file and use the `-var-file` flag or the `.auto.tfvars` extension to load it. If you are committing this template to source control, please insure that you add this file to your `.gitignore` file. ## variables.tf The `variables.tf` file contains all of the input parameters that the user can specify when deploying this Terraform template. -![`terraform graph`](/examples/azure-vnet-to-vnet-peering/graph.png) \ No newline at end of file +![`terraform graph`](/examples/azure-vnet-to-vnet-peering/graph.png) diff --git a/examples/azure-vnet-two-subnets/README.md b/examples/azure-vnet-two-subnets/README.md index 17ecb58933..d8c36ea6cf 100644 --- a/examples/azure-vnet-two-subnets/README.md +++ b/examples/azure-vnet-two-subnets/README.md @@ -12,7 +12,7 @@ This data is outputted when `terraform apply` is called, and can be queried usin Azure requires that an application is added to Azure Active Directory to generate the `client_id`, `client_secret`, and `tenant_id` needed by Terraform (`subscription_id` can be recovered from your Azure account details). Please go [here](https://www.terraform.io/docs/providers/azurerm/) for full instructions on how to create this to populate your `provider.tf` file. ## terraform.tfvars -If a `terraform.tfvars` file is present in the current directory, Terraform automatically loads it to populate variables. We don't recommend saving usernames and password to version control, but you can create a local secret variables file and use `-var-file` to load it. +If a `terraform.tfvars` or any `.auto.tfvars` files are present in the current directory, Terraform automatically loads them to populate variables. We don't recommend saving usernames and password to version control, but you can create a local secret variables file and use the `-var-file` flag or the `.auto.tfvars` extension to load it. ## variables.tf The `variables.tf` file contains all of the input parameters that the user can specify when deploying this Terraform template. diff --git a/examples/azure-wordpress-mysql-replication/README.md b/examples/azure-wordpress-mysql-replication/README.md index 75ad2dcbc5..b080397bc6 100644 --- a/examples/azure-wordpress-mysql-replication/README.md +++ b/examples/azure-wordpress-mysql-replication/README.md @@ -33,7 +33,7 @@ You may leave the provider block in the `main.tf`, as it is in this template, or Azure requires that an application is added to Azure Active Directory to generate the `client_id`, `client_secret`, and `tenant_id` needed by Terraform (`subscription_id` can be recovered from your Azure account details). Please go [here](https://www.terraform.io/docs/providers/azurerm/) for full instructions on how to create this to populate your `provider.tf` file. ## terraform.tfvars -If a `terraform.tfvars` file is present in the current directory, Terraform automatically loads it to populate variables. We don't recommend saving usernames and password to version control, but you can create a local secret variables file and use `-var-file` to load it. +If a `terraform.tfvars` or any `.auto.tfvars` files are present in the current directory, Terraform automatically loads them to populate variables. We don't recommend saving usernames and password to version control, but you can create a local secret variables file and use the `-var-file` flag or the `.auto.tfvars` extension to load it. If you are committing this template to source control, please insure that you add this file to your `.gitignore` file. diff --git a/website/docs/commands/apply.html.markdown b/website/docs/commands/apply.html.markdown index ff5b9d1425..872771ad3e 100644 --- a/website/docs/commands/apply.html.markdown +++ b/website/docs/commands/apply.html.markdown @@ -67,8 +67,9 @@ The command-line flags are all optional. The list of available flags are: specified via this flag. * `-var-file=foo` - Set variables in the Terraform configuration from - a [variable file](/docs/configuration/variables.html#variable-files). If - any files matching "*.tfvars" are present, they will be automatically loaded - in alphabetical order. Any files specified by `-var-file` override any values - set automatically from files in the working directory. This flag can be used - multiple times. + a [variable file](/docs/configuration/variables.html#variable-files). If + a `terraform.tfvars` or any `.auto.tfvars` files are present in the current + directory, they will be automatically loaded. `terraform.tfvars` is loaded + first and the `.auto.tfvars` files after in alphabetical order. Any files + specified by `-var-file` override any values set automatically from files in + the working directory. This flag can be used multiple times. diff --git a/website/docs/commands/import.html.md b/website/docs/commands/import.html.md index 8c65a74952..4862f87ec3 100644 --- a/website/docs/commands/import.html.md +++ b/website/docs/commands/import.html.md @@ -66,11 +66,13 @@ The command-line flags are all optional. The list of available flags are: specified via this flag. This is only useful with the `-config` flag. * `-var-file=foo` - Set variables in the Terraform configuration from - a [variable file](/docs/configuration/variables.html#variable-files). If - any file matching "*.tfvars" are present, they will be automatically loaded - in alphabetical order. Any files specified by `-var-file` override any values - set automatically from files in the working directory. This flag can be used - multiple times. This is only useful with the `-config` flag. + a [variable file](/docs/configuration/variables.html#variable-files). If + a `terraform.tfvars` or any `.auto.tfvars` files are present in the current + directory, they will be automatically loaded. `terraform.tfvars` is loaded + first and the `.auto.tfvars` files after in alphabetical order. Any files + specified by `-var-file` override any values set automatically from files in + the working directory. This flag can be used multiple times. This is only + useful with the `-config` flag. ## Provider Configuration diff --git a/website/docs/commands/plan.html.markdown b/website/docs/commands/plan.html.markdown index 98f01cc03a..771d20292a 100644 --- a/website/docs/commands/plan.html.markdown +++ b/website/docs/commands/plan.html.markdown @@ -72,11 +72,12 @@ The command-line flags are all optional. The list of available flags are: specified via this flag. * `-var-file=foo` - Set variables in the Terraform configuration from - a [variable file](/docs/configuration/variables.html#variable-files). If - any files matching "*.tfvars" are present, they will be automatically loaded - in alphabetical order. Any files specified by `-var-file` override any values - set automatically from files in the working directory. This flag can be used - multiple times. + a [variable file](/docs/configuration/variables.html#variable-files). If + a `terraform.tfvars` or any `.auto.tfvars` files are present in the current + directory, they will be automatically loaded. `terraform.tfvars` is loaded + first and the `.auto.tfvars` files after in alphabetical order. Any files + specified by `-var-file` override any values set automatically from files in + the working directory. This flag can be used multiple times. ## Resource Targeting diff --git a/website/docs/commands/refresh.html.markdown b/website/docs/commands/refresh.html.markdown index bf92b69016..659bea3724 100644 --- a/website/docs/commands/refresh.html.markdown +++ b/website/docs/commands/refresh.html.markdown @@ -55,8 +55,9 @@ The command-line flags are all optional. The list of available flags are: specified via this flag. * `-var-file=foo` - Set variables in the Terraform configuration from - a [variable file](/docs/configuration/variables.html#variable-files). If - any files matching "*.tfvars" are present, they will be automatically loaded - in alphabetical order. Any files specified by `-var-file` override any values - set automatically from files in the working directory. This flag can be used - multiple times. + a [variable file](/docs/configuration/variables.html#variable-files). If + a `terraform.tfvars` or any `.auto.tfvars` files are present in the current + directory, they will be automatically loaded. `terraform.tfvars` is loaded + first and the `.auto.tfvars` files after in alphabetical order. Any files + specified by `-var-file` override any values set automatically from files in + the working directory. This flag can be used multiple times. diff --git a/website/docs/configuration/variables.html.md b/website/docs/configuration/variables.html.md index 5fbe02c703..109378541a 100644 --- a/website/docs/configuration/variables.html.md +++ b/website/docs/configuration/variables.html.md @@ -256,9 +256,10 @@ $ TF_VAR_somemap='{foo = "bar", baz = "qux"}' terraform plan Variables can be collected in files and passed all at once using the `-var-file=foo.tfvars` flag. -For all files which match `*.tfvars` present in the current directory, -Terraform automatically loads it to populate variables. If the file is located -somewhere else, you can pass the path to the file using the `-var-file` flag. +For all files which match `terraform.tfvars` or `*.auto.tfvars` present in the +current directory, Terraform automatically loads them to populate variables. If +the file is located somewhere else, you can pass the path to the file using the +`-var-file` flag. Variables files use HCL or JSON to define variable values. Strings, lists or maps may be set in the same manner as the default value in a `variable` block @@ -337,14 +338,10 @@ _bar.tfvars_ baz = "bar" ``` -When they are read directly from the working directory, the files are evaluated -in alphabetical order. The result will be that baz contains the value `foo` -because `foo.tfvars` has the last definition loaded. - -When they are passed manually in the following order: +When they are passed in the following order: ```shell -$ terraform apply -var-file=path/to/foo.tfvars -var-file=path/to/bar.tfvars +$ terraform apply -var-file=foo.tfvars -var-file=bar.tfvars ``` The result will be that `baz` will contain the value `bar` because `bar.tfvars` diff --git a/website/intro/getting-started/variables.html.md b/website/intro/getting-started/variables.html.md index e843e49cc2..451f9fa113 100644 --- a/website/intro/getting-started/variables.html.md +++ b/website/intro/getting-started/variables.html.md @@ -86,9 +86,9 @@ access_key = "foo" secret_key = "bar" ``` -If a `terraform.tfvars` file is present in the current directory, -Terraform automatically loads it to populate variables. If the file is -named something else, you can use the `-var-file` flag directly to +For all files which match `terraform.tfvars` or `*.auto.tfvars` present in the +current directory, Terraform automatically loads them to populate variables. If +the file is named something else, you can use the `-var-file` flag directly to specify a file. These files are the same syntax as Terraform configuration files. And like Terraform configuration files, these files can also be JSON. diff --git a/website/upgrade-guides/0-7.html.markdown b/website/upgrade-guides/0-7.html.markdown index 90faa40a8f..c6fb8a8495 100644 --- a/website/upgrade-guides/0-7.html.markdown +++ b/website/upgrade-guides/0-7.html.markdown @@ -233,4 +233,4 @@ This will give the map the effective value: } ``` -It's also possible to override the values in a variables file, either in any `*.tfvars` file or specified using the `-var-file` flag. +It's also possible to override the values in a variables file, either in any `terraform.tfvars` file, an `.auto.tfvars` file, or specified using the `-var-file` flag.