Skip to content

Conversation

@ffjlabo
Copy link
Member

@ffjlabo ffjlabo commented Mar 30, 2022

What this PR does / why we need it:

This PR changes to show URL for terraform local module.
ref: local module https://www.terraform.io/language/modules/sources#local-paths

Which issue(s) this PR fixes:

A part of #3303

Does this PR introduce a user-facing change?:

Be able to show URL for terraform local module.

@pipecd-bot
Copy link
Collaborator

APPROVE

This pull request is NOT APPROVED. It will be approved when one of the following conditions is met:

  • Received a comment that contains /approve from an approver.
  • Received approval at review changes UI from at least 1 approvers.

@pipecd-bot
Copy link
Collaborator

COVERAGE

Code coverage for golang is 34.98%. This pull request increases coverage by 0.04%.

File Function Base Head Diff
pkg/app/piped/cloudprovider/terraform/module.go isModuleLocal -- 100.00% +100.00%
pkg/app/piped/cloudprovider/terraform/module.go NewLocalModuleSourceConverter -- 0.00% +0.00%
pkg/app/piped/cloudprovider/terraform/module.go LocalModuleSourceConverter.MakeURL -- 85.71% +85.71%

Comment on lines 120 to 126
func isModuleLocal(moduleSrc string) bool {
if strings.HasPrefix(moduleSrc, "./") || strings.HasPrefix(moduleSrc, "../") {
return true
}

return false
}
Copy link
Member

Choose a reason for hiding this comment

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

nits

Suggested change
func isModuleLocal(moduleSrc string) bool {
if strings.HasPrefix(moduleSrc, "./") || strings.HasPrefix(moduleSrc, "../") {
return true
}
return false
}
func isLocalModule(src string) bool {
return strings.HasPrefix(src, "./") || strings.HasPrefix(src, "../")
}

Copy link
Member Author

Choose a reason for hiding this comment

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

thank you for the suggestion!

@pipecd-bot
Copy link
Collaborator

COVERAGE

Code coverage for golang is 34.97%. This pull request increases coverage by 0.03%.

File Function Base Head Diff
pkg/app/piped/cloudprovider/terraform/module.go isLocalModule -- 100.00% +100.00%
pkg/app/piped/cloudprovider/terraform/module.go NewLocalModuleSourceConverter -- 0.00% +0.00%
pkg/app/piped/cloudprovider/terraform/module.go LocalModuleSourceConverter.MakeURL -- 85.71% +85.71%

Comment on lines 85 to 99
for _, f := range files {
for _, m := range f.Modules {
if m.IsLocal {
l := provider.NewLocalModuleSourceConverter(in.GitPath.Repo.Remote, in.GitPath.Repo.Branch, ds.RepoDir, ds.AppDir)
url, err := l.MakeURL(m.Source)
if err != nil {
return out, err
}

m.Source = url
} else {
// TODO: convert remote module to URL.
}
}
}
Copy link
Member

Choose a reason for hiding this comment

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

This shouldn't be included in this function. I think we should pass a GitPath to FindArtifactVersions to handle inside that function, instead.

Copy link
Member Author

Choose a reason for hiding this comment

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

I see I'll fix it! Thank you!
ds.RepoDir, ds.AppDir are also needed, so I'll fix to pass a GitPath and a ds!

@pipecd-bot
Copy link
Collaborator

TODO

The following ISSUES will be created once got merged. If you want me to skip creating the issue, you can use /todo skip command.

Details

1. convert remote module to URL.

// TODO: convert remote module to URL.
}
versions = append(versions, &model.ArtifactVersion{

This was created by todo plugin since "TODO:" was found in 4dbe548 when #3461 was merged. cc: @ffjlabo.

@pipecd-bot
Copy link
Collaborator

COVERAGE

Code coverage for golang is 35.00%. This pull request increases coverage by 0.06%.

File Function Base Head Diff
pkg/app/piped/cloudprovider/terraform/module.go isLocalModule -- 100.00% +100.00%
pkg/app/piped/cloudprovider/terraform/module.go NewLocalModuleSourceConverter -- 100.00% +100.00%
pkg/app/piped/cloudprovider/terraform/module.go LocalModuleSourceConverter.MakeURL -- 85.71% +85.71%
pkg/app/piped/cloudprovider/terraform/module.go FindArtifactVersions 100.00% 90.91% -9.09%

@knanao
Copy link
Member

knanao commented Mar 31, 2022

Nice
/lgtm

// FindArtifactVersions parses artifact versions from Terraform files.
// For Terraform, module version is an artifact version.
func FindArtifactVersions(tfs []File) ([]*model.ArtifactVersion, error) {
func FindArtifactVersions(tfs []File, gp *model.ApplicationGitPath, ds *deploysource.DeploySource) ([]*model.ArtifactVersion, error) {
Copy link
Member

Choose a reason for hiding this comment

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

model.ApplicationGitPath can be passed directly by value instead of a pointer.

Copy link
Member

Choose a reason for hiding this comment

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

Only passing the needed fields instead of all deploysource.DeploySource object.

Comment on lines +153 to +154
RepoDir: repoDir,
AppDir: AppDir,
Copy link
Member

Choose a reason for hiding this comment

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

Maybe we don't need these fields.
The File struct can contain a relative path of itself from the root of the repository.

@nghialv
Copy link
Member

nghialv commented Mar 31, 2022

@ffjlabo Thanks for your great work!

Please feel free to transfer this PR to me. 👍
And let me hold this PR to take a deeper look at this feature.

/hold

@nghialv
Copy link
Member

nghialv commented Mar 31, 2022

/hold

@nghialv nghialv removed the lgtm label Mar 31, 2022
@knanao
Copy link
Member

knanao commented Nov 25, 2022

Please create another PR when you'll work on this task.

@knanao knanao closed this Nov 25, 2022
@github-actions
Copy link
Contributor

CLA Assistant Lite bot: Welcome!
Thanks for your contributing. It looks like this is your first PR to this repository 🎉. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). Please read the CLA and leave a below comment on this pull request to sign the CLA.


/cla sign


You can retrigger this bot by commenting recheck in this Pull Request

@nghialv nghialv deleted the parse_terraform_local_module_source branch December 2, 2022 03:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants