-
-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Multiple include blocks #1804
Multiple include blocks #1804
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work Yori 👍
} | ||
``` | ||
|
||
### Using read\_terragrunt\_config to DRY parent configurations |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mentioned this in the other PR, but we probably want to encourage putting things that you typically change on an env-by-env basis in the env itself so it works better with CI / CD; and putting things that you would change globally (albeit rarely) into an _env
folder. So for example, env name, instance type, number of instances, ref
(version) are all things you may want to change in one env, but not another, and you may want CI / CD to be able to detect it based on the file you changed, so it makes more sense to define those params directly in stage/app/terragrunt.hcl
for stage and prod/app/terragrunt.hcl
for prod. For everything else, you can put it in _env
, under the assumption that it changes very rarely, and you can somehow manually trigger CI / CD as necessary for that change.
That does make me think of an alternative approach, which might be nonsense, but I figured it's worth thinking through: would it make sense to version the terragrunt.hcl
files in _env
? Ignoring implementation details, imagine for a second that all the _env
stuff is defined in infrastructure-modules
; inside the terragrunt.hcl
files in _env
, it uses relative paths within infrastructure-modules
; and the whole repo is versioned as usual. Then, in infrastructure-live
, you include
not from a path
but from a versioned source
parameter. That allows you to use different versions of _env
in each actual env, and promote changes from one env to another. In that case, you could define environment-specific values in _env
as well (e.g., instance type, instance count, etc), as you'd bump the version number in stage
or prod
to pick up the new configs, and CI / CD would pick that up.
So, in effect, infra-live
would become VERY minimal: just a bunch of terragrunt.hcl
marker files that use include
to pull in the actual configs from versioned URLs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That does make me think of an alternative approach, which might be nonsense, but I figured it's worth thinking through: would it make sense to version the terragrunt.hcl files in _env? Ignoring implementation details, imagine for a second that all the _env stuff is defined in infrastructure-modules; inside the terragrunt.hcl files in _env, it uses relative paths within infrastructure-modules; and the whole repo is versioned as usual. Then, in infrastructure-live, you include not from a path but from a versioned source parameter. That allows you to use different versions of _env in each actual env, and promote changes from one env to another. In that case, you could define environment-specific values in _env as well (e.g., instance type, instance count, etc), as you'd bump the version number in stage or prod to pick up the new configs, and CI / CD would pick that up.
Yes I had this exact thought! This actually has another advantage of better handling variable updates across module versions. E.g., in the current setup, there is a limitation where the shared inputs are in a static file shared across dev
, stage
, and prod
. What if a version bump removes a variable, or there is a new required variable, or an old variable type changed? Ideally, you would make the change in the shared variables in _env
, but then that would break stage
and prod
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mentioned this in the other PR, but we probably want to encourage putting things that you typically change on an env-by-env basis in the env itself so it works better with CI / CD; and putting things that you would change globally (albeit rarely) into an _env folder. So for example, env name, instance type, number of instances, ref (version) are all things you may want to change in one env, but not another, and you may want CI / CD to be able to detect it based on the file you changed, so it makes more sense to define those params directly in stage/app/terragrunt.hcl for stage and prod/app/terragrunt.hcl for prod. For everything else, you can put it in _env, under the assumption that it changes very rarely, and you can somehow manually trigger CI / CD as necessary for that change.
Good point. I updated the docs to use expose
instead of read_terragrunt_config
for the module version, and updated read_terragrunt_config
docs to be something more generic: c034ca9
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That does make me think of an alternative approach, which might be nonsense, but I figured it's worth thinking through: would it make sense to version the terragrunt.hcl files in _env? Ignoring implementation details, imagine for a second that all the _env stuff is defined in infrastructure-modules; inside the terragrunt.hcl files in _env, it uses relative paths within infrastructure-modules; and the whole repo is versioned as usual. Then, in infrastructure-live, you include not from a path but from a versioned source parameter. That allows you to use different versions of _env in each actual env, and promote changes from one env to another. In that case, you could define environment-specific values in _env as well (e.g., instance type, instance count, etc), as you'd bump the version number in stage or prod to pick up the new configs, and CI / CD would pick that up.
Yes I had this exact thought! This actually has another advantage of better handling variable updates across module versions. E.g., in the current setup, there is a limitation where the shared inputs are in a static file shared across
dev
,stage
, andprod
. What if a version bump removes a variable, or there is a new required variable, or an old variable type changed? Ideally, you would make the change in the shared variables in_env
, but then that would breakstage
andprod
.
We should def experiment with this as the way to make the Ref Arch super DRY, versioned, etc.
9ecd023
to
fb5d604
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is great work Yori 👍
|
||
include "env" { | ||
path = "${get_terragrunt_dir()}/../../_env/app.hcl" | ||
expose = true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Neat 👍
``` | ||
|
||
|
||
### Using read\_terragrunt\_config to DRY parent configurations |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, nice, this is a better example 👍
} | ||
|
||
terraform { | ||
source = "../modules/${path_relative_to_include("root")}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Passing in the name is a great solution 👍
Thanks for review! Will merge this in, cut a new release as backward compatible (given how much code change there is to the |
This is the implementation of the feature described in #1803
This is backward compatible for the most part, except for the expose feature, where you must now index into the label - any prior references to exposed
include
must be updated toinclude[""]
. E.g., if the user had:the
include.locals.region
reference must be updated toinclude[""].locals.region
.