Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Path from Terraform 0.13 #140

Closed
wants to merge 1 commit into from

Conversation

Lewiscowles1986
Copy link

@Lewiscowles1986 Lewiscowles1986 commented Dec 20, 2020

This was all I needed to overcome terraform init failing

Description

Motivation and Context

  • I have raised an issue to propose this change this is required

Affects #67 & #77

How Has This Been Tested?

By running terraform init and it not failing with

Could not retrieve the list of available versions for provider
hashicorp/digitalocean: provider registry registry.terraform.io does not have
a provider named registry.terraform.io/hashicorp/digitalocean

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • [?] Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

Commits:

  • I've read the CONTRIBUTION guide
  • My commit message has a body and describe how this was tested and why it is required.
  • I have signed-off my commits with git commit -s for the Developer Certificate of Origin (DCO)

Code:

  • My code follows the code style of this project.
  • I have added tests to cover my changes.

Docs:

  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.

This was all I needed to overcome terraform init failing
@derek
Copy link

derek bot commented Dec 20, 2020

Thank you for your contribution. I've just checked and your commit doesn't appear to be signed-off. That's something we need before your Pull Request can be merged. Please see our contributing guide.
Tip: if you only have one commit so far then run: git commit --amend --signoff and then git push --force.

@alexellis
Copy link
Member

This terraform is for v0.12.0

alex@am1 bootstrap % arkade get terraform --version 0.12.0

alex@am1 bootstrap % /Users/alex/.arkade/bin/terraform init

Initializing the backend...

Initializing provider plugins...
- Checking for available provider plugins...
- Downloading plugin for provider "random" (hashicorp/random) 3.0.0...
- Downloading plugin for provider "local" (hashicorp/local) 2.0.0...
- Downloading plugin for provider "template" (hashicorp/template) 2.2.0...
- Downloading plugin for provider "digitalocean" (terraform-providers/digitalocean) 2.3.0...

The following providers do not have any version constraints in configuration,
so the latest version was installed.

To prevent automatic upgrades to new major versions that may contain breaking
changes, it is recommended to add version = "..." constraints to the
corresponding provider blocks in configuration, with the constraint strings
suggested below.

* provider.digitalocean: version = "~> 2.3"
* provider.local: version = "~> 2.0"
* provider.random: version = "~> 3.0"
* provider.template: version = "~> 2.2"


Warning: registry.terraform.io: For users on Terraform 0.13 or greater, this provider has moved to digitalocean/digitalocean. Please update your source in required_providers.


Terraform has been successfully initialized!

You may now begin working with Terraform. Try running "terraform plan" to see
any changes that are required for your infrastructure. All Terraform commands
should now work.

If you ever set or change modules or backend configuration for Terraform,
rerun this command to reinitialize your working directory. If you forget, other
commands will detect it and remind you to do so if necessary.
alex@am1 bootstrap % 

Happy to update the files, but can you confirm that the changes will work with Terraform v0.12.0 still?

@alexellis
Copy link
Member

cc @jsiebens

@alexellis
Copy link
Member

For me, running terraform 0.13upgrade resulted in a file that didn't work with terraform 0.12.0.

Copy link
Member

@alexellis alexellis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change breaks Terraform v0.12.0

alex@am1 bootstrap % /Users/alex/.arkade/bin/terraform version
Terraform v0.12.0
+ provider.digitalocean v2.3.0
+ provider.local v2.0.0
+ provider.random v3.0.0
+ provider.template v2.2.0

Your version of Terraform is out of date! The latest version
is 0.14.3. You can update by downloading from www.terraform.io/downloads.html
alex@am1 bootstrap % /Users/alex/.arkade/bin/terraform init   
There are some problems with the configuration, described below.

The Terraform configuration must be valid before initialization so that
Terraform can determine which modules and providers need to be installed.

Error: Invalid version constraint

  on main.tf line 5, in terraform:
   5:     digitalocean = {
   6:       source = "digitalocean/digitalocean"
   7:       version = "2.3.0"
   8:     }

A string value is required for digitalocean.

alex@am1 bootstrap % 

@alexellis
Copy link
Member

You'll need to add the following to make it compatible with both versions. See more here: v0.12-Compatible Provider Requirements

+  required_providers {
+    digitalocean = "2.3.0"
+  }

@Lewiscowles1986
Copy link
Author

It still fails with that @alexellis, in any case pinning to terraform 0.14 might be the safest path forward. I've raised this more as documentation of a thing I found. I'll close now. Feel free to experiment more.

@alexellis
Copy link
Member

It didn't fail for me on 0.12.0 and when I upgrade to 0.13.0 it worked OK. Can you confirm the error you got with 0.13.0 with my alteration?

@Lewiscowles1986
Copy link
Author

Lewiscowles1986 commented Dec 23, 2020

On Terraform v0.12.29 your suggested change works, but then again, on that terraform version it always worked, without pinning.
On Terraform v0.13.5 your suggested change returns an error

traceback for TF 0.13.5 - green (no state, no .terraform folder)
terraform-0.13 init

Initializing the backend...

Initializing provider plugins...
- Finding latest version of hashicorp/local...
- Finding latest version of hashicorp/template...
- Finding hashicorp/digitalocean versions matching "2.3.0"...
- Finding latest version of hashicorp/random...
- Installing hashicorp/local v2.0.0...
- Installed hashicorp/local v2.0.0 (signed by HashiCorp)
- Installing hashicorp/template v2.2.0...
- Installed hashicorp/template v2.2.0 (signed by HashiCorp)
- Installing hashicorp/random v3.0.0...
- Installed hashicorp/random v3.0.0 (signed by HashiCorp)

Warning: Interpolation-only expressions are deprecated

  on main.tf line 50, in data "template_file" "cloud_init":
  50:   template = "${file("cloud-config.tpl")}"

Terraform 0.11 and earlier required all non-constant expressions to be
provided via interpolation syntax, but this pattern is now deprecated. To
silence this warning, remove the "${ sequence from the start and the }"
sequence from the end of this expression, leaving just the inner expression.

Template interpolation syntax is still used to construct strings from
expressions when the template includes multiple interpolation sequences or a
mixture of literal strings and interpolations. This deprecation applies only
to templates that consist entirely of a single interpolation sequence.


Error: Failed to install providers

Could not find required providers, but found possible alternatives:

  hashicorp/digitalocean -> digitalocean/digitalocean

If these suggestions look correct, upgrade your configuration with the
following command:
    terraform 0.13upgrade .
On Terraform `v0.14.4` (stable). your suggested change returns an error
traceback for TF 0.14.4 - green (no state, no .terraform folder)
$ terraform init

Initializing the backend...

Initializing provider plugins...
- Finding latest version of hashicorp/template...
- Finding hashicorp/digitalocean versions matching "2.3.0"...
- Finding latest version of hashicorp/random...
- Finding latest version of hashicorp/local...
- Installing hashicorp/template v2.2.0...
- Installed hashicorp/template v2.2.0 (signed by HashiCorp)
- Installing hashicorp/random v3.0.0...
- Installed hashicorp/random v3.0.0 (signed by HashiCorp)
- Installing hashicorp/local v2.0.0...
- Installed hashicorp/local v2.0.0 (signed by HashiCorp)

Warning: Interpolation-only expressions are deprecated

  on main.tf line 50, in data "template_file" "cloud_init":
  50:   template = "${file("cloud-config.tpl")}"

Terraform 0.11 and earlier required all non-constant expressions to be
provided via interpolation syntax, but this pattern is now deprecated. To
silence this warning, remove the "${ sequence from the start and the }"
sequence from the end of this expression, leaving just the inner expression.

Template interpolation syntax is still used to construct strings from
expressions when the template includes multiple interpolation sequences or a
mixture of literal strings and interpolations. This deprecation applies only
to templates that consist entirely of a single interpolation sequence.


Error: Failed to query available provider packages

Could not retrieve the list of available versions for provider
hashicorp/digitalocean: provider registry registry.terraform.io does not have
a provider named registry.terraform.io/hashicorp/digitalocean

If you have just upgraded directly from Terraform v0.12 to Terraform v0.14
then please upgrade to Terraform v0.13 first and follow the upgrade guide for
that release, which might help you address this problem.

Did you intend to use digitalocean/digitalocean? If so, you must specify that
source address in each module which requires that provider. To see which
modules are currently depending on hashicorp/digitalocean, run the following
command:
    terraform providers

On 0.13 I can run terraform 0.13upgrade . and it will fix the code. On 0.14 this seems to be gone.
On 0.13 after the terraform 0.13upgrade command it looks like this PR, with some extras that I didn't include such as whitespace changes and more dependency pinning (good practice for IaC).

Honestly, telling people to use terraform 0.12 is an alternative path. It was not specified in the guide I saw Sunday, which was one reason why I opted to go upgrade path.

This might need more looking into, maybe it's fine and everyone will somehow know to get an older 2019 version of Terraform. I'm definitely not the target market for this. I found if the terraform is used to provision DNS it always hard-codes to faasd (similar micro-fix).

@Lewiscowles1986 Lewiscowles1986 changed the title Overcome terraform DO missing pinning Path from Terraform 0.13 Dec 23, 2020
@alexellis
Copy link
Member

@jsiebens PTAL?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants