vainkop / terraform-aws-wireguard

Terraform Module for Wireguard VPN
GNU General Public License v3.0
25 stars 23 forks source link

Use 'required_providers' for AWS provider minimum version #2

Closed MarcMeszaros closed 3 years ago

MarcMeszaros commented 3 years ago

The way the AWS provider minimum version was specified was causing version conflicts in my Terraform project. It is also using the deprecated method of declaring provider versions.

https://www.terraform.io/docs/language/providers/configuration.html#version-an-older-way-to-manage-provider-versions

The other change is the removal of the S3 backend and terraform config block. Since this is a public module consumed by other terraform workspaces, terraform ignores the S3 backend. In my particular case I don't use S3 for state management and use a different backend.

vainkop commented 3 years ago

@MarcMeszaros as you can see my configuration is using Terragrunt with an s3 backend which is the most popular & recommended way of managing the Terraform state so please put it back into tf code.

I suggest you use the following format for the versions.tf & also it's safe to bump up the TF version to 0.14.10:

terraform {
  backend "s3" {}
}

provider "aws" {
  region = var.region
}

terraform {
  required_version = ">= 0.14.10"

  required_providers {
    aws = {
      source  = "hashicorp/aws"
      version = "~> 3.0"
    }
    tls = {
      source  = "hashicorp/tls"
      version = "~> 3.0"
    }
    archive = {
      source  = "hashicorp/archive"
      version = "~> 2.1"
    }
    null = {
      source  = "hashicorp/null"
      version = "~> 3.0"
    }
    local = {
      source  = "hashicorp/local"
      version = "~> 2.1"
    }
  }
}
MarcMeszaros commented 3 years ago

@vainkop Added back the S3 backend for terragrunt users and refactored to have the versions.tf as suggested. I also ran terraform fmt on the module.

I had originally removed the backend because of this warning (terraform v0.15.3) during plan:

Screen Shot 2021-05-25 at 11 12 18 AM

We use terraform cloud and we don't use terragrunt. We originally found this module via the terraform module registry. Is there a way to have defaults for terragrunt users without also throwing the warning for non terragrunt users using the module?

vainkop commented 3 years ago

@vainkop Added back the S3 backend for terragrunt users and refactored to have the versions.tf as suggested. I also ran terraform fmt on the module.

@MarcMeszaros I didn't mean to add all those providers into configuration, I just gave an example :) Please remove the ones which are not actually used. Thanks

vainkop commented 3 years ago

We use terraform cloud and we don't use terragrunt. We originally found this module via the terraform module registry. Is there a way to have defaults for terragrunt users without also throwing the warning for non terragrunt users using the module?

A terragrunt.hcl similar to the following is usually used by terragrunt users for configuration of the backend: https://github.com/vainkop/terraform-aws-wireguard/blob/master/example/terragrunt.hcl#L4

A warning is not an error so shouldn't be a problem but it's not ideal I agree.

It's possible to use terragrunt with terraform cloud but the experience is limited:

https://stackoverflow.com/a/60066545/7778447

https://blog.gruntwork.io/how-deploy-production-grade-infrastructure-using-gruntwork-with-terraform-cloud-aca919ca92c2

https://gruntwork.io/guides/foundations/how-to-use-gruntwork-infrastructure-as-code-library#integration_with_tfc_tfe

MarcMeszaros commented 3 years ago

@vainkop my mistake. I thought you literally wanted all the other dependencies in the versions.tf. 😉

I also merged the s3 backend in the same terraform declaration in versions.tf.

I move the provider aws { } to versions.tf since it seems more related to module setup than the actual module implementation in main.tf. Let me know if you actually want the aws provider declaration inside main.tf.