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

(TFECO-7366) Stacks: parse terraform-sources.json to support remote component sources #1836

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

ansgarm
Copy link
Member

@ansgarm ansgarm commented Sep 25, 2024

needs hashicorp/terraform-schema#406

Open tasks

  • Tests!

@ansgarm ansgarm changed the title wip stacks: parse terraform-sources.json to support remote component sources Sep 25, 2024
internal/features/rootmodules/state/installed_modules.go Outdated Show resolved Hide resolved
@@ -350,6 +401,8 @@ func (s *RootStore) CallersOfModule(path string) ([]string, error) {
if record.ModManifest.ContainsLocalModule(path) {
callers = append(callers, record.path)
}

// TODO: support TerraformSources as well here
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to?

@@ -375,10 +428,28 @@ func (s *RootStore) InstalledModuleCalls(path string) (map[string]tfmod.Installe
}
}
}
// TODO: support TerraformSources as well here
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to?


fi, err := fs.Stat(terraformSourcesPath)
if err == nil && fi.Mode().IsRegular() {
return terraformSourcesDirPath, true // TODO: this is a bit weird and misleading, maybe we should just use the bundle thing reading the dir and catch the proper error or sth like that
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unsure whether we need this method at all since the go-slug parser for this file also handles it not existing

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. I think you can remove it and make ParseTerraformSources a bit leaner.

@ansgarm ansgarm changed the title stacks: parse terraform-sources.json to support remote component sources (TFECO-7366) Stacks: parse terraform-sources.json to support remote component sources Oct 16, 2024
@ansgarm ansgarm marked this pull request as ready for review October 28, 2024 08:13
@ansgarm ansgarm requested a review from a team as a code owner October 28, 2024 08:13
@ansgarm ansgarm force-pushed the parse-terraform-sources branch 2 times, most recently from 6bcb15e to 21628e9 Compare October 29, 2024 12:51
Copy link
Member

@dbanck dbanck left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work! I left some comments

return err
}

tfs, err := datadir.ParseTerraformSourcesFromFile(terraformSourcesPath)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we pass modPath as an argument to this function? This will remove the need for the module path "detection" logic inside that function

normalizedSource := tfmod.ParseModuleSourceAddr(remote.String())
installedModules[normalizedSource.String()] = dir
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By iterating over sources.RegistryPackages(), we should be able to add support for registry modules as well

@@ -350,6 +401,8 @@ func (s *RootStore) CallersOfModule(path string) ([]string, error) {
if record.ModManifest.ContainsLocalModule(path) {
callers = append(callers, record.path)
}

// TODO: support TerraformSources as well here -> they don't contain local modules though, so we'd need to do this different here for stacks?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can leave this as is for now. I'm not sure if the module caller command makes sense in a stack context.


fi, err := fs.Stat(terraformSourcesPath)
if err == nil && fi.Mode().IsRegular() {
return terraformSourcesDirPath, true // TODO: this is a bit weird and misleading, maybe we should just use the bundle thing reading the dir and catch the proper error or sth like that
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. I think you can remove it and make ParseTerraformSources a bit leaner.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants