Create experiment for sensitive attribute

This commit is contained in:
Pam Selle 2020-09-10 10:08:04 -04:00
parent 843ed8911b
commit 02c1bddfe1
4 changed files with 21 additions and 5 deletions

View File

@ -138,6 +138,17 @@ func checkModuleExperiments(m *Module) hcl.Diagnostics {
} }
} }
*/ */
if !m.ActiveExperiments.Has(experiments.SensitiveVariables) {
for _, v := range m.Variables {
if v.Sensitive {
diags = diags.Append(&hcl.Diagnostic{
Severity: hcl.DiagError,
Summary: "Variable sensitivity is experimental",
Detail: "This feature is currently an opt-in experiment, subject to change in future releases based on feedback.\n\nActivate the feature for this module by adding sensitive_variables to the list of active experiments.",
Subject: v.DeclRange.Ptr(),
})
}
}
}
return diags return diags
} }

View File

@ -22,7 +22,3 @@ variable "cheeze_pizza" {
variable "π" { variable "π" {
default = 3.14159265359 default = 3.14159265359
} }
variable "sensitive-value" {
sensitive = true
}

View File

@ -0,0 +1,7 @@
terraform {
experiments = [sensitive_variables] # WARNING: Experimental feature "sensitive_variables" is active
}
variable "sensitive-value" {
sensitive = true
}

View File

@ -14,12 +14,14 @@ type Experiment string
// identifier so that it can be specified in configuration. // identifier so that it can be specified in configuration.
const ( const (
VariableValidation = Experiment("variable_validation") VariableValidation = Experiment("variable_validation")
SensitiveVariables = Experiment("sensitive_variables")
) )
func init() { func init() {
// Each experiment constant defined above must be registered here as either // Each experiment constant defined above must be registered here as either
// a current or a concluded experiment. // a current or a concluded experiment.
registerConcludedExperiment(VariableValidation, "Custom variable validation can now be used by default, without enabling an experiment.") registerConcludedExperiment(VariableValidation, "Custom variable validation can now be used by default, without enabling an experiment.")
registerCurrentExperiment(SensitiveVariables)
} }
// GetCurrent takes an experiment name and returns the experiment value // GetCurrent takes an experiment name and returns the experiment value