Skip to content

Commit 48d970d

Browse files
committed
Merge branch 'reintroduce-config-ds' into 'main'
Reintroduce the gitlabci_runner_config data source See merge request rsrchboy/terraform-provider-gitlabci!7
2 parents 1bd8d5b + 647b617 commit 48d970d

File tree

24 files changed

+10860
-50
lines changed

24 files changed

+10860
-50
lines changed

Makefile

Lines changed: 44 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
GOFMT_FILES?=$$(find . -name '*.go' |grep -v vendor)
22

33
sources = $(wildcard *.go gitlabci/*.go go.mod helper/**/*.go internal/**/*.go)
4+
docs = $(wildcard docs/**/*)
5+
doc_sources = $(wildcard templates/**/* examples/**/resource.tf examples/**/data-source.tf) \
6+
examples/provider/provider.tf \
7+
$(wildcard examples/registering-a-runner/**/*)
48

59
binary_name = terraform-provider-gitlabci
610

@@ -10,13 +14,14 @@ build: $(binary_name)
1014

1115
$(binary_name): $(sources)
1216
go build .
17+
rm -f .terraform.lock.hcl
1318

1419
test: $(binary_name)
1520
go test `go list ./...`
1621

1722
clean:
18-
rm -f $(binary_name) predefined_variables.md vars-data
19-
rm -rf terraform.d/
23+
rm -f $(binary_name) predefined_variables.md vars-data .terraform.lock.hcl
24+
rm -rf terraform.d/ .terraform/
2025

2126
fmt:
2227
gofmt -w $(GOFMT_FILES)
@@ -33,6 +38,39 @@ vet:
3338
gen:
3439
go generate
3540

41+
$(docs): $(doc_sources)
42+
go generate
43+
44+
# generate docs if templates have been changed
45+
docs: $(docs)
46+
47+
docs-commit: $(docs)
48+
git add -A docs/
49+
git commit -m 'Update generated docs' -- docs/
50+
51+
gen-third-party: gen-runner-structs
52+
53+
runner_structs_tools = $(wildcard tools/centrifuge/*.go)
54+
runner_structs_files = $(wildcard third_party/**/*.go)
55+
56+
third-party: $(runner_structs_files)
57+
git diff -- third_party/
58+
59+
$(runner_structs_files): $(runner_structs_tools)
60+
# go run ./tools/centrifuge/*.go
61+
go run $(runner_structs_tools)
62+
git diff -- third_party/
63+
64+
gen-runner-structs:
65+
# go run ./tools/centrifuge/*.go
66+
go run $(runner_structs_tools)
67+
git diff -- third_party/
68+
69+
gen-schema:
70+
go run ./tools/config-schema-gen/*.go
71+
72+
.PHONY: gen-schema gen-runner-structs gen
73+
3674
# convenience targets for development
3775

3876
tfa: $(binary_name)
@@ -42,11 +80,13 @@ tfp: $(binary_name)
4280
terraform init && TF_LOG=TRACE terraform plan
4381

4482
local: $(local_bin)
45-
echo
4683

4784
init: $(local_bin)
4885
terraform init
4986

87+
plan:
88+
terraform plan
89+
5090
$(local_bin): $(binary_name)
5191
mkdir -p $(dir $@)
5292
cp $(binary_name) $@
@@ -66,4 +106,4 @@ env-ds-struct: vars-data
66106
env-ds-set: vars-data
67107
@cat $< | sed -e 's/^ `//; s/`.*//' | perl -nE 'chomp; say qq{d.Set("} . lc($$_) . qq{", os.Getenv("$$_"))}'
68108

69-
.PHONY: build clean ci-datasource fmt vet tfa tfp test
109+
.PHONY: build clean fmt vet tfa tfp test

docs/data-sources/runner_config.md

Lines changed: 1079 additions & 0 deletions
Large diffs are not rendered by default.

docs/index.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ layout: ""
33
page_title: "gitlabci Provider"
44
subcategory: ""
55
description: |-
6-
The GitLabCI provider allows the trivial creation of a runner token.
6+
The GitLabCI provider allows the trivial creation of runner tokens and
7+
configuration.
78
---
89

910
# GitLabCI Provider
@@ -17,6 +18,11 @@ specific user.
1718
For more information, please see the [Registering a
1819
runner](guides/registering-a-runner) guide.
1920

21+
This provider also provides data sources related to GitLab CI, including
22+
[`gitlabci_runner_config`](data-sources/runner_config), a data source allowing
23+
runner configuration to be generated (much as, say, the AWS provider's
24+
`aws_iam_policy_document` does for IAM policies).
25+
2026
For a general-purpose provider (that includes the ability to look up
2127
registration tokens), please see the [GitLab terraform
2228
provider](https://www.terraform.io/docs/providers/gitlab/).

docs/resources/runner_token.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,30 @@ result in the resource being destroyed and recreated.
3030
See the [Registering a runner](https://registry.terraform.io/providers/rsrchboy/gitlabci/latest/docs/guides/registering-a-runner)
3131
guide for more information.
3232

33+
## Example Usage
3334

35+
```terraform
36+
resource "gitlabci_runner_token" "this" {
37+
registration_token = var.registration_token
38+
locked = true
39+
tags = [
40+
"jinx",
41+
"powder",
42+
"cupcake",
43+
]
44+
}
45+
46+
variable "registration_token" {
47+
type = string
48+
description = "Runner registration token"
49+
sensitive = true
50+
}
51+
52+
output "token" {
53+
sensitive = true
54+
value = gitlabci_runner_token.this.token
55+
}
56+
```
3457

3558
<!-- schema generated by tfplugindocs -->
3659
## Schema
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
data "gitlab_project" "this" {
2+
id = var.project_id
3+
}
4+
5+
resource "gitlabci_runner_token" "this" {
6+
registration_token = data.gitlab_project.this.runners_token
7+
locked = true
8+
tags = ["jinx", "powder", "cupcake"]
9+
}
10+
11+
data "gitlabci_runner_config" "this" {
12+
log_format = "json"
13+
runners {
14+
url = "https://gitlab.com"
15+
token = gitlabci_runner_token.this.token
16+
# ...
17+
}
18+
}
19+
20+
resource "local_file" "this" {
21+
filename = "${path.module}/config.toml"
22+
content = data.gitlabci_runner_config.this.config
23+
}
24+
25+
output "config" {
26+
description = "Our generated runner configuration"
27+
value = data.gitlabci_runner_config.this.config
28+
}
29+
30+
variable "project_id" {
31+
# note this could also legitimately be an int; see
32+
# https://registry.terraform.io/providers/gitlabhq/gitlab/latest/docs/data-sources/project#id
33+
type = string
34+
description = "Project ID (path, e.g. rsrchboy/scratch)"
35+
}
36+

go.mod

Lines changed: 35 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,41 @@ module gitlab.com/rsrchboy/terraform-provider-gitlabci
33
go 1.17
44

55
require (
6+
github.com/BurntSushi/toml v1.0.0
7+
github.com/Masterminds/sprig/v3 v3.2.2
8+
github.com/giantswarm/to v0.4.0
69
github.com/hashicorp/terraform-plugin-docs v0.5.1
10+
github.com/hashicorp/terraform-plugin-log v0.2.1
11+
github.com/hashicorp/terraform-plugin-sdk v1.17.2
712
github.com/hashicorp/terraform-plugin-sdk/v2 v2.10.1
13+
github.com/imdario/mergo v0.3.12
814
github.com/parnurzeal/gorequest v0.2.16
15+
github.com/pkg/errors v0.9.1
916
github.com/spf13/pflag v1.0.5
17+
github.com/stoewer/go-strcase v1.2.0
18+
golang.org/x/tools v0.1.5
1019
)
1120

1221
require (
13-
cloud.google.com/go v0.61.0 // indirect
22+
cloud.google.com/go v0.81.0 // indirect
1423
cloud.google.com/go/storage v1.10.0 // indirect
15-
github.com/Masterminds/goutils v1.1.0 // indirect
24+
github.com/Masterminds/goutils v1.1.1 // indirect
1625
github.com/Masterminds/semver v1.5.0 // indirect
26+
github.com/Masterminds/semver/v3 v3.1.1 // indirect
1727
github.com/Masterminds/sprig v2.22.0+incompatible // indirect
28+
github.com/Microsoft/go-winio v0.4.17 // indirect
1829
github.com/agext/levenshtein v1.2.3 // indirect
1930
github.com/apparentlymart/go-textseg/v13 v13.0.0 // indirect
2031
github.com/armon/go-radix v1.0.0 // indirect
21-
github.com/aws/aws-sdk-go v1.25.3 // indirect
32+
github.com/aws/aws-sdk-go v1.37.0 // indirect
2233
github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d // indirect
2334
github.com/bgentry/speakeasy v0.1.0 // indirect
2435
github.com/elazarl/goproxy v0.0.0-20191011121108-aa519ddbe484 // indirect
2536
github.com/fatih/color v1.13.0 // indirect
26-
github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e // indirect
37+
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
2738
github.com/golang/protobuf v1.5.2 // indirect
28-
github.com/google/go-cmp v0.5.6 // indirect
29-
github.com/google/uuid v1.1.2 // indirect
39+
github.com/google/go-cmp v0.5.7 // indirect
40+
github.com/google/uuid v1.2.0 // indirect
3041
github.com/googleapis/gax-go/v2 v2.0.5 // indirect
3142
github.com/hashicorp/errwrap v1.1.0 // indirect
3243
github.com/hashicorp/go-checkpoint v0.5.0 // indirect
@@ -42,16 +53,14 @@ require (
4253
github.com/hashicorp/hcl/v2 v2.11.1 // indirect
4354
github.com/hashicorp/terraform-exec v0.15.0 // indirect
4455
github.com/hashicorp/terraform-json v0.13.0 // indirect
45-
github.com/hashicorp/terraform-plugin-go v0.5.0 // indirect
46-
github.com/hashicorp/terraform-plugin-log v0.2.1 // indirect
56+
github.com/hashicorp/terraform-plugin-go v0.7.0 // indirect
4757
github.com/hashicorp/terraform-registry-address v0.0.0-20210816115301-cb2034eba045 // indirect
4858
github.com/hashicorp/terraform-svchost v0.0.0-20200729002733-f050f53b9734 // indirect
4959
github.com/hashicorp/yamux v0.0.0-20211028200310-0bc27b27de87 // indirect
5060
github.com/huandu/xstrings v1.3.2 // indirect
51-
github.com/imdario/mergo v0.3.12 // indirect
52-
github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af // indirect
61+
github.com/jmespath/go-jmespath v0.4.0 // indirect
5362
github.com/jstemmer/go-junit-report v0.9.1 // indirect
54-
github.com/klauspost/compress v1.11.2 // indirect
63+
github.com/klauspost/compress v1.11.13 // indirect
5564
github.com/mattn/go-colorable v0.1.12 // indirect
5665
github.com/mattn/go-isatty v0.0.14 // indirect
5766
github.com/mitchellh/cli v1.1.2 // indirect
@@ -62,27 +71,31 @@ require (
6271
github.com/mitchellh/mapstructure v1.4.3 // indirect
6372
github.com/mitchellh/reflectwalk v1.0.2 // indirect
6473
github.com/oklog/run v1.1.0 // indirect
65-
github.com/pkg/errors v0.9.1 // indirect
6674
github.com/posener/complete v1.2.1 // indirect
6775
github.com/russross/blackfriday v1.6.0 // indirect
76+
github.com/shopspring/decimal v1.2.0 // indirect
6877
github.com/smartystreets/goconvey v1.6.4 // indirect
78+
github.com/spf13/cast v1.3.1 // indirect
6979
github.com/ulikunitz/xz v0.5.8 // indirect
7080
github.com/vmihailenco/msgpack v4.0.4+incompatible // indirect
81+
github.com/vmihailenco/msgpack/v4 v4.3.12 // indirect
82+
github.com/vmihailenco/tagparser v0.1.2 // indirect
7183
github.com/zclconf/go-cty v1.10.0 // indirect
72-
go.opencensus.io v0.22.4 // indirect
73-
golang.org/x/crypto v0.0.0-20210616213533-5ff15b29337e // indirect
74-
golang.org/x/lint v0.0.0-20200302205851-738671d3881b // indirect
75-
golang.org/x/mod v0.3.0 // indirect
76-
golang.org/x/net v0.0.0-20220111093109-d55c255bac03 // indirect
77-
golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d // indirect
78-
golang.org/x/sys v0.0.0-20220111092808-5a964db01320 // indirect
84+
go.opencensus.io v0.23.0 // indirect
85+
golang.org/x/crypto v0.0.0-20210817164053-32db794688a5 // indirect
86+
golang.org/x/lint v0.0.0-20201208152925-83fdc39ff7b5 // indirect
87+
golang.org/x/mod v0.4.2 // indirect
88+
golang.org/x/net v0.0.0-20220121210141-e204ce36a2ba // indirect
89+
golang.org/x/oauth2 v0.0.0-20210819190943-2bc19b11175f // indirect
90+
golang.org/x/sys v0.0.0-20220114195835-da31bd327af9 // indirect
7991
golang.org/x/text v0.3.7 // indirect
80-
golang.org/x/tools v0.0.0-20200713011307-fd294ab11aed // indirect
8192
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
82-
google.golang.org/api v0.29.0 // indirect
93+
google.golang.org/api v0.43.0 // indirect
8394
google.golang.org/appengine v1.6.7 // indirect
84-
google.golang.org/genproto v0.0.0-20220112215332-a9c7c0acf9f2 // indirect
95+
google.golang.org/genproto v0.0.0-20220118154757-00ab72f36ad5 // indirect
8596
google.golang.org/grpc v1.43.0 // indirect
8697
google.golang.org/protobuf v1.27.1 // indirect
98+
gopkg.in/yaml.v2 v2.4.0 // indirect
99+
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
87100
moul.io/http2curl v1.0.0 // indirect
88101
)

0 commit comments

Comments
 (0)