configs: Show tailored message for optional attrs experiment

Since we've both concluded the module_variables_optional_attrs experiment
and made experiments available only in alpha releases in the same minor
release, we accidentally made the more general message about experiments
not being available mask the specific message about the experiment being
concluded.

In order to give better feedback to those who were participating in the
experiment in earlier Terraform releases, we'll retain a minimal exception
to our checks to allow the "experiment has concluded" error message to
shine through if and only if that is the only selected experiment.
This commit is contained in:
Martin Atkins 2022-07-01 08:55:54 -07:00
parent 7b19acb7eb
commit b88e29e473
2 changed files with 29 additions and 1 deletions

View File

@ -84,6 +84,25 @@ func sniffActiveExperiments(body hcl.Body, allowed bool) (experiments.Set, hcl.D
}
exps, expDiags := decodeExperimentsAttr(attr)
// Because we concluded this particular experiment in the same
// release as we made experiments alpha-releases-only, we need to
// treat it as special to avoid masking the "experiment has concluded"
// error with the more general "experiments are not available at all"
// error. Note that this experiment is marked as concluded so this
// only "allows" showing the different error message that it is
// concluded, and does not allow actually using the experiment outside
// of an alpha.
// NOTE: We should be able to remove this special exception a release
// or two after v1.3 when folks have had a chance to notice that the
// experiment has concluded and update their modules accordingly.
// When we do so, we might also consider changing decodeExperimentsAttr
// to _not_ include concluded experiments in the returned set, since
// we're doing that right now only to make this condition work.
if exps.Has(experiments.ModuleVariableOptionalAttrs) && len(exps) == 1 {
allowed = true
}
if allowed {
diags = append(diags, expDiags...)
if !expDiags.HasErrors() {
@ -134,6 +153,15 @@ func decodeExperimentsAttr(attr *hcl.Attribute) (experiments.Set, hcl.Diagnostic
Subject: expr.Range().Ptr(),
})
case experiments.ConcludedError:
// As a special case we still include the optional attributes
// experiment if it's present, because our caller treats that
// as special. See the comment in sniffActiveExperiments for
// more information, and remove this special case here one the
// special case up there is also removed.
if kw == "module_variable_optional_attrs" {
ret.Add(experiments.ModuleVariableOptionalAttrs)
}
diags = diags.Append(&hcl.Diagnostic{
Severity: hcl.DiagError,
Summary: "Experiment has concluded",

View File

@ -27,7 +27,7 @@ func init() {
registerConcludedExperiment(SuppressProviderSensitiveAttrs, "Provider-defined sensitive attributes are now redacted by default, without enabling an experiment.")
registerConcludedExperiment(ConfigDrivenMove, "Declarations of moved resource instances using \"moved\" blocks can now be used by default, without enabling an experiment.")
registerConcludedExperiment(PreconditionsPostconditions, "Condition blocks can now be used by default, without enabling an experiment.")
registerConcludedExperiment(ModuleVariableOptionalAttrs, "Optional object attributes in module variable type constraints can now be used by default, without enabling an experiment.")
registerConcludedExperiment(ModuleVariableOptionalAttrs, "The final feature corresponding to this experiment differs from the experimental form and is available in the Terraform language from Terraform v1.3.0 onwards.")
}
// GetCurrent takes an experiment name and returns the experiment value