Variables Best Practices
1. Variables Best Practices
Now that you learned how variables can be used in your configuration, let’s explore some best practices for using them. First, only parameterize values that vary for each instance or environment. When deciding whether to expose a variable, ensure that you have a concrete use case for changing it. If there's only a small chance that a variable might be needed, don't expose it. Changing or adding a variable with a default value is backward-compatible, removing a variable is not. For root modules, provide values to variables by using a . tfvars variables file. Avoid alternating between var-files and command-line options. Command-line options are ephemeral and easy to forget, and they cannot be checked into source control. Default variable files are more predictable. Give variables descriptive names that are relevant to their usage or purpose. Variables representing numeric values—such as disk sizes or RAM size—must be named with units. Google Cloud APIs don't have standard units, so following this naming convention clears the expected input unit for configuration maintainers. To simplify conditional logic, give boolean variables positive names, for example, enable_external_access. Finally, variables must have descriptions. Descriptions are automatically included in documentation, and add additional context for new developers.2. Let's practice!
Create Your Free Account
or
By continuing, you accept our Terms of Use, our Privacy Policy and that your data is stored in the USA.