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

Check for Environment Scope in ReadVariable #746

Open
oesah opened this issue Dec 16, 2019 · 8 comments
Open

Check for Environment Scope in ReadVariable #746

oesah opened this issue Dec 16, 2019 · 8 comments
Labels

Comments

@oesah
Copy link

oesah commented Dec 16, 2019

I am coming here from https://github.com/terraform-providers/terraform-provider-gitlab.

Problem
We are using go-gitlab to create resources using terraform. We face an issue, however, where project or group variables do not consider the scope. So if you have 2 variables with the same name but different scopes, it will cause terraform to always try to update them. See discussion here: https://github.com/terraform-providers/terraform-provider-gitlab/issues/213

I think the issue lie here:
https://github.com/xanzy/go-gitlab/blob/master/group_variables.go#L84
https://github.com/xanzy/go-gitlab/blob/master/project_variables.go#L86

Possible Solutions
Currently, the Gitlab API does not allow to filter them. You can follow the issue here: https://gitlab.com/gitlab-org/gitlab/issues/20661

Once that bug is fixed, we can enhance the above mentioned functions to incorporate the filtering solution.

@abelmokadem
Copy link

As an intermediate solution, can't you just query the list of all variables and then pick the variable from there?

/api/v4/projects/<project_id>/variables

I know that this is not a "nice" solution, but it would solve the issue we also have in the terraform project.

@remil1000
Copy link

remil1000 commented Jul 10, 2020

There is an update coming (probably end of July 2020) addressing this issue with a feature flag to be enabled ci_variables_api_filter_environment_scope

edit: it's not a request, only a heads up; I'll try to take a look and send a PR once it's released

@enkov
Copy link

enkov commented Aug 4, 2020

Any news? Gitlab fix the issue and released it.

@remil1000
Copy link

made an attempt here
https://github.com/remil1000/go-gitlab/tree/9912-project-variable-environment-scope
used and tested in https://github.com/remil1000/terraform-provider-gitlab/tree/9912-project-variable-environment-scope

don't forget to enable the Gitlab feature through Gitlab console
sudo gitlab-rails console and Feature.enable(:ci_variables_api_filter_environment_scope)

@woz5999
Copy link

woz5999 commented Aug 6, 2020

@remil1000 do you plan to submit a PR with your changes?

@martinhanzik
Copy link

@remil1000 It would be really nice to get this into a PR so we can finally get the Terraform resource working properly, do you plan to submit this? If not, I will reimplement it and submit it myself, but I don't see the point in doing this, if you've already done it.

@remil1000
Copy link

I should make a PR, but in the mean time I discovered there may be a simpler and prettier way of doing this
it seems the NewRequest function argument includes an opt interface{} to construct query string from a struct of options for each CRUD method; an example of such struct for the Update/PUT method is

type UpdateProjectVariableOptions struct {
  Value            *string            `url:"value,omitempty" json:"value,omitempty"`
  VariableType     *VariableTypeValue `url:"variable_type,omitempty" json:"variable_type,omitempty"`
  Protected        *bool              `url:"protected,omitempty" json:"protected,omitempty"`
  Masked           *bool              `url:"masked,omitempty" json:"masked,omitempty"`
  EnvironmentScope *string            `url:"environment_scope,omitempty" json:"environment_scope,omitempty"`
}

so probably adding an url:"filter[environment_scope],omitempty" would do the trick
I still need to check on that

if you have any suggestion let me know

@martinhanzik
Copy link

@remil1000 Any progress on this?

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

No branches or pull requests

7 participants