-
Notifications
You must be signed in to change notification settings - Fork 12
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
Addition of opinionated Terrafile support #10
base: master
Are you sure you want to change the base?
Conversation
867f882
to
b64fd5d
Compare
Hi. I'm not sure about the way it matches module names. Here is how I would probably do it:
# Terrafile
example:
source: https://github.com/joeblogs/example.git
version: master # dev/apps/main.tf
module "example1" {
source = "../../modules/example"
name = "example 1"
}
module "example2" {
source = "../../modules/example"
name = "example 2"
} When pterrafile runs, it searches for module sources, rather than names, in files in the current directory. If a module source directory matches an entry in Terrafile, it gets downloaded. This way, module names in your Terraform code don't have to match the name of the module. More importantly, it allows for using the same downloaded module multiple times - in the above example it gets used twice in the same file, but also multiple projects (apps, ec2, etc) could all refer to the same shared module directory and it only has to be downloaded once. |
The version feature is interesting, but I don't see any reason for it to be part of this pull request. 1 pull request = 1 feature only, please :) If it is going to be implemented, I think it should be done similarly to https://www.terraform.io/docs/configuration/providers.html#version-provider-versions where you can specify an exact version or use prefixes like # Terrafile
example:
source: https://github.com/joeblogs/example.git
version: ~> 1.2 I've never considered automatically upgrading Terraform modules in this way. It's very interesting to see how other people are using Terraform in different ways. |
@raymondbutcher Thanks for getting back to me. Let me clarify the new functionality with a couple of the use cases so you have better understanding of why its done in this manner and your suggested alternative will not meet the use case.(Even though there is obviously many ways to implement the same functionality). Use Case 1: Based on the above you can see that if the two attributes match then multiple modules will utilize the same retrieved repos. So your suggestion feature support is already encompassed, but it cannot be done in the manner you describe because you are not taking into consideration that the module source string only requires the repo name within it somewhere, but all the pre or post parts can be different. Use Case 2: module sources suffix can have different subfolder suffixes, Here the functionality will retrieve the repo once, and the two modules will both reference the same source
|
No worries about the version commit, and thanks for providing all of this detail. I'll try to be clear with terminology too:
Each pterrafile uses the
Each Here is what I'm proposing: pterrafile looks through all pterrafile then searches through pterrafile then populates the matched That's it. It's just a new option that makes it only download modules if they are going to be used. I don't think the name of a module in the Terraform code should have anything to do with the module directory name. We can achieve everything by using the source field. That's what the source field is for. This feature would not be "opinionated" and it wouldn't require much of an explanation. Nobody has to change how they use modules or pterrafile to use this feature. I have translated your use cases (I think I got the intentions right) into how it would work with source matching. I think it works for all of them. Use Case 1: use one module twice
Use Case 2: use two subfolders of one module
Use Case 3: use two branches of one module
Use Case 4 module with relative path
|
@raymondbutcher Thanks for taking the time to provide a more detailed explanation. I now get your suggested change of flipping the search and dropping the terraform module as index and utilising value from terraform module source instead and it makes sense as we are dealing with insignificant number of records and it is more compatible upgrade. I am trying to identify any problems with it. There is a potential issue in that you have to search for all the module names from the Terrafile across all the terraform files module source strings. I believe this may easily result in some false positives as people inadvertently have Terrafile module names in terraform module source strings or utilising modules outside their control that utilise the aggregate multiple modules with single repo distinguishing by subfolder suffix (USE CASE 2). I will look into prototyping the change and I will refer back. |
Tested against python 2.7.6 and python 3.7.4