Skip to content

Commit 59c52b9

Browse files
authored
Merge pull request #990 from timofurrer/refactoring/group-project-variables
Implement data sources for all variable types
2 parents af538dc + c2ce27c commit 59c52b9

34 files changed

+1167
-162
lines changed

docs/data-sources/group_variable.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
---
2+
# generated by https://github.com/hashicorp/terraform-plugin-docs
3+
page_title: "gitlab_group_variable Data Source - terraform-provider-gitlab"
4+
subcategory: ""
5+
description: |-
6+
The gitlab_group_variable data source allows to retrieve details about a group-level CI/CD variable.
7+
Upstream API: GitLab REST API docs https://docs.gitlab.com/ee/api/group_level_variables.html
8+
---
9+
10+
# gitlab_group_variable (Data Source)
11+
12+
The `gitlab_group_variable` data source allows to retrieve details about a group-level CI/CD variable.
13+
14+
**Upstream API**: [GitLab REST API docs](https://docs.gitlab.com/ee/api/group_level_variables.html)
15+
16+
17+
18+
<!-- schema generated by tfplugindocs -->
19+
## Schema
20+
21+
### Required
22+
23+
- `group` (String) The name or id of the group.
24+
- `key` (String) The name of the variable.
25+
26+
### Optional
27+
28+
- `environment_scope` (String) The environment scope of the variable. Defaults to all environment (`*`). Note that in Community Editions of Gitlab, values other than `*` will cause inconsistent plans.
29+
- `id` (String) The ID of this resource.
30+
31+
### Read-Only
32+
33+
- `masked` (Boolean) If set to `true`, the value of the variable will be hidden in job logs. The value must meet the [masking requirements](https://docs.gitlab.com/ee/ci/variables/#masked-variables). Defaults to `false`.
34+
- `protected` (Boolean) If set to `true`, the variable will be passed only to pipelines running on protected branches and tags. Defaults to `false`.
35+
- `value` (String) The value of the variable.
36+
- `variable_type` (String) The type of a variable. Valid values are: `env_var`, `file`. Default is `env_var`.
37+
38+

docs/data-sources/group_variables.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
---
2+
# generated by https://github.com/hashicorp/terraform-plugin-docs
3+
page_title: "gitlab_group_variables Data Source - terraform-provider-gitlab"
4+
subcategory: ""
5+
description: |-
6+
The gitlab_group_variables data source allows to retrieve all group-level CI/CD variables.
7+
Upstream API: GitLab REST API docs https://docs.gitlab.com/ee/api/group_level_variables.html
8+
---
9+
10+
# gitlab_group_variables (Data Source)
11+
12+
The `gitlab_group_variables` data source allows to retrieve all group-level CI/CD variables.
13+
14+
**Upstream API**: [GitLab REST API docs](https://docs.gitlab.com/ee/api/group_level_variables.html)
15+
16+
17+
18+
<!-- schema generated by tfplugindocs -->
19+
## Schema
20+
21+
### Required
22+
23+
- `group` (String) The name or id of the group.
24+
25+
### Optional
26+
27+
- `environment_scope` (String) The environment scope of the variable. Defaults to all environment (`*`).
28+
- `id` (String) The ID of this resource.
29+
30+
### Read-Only
31+
32+
- `variables` (List of Object) The list of variables returned by the search (see [below for nested schema](#nestedatt--variables))
33+
34+
<a id="nestedatt--variables"></a>
35+
### Nested Schema for `variables`
36+
37+
Read-Only:
38+
39+
- `environment_scope` (String)
40+
- `group` (String)
41+
- `key` (String)
42+
- `masked` (Boolean)
43+
- `protected` (Boolean)
44+
- `value` (String)
45+
- `variable_type` (String)
46+
47+
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
---
2+
# generated by https://github.com/hashicorp/terraform-plugin-docs
3+
page_title: "gitlab_instance_variable Data Source - terraform-provider-gitlab"
4+
subcategory: ""
5+
description: |-
6+
The gitlab_instance_variable data source allows to retrieve details about an instance-level CI/CD variable.
7+
Upstream API: GitLab REST API docs https://docs.gitlab.com/ee/api/instance_level_ci_variables.html
8+
---
9+
10+
# gitlab_instance_variable (Data Source)
11+
12+
The `gitlab_instance_variable` data source allows to retrieve details about an instance-level CI/CD variable.
13+
14+
**Upstream API**: [GitLab REST API docs](https://docs.gitlab.com/ee/api/instance_level_ci_variables.html)
15+
16+
17+
18+
<!-- schema generated by tfplugindocs -->
19+
## Schema
20+
21+
### Required
22+
23+
- `key` (String) The name of the variable.
24+
25+
### Optional
26+
27+
- `id` (String) The ID of this resource.
28+
29+
### Read-Only
30+
31+
- `masked` (Boolean) If set to `true`, the value of the variable will be hidden in job logs. The value must meet the [masking requirements](https://docs.gitlab.com/ee/ci/variables/#masked-variables). Defaults to `false`.
32+
- `protected` (Boolean) If set to `true`, the variable will be passed only to pipelines running on protected branches and tags. Defaults to `false`.
33+
- `value` (String) The value of the variable.
34+
- `variable_type` (String) The type of a variable. Valid values are: `env_var`, `file`. Default is `env_var`.
35+
36+
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
---
2+
# generated by https://github.com/hashicorp/terraform-plugin-docs
3+
page_title: "gitlab_instance_variables Data Source - terraform-provider-gitlab"
4+
subcategory: ""
5+
description: |-
6+
The gitlab_instance_variables data source allows to retrieve all instance-level CI/CD variables.
7+
Upstream API: GitLab REST API docs https://docs.gitlab.com/ee/api/instance_level_ci_variables.html
8+
---
9+
10+
# gitlab_instance_variables (Data Source)
11+
12+
The `gitlab_instance_variables` data source allows to retrieve all instance-level CI/CD variables.
13+
14+
**Upstream API**: [GitLab REST API docs](https://docs.gitlab.com/ee/api/instance_level_ci_variables.html)
15+
16+
17+
18+
<!-- schema generated by tfplugindocs -->
19+
## Schema
20+
21+
### Optional
22+
23+
- `id` (String) The ID of this resource.
24+
25+
### Read-Only
26+
27+
- `variables` (List of Object) The list of variables returned by the search (see [below for nested schema](#nestedatt--variables))
28+
29+
<a id="nestedatt--variables"></a>
30+
### Nested Schema for `variables`
31+
32+
Read-Only:
33+
34+
- `key` (String)
35+
- `masked` (Boolean)
36+
- `protected` (Boolean)
37+
- `value` (String)
38+
- `variable_type` (String)
39+
40+

docs/data-sources/project_variable.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
---
2+
# generated by https://github.com/hashicorp/terraform-plugin-docs
3+
page_title: "gitlab_project_variable Data Source - terraform-provider-gitlab"
4+
subcategory: ""
5+
description: |-
6+
The gitlab_project_variable data source allows to retrieve details about a project-level CI/CD variable.
7+
Upstream API: GitLab REST API docs https://docs.gitlab.com/ee/api/project_level_variables.html
8+
---
9+
10+
# gitlab_project_variable (Data Source)
11+
12+
The `gitlab_project_variable` data source allows to retrieve details about a project-level CI/CD variable.
13+
14+
**Upstream API**: [GitLab REST API docs](https://docs.gitlab.com/ee/api/project_level_variables.html)
15+
16+
17+
18+
<!-- schema generated by tfplugindocs -->
19+
## Schema
20+
21+
### Required
22+
23+
- `key` (String) The name of the variable.
24+
- `project` (String) The name or id of the project.
25+
26+
### Optional
27+
28+
- `environment_scope` (String) The environment scope of the variable. Defaults to all environment (`*`). Note that in Community Editions of Gitlab, values other than `*` will cause inconsistent plans.
29+
- `id` (String) The ID of this resource.
30+
31+
### Read-Only
32+
33+
- `masked` (Boolean) If set to `true`, the value of the variable will be hidden in job logs. The value must meet the [masking requirements](https://docs.gitlab.com/ee/ci/variables/#masked-variables). Defaults to `false`.
34+
- `protected` (Boolean) If set to `true`, the variable will be passed only to pipelines running on protected branches and tags. Defaults to `false`.
35+
- `value` (String) The value of the variable.
36+
- `variable_type` (String) The type of a variable. Valid values are: `env_var`, `file`. Default is `env_var`.
37+
38+
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
---
2+
# generated by https://github.com/hashicorp/terraform-plugin-docs
3+
page_title: "gitlab_project_variables Data Source - terraform-provider-gitlab"
4+
subcategory: ""
5+
description: |-
6+
The gitlab_project_variables data source allows to retrieve all project-level CI/CD variables.
7+
Upstream API: GitLab REST API docs https://docs.gitlab.com/ee/api/project_level_variables.html
8+
---
9+
10+
# gitlab_project_variables (Data Source)
11+
12+
The `gitlab_project_variables` data source allows to retrieve all project-level CI/CD variables.
13+
14+
**Upstream API**: [GitLab REST API docs](https://docs.gitlab.com/ee/api/project_level_variables.html)
15+
16+
17+
18+
<!-- schema generated by tfplugindocs -->
19+
## Schema
20+
21+
### Required
22+
23+
- `project` (String) The name or id of the project.
24+
25+
### Optional
26+
27+
- `environment_scope` (String) The environment scope of the variable. Defaults to all environment (`*`).
28+
- `id` (String) The ID of this resource.
29+
30+
### Read-Only
31+
32+
- `variables` (List of Object) The list of variables returned by the search (see [below for nested schema](#nestedatt--variables))
33+
34+
<a id="nestedatt--variables"></a>
35+
### Nested Schema for `variables`
36+
37+
Read-Only:
38+
39+
- `environment_scope` (String)
40+
- `key` (String)
41+
- `masked` (Boolean)
42+
- `project` (String)
43+
- `protected` (Boolean)
44+
- `value` (String)
45+
- `variable_type` (String)
46+
47+

docs/resources/group_variable.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,11 @@ resource "gitlab_group_variable" "example" {
3737

3838
### Optional
3939

40-
- `environment_scope` (String) The environment scope of the variable. Defaults to all environment (`*`). Note that in Community Editions of Gitlab, values other than `*` will cause inconsistent plans. See https://docs.gitlab.com/ee/ci/variables/#add-a-cicd-variable-to-a-group
40+
- `environment_scope` (String) The environment scope of the variable. Defaults to all environment (`*`). Note that in Community Editions of Gitlab, values other than `*` will cause inconsistent plans.
4141
- `id` (String) The ID of this resource.
4242
- `masked` (Boolean) If set to `true`, the value of the variable will be hidden in job logs. The value must meet the [masking requirements](https://docs.gitlab.com/ee/ci/variables/#masked-variables). Defaults to `false`.
4343
- `protected` (Boolean) If set to `true`, the variable will be passed only to pipelines running on protected branches and tags. Defaults to `false`.
44-
- `variable_type` (String) The type of a variable. Available types are: env_var (default) and file.
44+
- `variable_type` (String) The type of a variable. Valid values are: `env_var`, `file`. Default is `env_var`.
4545

4646
## Import
4747

docs/resources/instance_variable.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
page_title: "gitlab_instance_variable Resource - terraform-provider-gitlab"
44
subcategory: ""
55
description: |-
6-
The gitlab_instance_variable resource allows to manage the lifecycle of a CI/CD variable for an instance.
6+
The gitlab_instance_variable resource allows to manage the lifecycle of an instance-level CI/CD variable.
77
Upstream API: GitLab REST API docs https://docs.gitlab.com/ee/api/instance_level_variables.html
88
---
99

1010
# gitlab_instance_variable (Resource)
1111

12-
The `gitlab_instance_variable` resource allows to manage the lifecycle of a CI/CD variable for an instance.
12+
The `gitlab_instance_variable` resource allows to manage the lifecycle of an instance-level CI/CD variable.
1313

1414
**Upstream API**: [GitLab REST API docs](https://docs.gitlab.com/ee/api/instance_level_variables.html)
1515

@@ -35,9 +35,9 @@ resource "gitlab_instance_variable" "example" {
3535
### Optional
3636

3737
- `id` (String) The ID of this resource.
38-
- `masked` (Boolean) If set to `true`, the value of the variable will be hidden in job logs. The value must meet the [masking requirements](https://docs.gitlab.com/ee/ci/variables/#masked-variable-requirements). Defaults to `false`.
38+
- `masked` (Boolean) If set to `true`, the value of the variable will be hidden in job logs. The value must meet the [masking requirements](https://docs.gitlab.com/ee/ci/variables/#masked-variables). Defaults to `false`.
3939
- `protected` (Boolean) If set to `true`, the variable will be passed only to pipelines running on protected branches and tags. Defaults to `false`.
40-
- `variable_type` (String) The type of a variable. Available types are: env_var (default) and file.
40+
- `variable_type` (String) The type of a variable. Valid values are: `env_var`, `file`. Default is `env_var`.
4141

4242
## Import
4343

docs/resources/project_variable.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,11 @@ resource "gitlab_project_variable" "example" {
3838

3939
### Optional
4040

41-
- `environment_scope` (String) The environment_scope of the variable. Defaults to `*`.
41+
- `environment_scope` (String) The environment scope of the variable. Defaults to all environment (`*`). Note that in Community Editions of Gitlab, values other than `*` will cause inconsistent plans.
4242
- `id` (String) The ID of this resource.
43-
- `masked` (Boolean) If set to `true`, the variable will be masked if it would have been written to the logs. Defaults to `false`.
43+
- `masked` (Boolean) If set to `true`, the value of the variable will be hidden in job logs. The value must meet the [masking requirements](https://docs.gitlab.com/ee/ci/variables/#masked-variables). Defaults to `false`.
4444
- `protected` (Boolean) If set to `true`, the variable will be passed only to pipelines running on protected branches and tags. Defaults to `false`.
45-
- `variable_type` (String) The type of a variable. Available types are: env_var (default) and file.
45+
- `variable_type` (String) The type of a variable. Valid values are: `env_var`, `file`. Default is `env_var`.
4646

4747
## Import
4848

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package provider
2+
3+
import (
4+
"context"
5+
"fmt"
6+
7+
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
8+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
9+
"github.com/xanzy/go-gitlab"
10+
)
11+
12+
var _ = registerDataSource("gitlab_group_variable", func() *schema.Resource {
13+
return &schema.Resource{
14+
Description: `The ` + "`gitlab_group_variable`" + ` data source allows to retrieve details about a group-level CI/CD variable.
15+
16+
**Upstream API**: [GitLab REST API docs](https://docs.gitlab.com/ee/api/group_level_variables.html)`,
17+
18+
ReadContext: dataSourceGitlabGroupVariableRead,
19+
Schema: datasourceSchemaFromResourceSchema(gitlabGroupVariableGetSchema(), []string{"group", "key"}, []string{"environment_scope"}),
20+
}
21+
})
22+
23+
func dataSourceGitlabGroupVariableRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
24+
client := meta.(*gitlab.Client)
25+
group := d.Get("group").(string)
26+
key := d.Get("key").(string)
27+
environmentScope := d.Get("environment_scope").(string)
28+
29+
variable, _, err := client.GroupVariables.GetVariable(group, key, nil, gitlab.WithContext(ctx), withEnvironmentScopeFilter(ctx, environmentScope))
30+
if err != nil {
31+
return diag.FromErr(err)
32+
}
33+
34+
d.SetId(fmt.Sprintf("%s:%s:%s", group, key, environmentScope))
35+
stateMap := gitlabGroupVariableToStateMap(group, variable)
36+
if err := setStateMapInResourceData(stateMap, d); err != nil {
37+
return diag.FromErr(err)
38+
}
39+
return nil
40+
}

0 commit comments

Comments
 (0)