From cc3ce67d241836985dc96a25e419c0ba658e45a3 Mon Sep 17 00:00:00 2001 From: Ivan Milchev Date: Tue, 19 Sep 2023 20:13:55 +0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix=20gitlab=20hcl=20discovery?= =?UTF-8?q?=20for=20groups=20(#1792)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Ivan Milchev --- motor/discovery/gitlab/gitlab.go | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/motor/discovery/gitlab/gitlab.go b/motor/discovery/gitlab/gitlab.go index 1253f026ee..5183a27784 100644 --- a/motor/discovery/gitlab/gitlab.go +++ b/motor/discovery/gitlab/gitlab.go @@ -172,6 +172,29 @@ func (r *Resolver) Resolve(ctx context.Context, root *asset.Asset, pCfg *provide terraformCfg.Backend = providers.ProviderType_TERRAFORM // git+https://gitlab.com/mondoolabs/example-gitlab.git terraformCfg.Options["path"] = "git+" + project.HTTPURLToRepo + + terraformCfg.Options = map[string]string{ + "asset-type": "hcl", + "path": "git+" + project.HTTPURLToRepo, + } + + if len(pCfg.Credentials) == 0 { + token := os.Getenv("GITLAB_TOKEN") + terraformCfg.Credentials = []*vault.Credential{{ + Type: vault.CredentialType_password, + User: "oauth2", + Secret: []byte(token), + }} + } else { + // add oauth2 user to the credentials + for i := range pCfg.Credentials { + cred := pCfg.Credentials[i] + if cred.Type == vault.CredentialType_password { + cred.User = "oauth2" + } + } + } + assets, err := (&terraform_resolver.Resolver{}).Resolve(ctx, projectAsset, terraformCfg, credsResolver, sfn) if err == nil && len(assets) > 0 { for i := range assets { @@ -183,6 +206,8 @@ func (r *Resolver) Resolve(ctx context.Context, root *asset.Asset, pCfg *provide continue } } + } else { + log.Error().Err(err).Msg("error discovering terraform") } } }