-
Notifications
You must be signed in to change notification settings - Fork 97
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
generate/hcl: support module calls through source
keyword
#130
base: master
Are you sure you want to change the base?
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.
Are you also still working on adding the afero.FS
implemtation into the TF lib?
managedResources := make(map[string]*configs.Resource) | ||
for rk, rv := range mod.ManagedResources { | ||
managedResources[rk] = rv | ||
} |
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.
One thing we are doing right now on the State is check if we have to prefix a resource with the module because the same resource could exist on another module aws_instance.front
could be in multiple modules.
We only do that when we have more than 1 module we should try to do the same as we'll find the same issue.
for _, vers := range meta.Versions { | ||
v, err := version.NewVersion(vers.Version) | ||
if err != nil { | ||
return fmt.Errorf("unable to create version from string: %w", err) | ||
} | ||
|
||
if latest == nil || v.GreaterThan(latest) { | ||
latest = v | ||
} | ||
|
||
if call.Version.Required.Check(v) { | ||
if match == nil || v.GreaterThan(match) { | ||
match = v | ||
} | ||
} | ||
} |
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.
Comment a bit this logic.
generate/hcl.go
Outdated
dst := path.Join(cachePath, name) | ||
// TODO: we should add a logic to invalidate | ||
// the cache | ||
if _, err := os.Stat(dst); os.IsNotExist(err) { | ||
client := &getter.Client{ | ||
Src: src, | ||
Dst: dst, | ||
Pwd: pwd, | ||
Mode: getter.ClientModeDir, | ||
} |
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.
As we have versions, we can assume versions are immutable, so you could use a dst := path.Join(cachePath, fmt.Sprintf("%s-%s", name, version))
// fill the final map of managed resources | ||
// using the config freshly loaded | ||
for rk, rv := range m.ManagedResources { | ||
(*mRes)[rk] = rv | ||
} | ||
|
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.
Potentially prefix it with them module if more than one or we'll have collision.
cmd/root.go
Outdated
PersistentPreRun: func(cmd *cobra.Command, args []string) { | ||
if debug { | ||
logsOut = os.Stdout | ||
} | ||
log.Init(logsOut, debug) | ||
}, |
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 would prefer not to include TC for this, copy the part you need (activation of TF logs) and open an issue to add Debugging to IM (if we do not have one already)
Ping @Thomas-lhuillier hehe. |
What do I have to do? 😅 |
@Thomas-lhuillier I guess @xescugc wanted to ping me instead - but feel free to work on this PR if you want to. 🙈 Anyways, thanks for the ping ! Besides the comments to address, I guess there is not so much effort to provide to get this PR land into a new release.
Nope. It was quite a mess to bring |
Makes sense 👍 Well, this all seems out of reach to me, maybe after a couple months/years training |
c0bd35f
to
d9632dd
Compare
Yes I think it was an autocomplete error from GH and I did not check haha the ping is for @tormath1 (ok if i do |
In this PR, we add the support for module calls. It supports local, remote and Terraform registry ones.
The function
moduleInstall
is called recursively in order to walk through theModuleCalls
of each module to feed aManagedResource
slice. It stores a trace of each installed element to avoid infinite loops and modules are cached into$XDG_CACHE
directory.Then it loops over the
ManagedResource
slice with the current behavior.A few notes:
Output example using this stack: https://github.com/cycloid-community-catalog/stack-gke
Closes: #56, #54