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

Enforce the provider version within the module #20996

Closed
chenrui333 opened this issue Apr 12, 2019 · 7 comments
Closed

Enforce the provider version within the module #20996

chenrui333 opened this issue Apr 12, 2019 · 7 comments
Labels

Comments

@chenrui333
Copy link

Recently, I have run into a issue that the module is using the latest available provider feature (PR details).

I wonder if I can enforce the provider version within the module, something like:

module "vpc" {
  source             = "terraform-aws-modules/vpc/aws"
  version            = "1.60.0"
  provider          = "">= 2.0.0""

In other words, the peerDependency between the modules.

@mildwonkey
Copy link
Contributor

Hi @chenrui333 !

I'm sorry, but I'm not quite following your question. Can you explain a bit more about what you are trying to achieve? Are you trying to override the provider version set in the module?

If the provider version is set in the module itself, terraform will use that version. There can only be one version of any given provider, so you don't need to "repeat" the provider version. If you have a module that is not setting the provider version, you can always set the provider version at the top-level .tf file and terraform will use that version (there can only be one version of any given provider used, so that version would be used by any and all modules using that provider).

@mildwonkey mildwonkey added question waiting-response An issue/pull request is waiting for a response from the community labels Apr 12, 2019
@chenrui333
Copy link
Author

chenrui333 commented Apr 12, 2019

If the provider version is set in the module itself, terraform will use that version.

@mildwonkey That sounds pretty cool, where can I see the example?

@ghost ghost removed the waiting-response An issue/pull request is waiting for a response from the community label Apr 12, 2019
@mildwonkey
Copy link
Contributor

Sure, here's a (made-up) example. If you have this main.tf:

module "foo" {
   source = "./bar"
}

And this module in ./bar/main.tf:

provider "random" {
    version = ">= 2.0.0"
}

resource "random_string" "example" {
     [ ... ]
}

Terraform will use the random provider >= v2.0.

Alternatively, if the module does not have a provider version specified, you can get the same behavior by putting the provider version in main.tf:

provider "random" {
    version = ">= 2.0.0"
}

module "foo" {
   source = "./bar"
}

Keep in mind that this would cause an error, because the provider versions specified cannot be reconciled:

main.tf:

provider "random" {
    version = "1.0.0"
}

module "foo" {
   source = "./bar"
}

./bar/main.tf:

provider "random" {
    version = ">= 2.0.0"
}

resource "random_string" "example" {
     [ ... ]
}

Does this help?

@chenrui333
Copy link
Author

@mildwonkey yeah, that is certainly help, I have to play around to see how the error message looks like.

Also, I have found this issue, #16835, sounds like very much the same idea does get implemented in the tf 0.12 version. :)

@chenrui333
Copy link
Author

Works pretty good for me, thanks @mildwonkey !

@chenrui333
Copy link
Author

@mildwonkey. not sure if it is relevant, I do encounter a issue to pass the version as variable to the provider block within the module:

./bar/main.tf:

variable "region" {
  default = "us-west-2"
}

provider "aws" {
  version = ">= 2.0.0"
  region 	= "${var.region}"
}

When I do terraform plan, it complains about missing the provider region declaration.

@ghost
Copy link

ghost commented Jul 26, 2019

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@ghost ghost locked and limited conversation to collaborators Jul 26, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants