Autoload only .auto.tfvars files
This commit is contained in:
parent
006744bfe0
commit
8d98fdecac
|
@ -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.
|
||||
|
||||
|
||||
`
|
||||
|
|
|
@ -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.
|
||||
|
||||
|
||||
`
|
||||
|
|
|
@ -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.
|
||||
|
||||
|
||||
`
|
||||
|
|
|
@ -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")
|
||||
}
|
||||
|
|
|
@ -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])
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -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.
|
||||
The `variables.tf` file contains all of the input parameters that the user can specify when deploying this Terraform template.
|
||||
|
|
|
@ -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)
|
||||
![graph](/examples/azure-cdn-with-storage-account/graph.png)
|
||||
|
|
|
@ -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)
|
||||
![graph](/examples/azure-encrypt-running-linux-vm/graph.png)
|
||||
|
|
|
@ -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)
|
||||
![graph](/examples/azure-search-create/graph.png)
|
||||
|
|
|
@ -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)
|
||||
![graph](/examples/azure-servicebus-create-topic-and-subscription/graph.png)
|
||||
|
|
|
@ -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.
|
||||
|
||||
|
|
|
@ -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)
|
||||
![graph](/examples/azure-sql-database/graph.png)
|
||||
|
|
|
@ -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.
|
||||
|
||||
|
|
|
@ -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)
|
||||
![graph](/examples/azure-vm-from-user-image/graph.png)
|
||||
|
|
|
@ -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)
|
||||
![graph](/examples/azure-vm-simple-linux-managed-disk/graph.png)
|
||||
|
|
|
@ -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)
|
||||
![graph](/examples/azure-vm-specialized-vhd-existing-vnet/graph.png)
|
||||
|
|
|
@ -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)
|
||||
![`terraform graph`](/examples/azure-vmss-ubuntu/graph.png)
|
||||
|
|
|
@ -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)
|
||||
![`terraform graph`](/examples/azure-vnet-to-vnet-peering/graph.png)
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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.
|
||||
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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`
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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.
|
||||
|
|
Loading…
Reference in New Issue