Upgrade TF to 0.15 and include the provider's configuration_aliases

This commit is contained in:
Peter Rifel 2021-09-16 23:58:48 -05:00
parent 7eaa647b2a
commit 0449d6e36f
No known key found for this signature in database
GPG Key ID: BC6469E5B16DB2B6
2 changed files with 16 additions and 3 deletions

View File

@ -92,6 +92,9 @@ For file assets, it means adding an explicit path as shown below:
# Required actions
* Terraform support now requires Terraform >=0.15.0.
Users on older versions must follow Terraform's recommended upgrade path of applying one minor version at a time prior to running `kops update cluster --target terraform`.
* The kOps Terraform support now renders managed files through the Terraform configuration instead
of writing them to S3 directly. If, after upgrading kOps and applying a new Terraform plan,
you subsequently downgrade to an earlier version of kOps, the generated plan will delete these

View File

@ -100,7 +100,7 @@ func (t *TerraformTarget) finishHCL2() error {
terraformBlock := rootBody.AppendNewBlock("terraform", []string{})
terraformBody := terraformBlock.Body()
terraformBody.SetAttributeValue("required_version", cty.StringVal(">= 0.12.26"))
terraformBody.SetAttributeValue("required_version", cty.StringVal(">= 0.15.0"))
requiredProvidersBlock := terraformBody.AppendNewBlock("required_providers", []string{})
requiredProvidersBody := requiredProvidersBlock.Body()
@ -111,9 +111,19 @@ func (t *TerraformTarget) finishHCL2() error {
"version": cty.StringVal(">= 2.19.0"),
})
} else if t.Cloud.ProviderID() == kops.CloudProviderAWS {
configurationAliases := []*terraformWriter.Literal{terraformWriter.LiteralTokens("aws", "files")}
aliasesType, err := gocty.ImpliedType(configurationAliases)
if err != nil {
return err
}
aliasesVal, err := gocty.ToCtyValue(configurationAliases, aliasesType)
if err != nil {
return err
}
writeMap(requiredProvidersBody, "aws", map[string]cty.Value{
"source": cty.StringVal("hashicorp/aws"),
"version": cty.StringVal(">= 3.59.0"),
"source": cty.StringVal("hashicorp/aws"),
"version": cty.StringVal(">= 3.59.0"),
"configuration_aliases": aliasesVal,
})
if featureflag.Spotinst.Enabled() {
writeMap(requiredProvidersBody, "spotinst", map[string]cty.Value{