Skip to content

Commit 2b45f98

Browse files
SarahFrenchansgarm
andauthored
Update how code is generated from .proto files (#566)
* go get google.golang.org/genproto * go get github.com/hashicorp/[email protected] * go mod tidy * Copy approach for generating code from proto files from hashicorp/terraform * Add use of Go workspace to let Makefile run Go code in ./tools * Fix to where code is generated to * Update script to match the current version of protoc used * switch to MPL-2.0 licensed version of this tool from Terraform v1.5 MPL licensed source: https://github.com/hashicorp/terraform/blob/7111fd1170c90b2b05aae61e7c89cc812dd7ca7b/tools/protobuf-compile/protobuf-compile.go * re-adjust generation to plugin-go Co-authored-by: Sarah French <[email protected]> * Fix the terraform-provider-corner-tfprotov5 tests * Fix the terraform-provider-corner-tfprotov6 tests * Change how diffing GHA downloads protoc * go mod download * Update README * Update description & instructions related to reusable proto files * Remove `protoc` and `tools` targets in Makefile, simplify README --------- Co-authored-by: Ansgar Mertens <[email protected]>
1 parent a361c9b commit 2b45f98

File tree

10 files changed

+2062
-81
lines changed

10 files changed

+2062
-81
lines changed

.github/workflows/ci-go.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ jobs:
4141
with:
4242
terraform_version: ${{ matrix.terraform }}
4343
terraform_wrapper: false
44+
- run: go work use ../terraform-provider-corner
4445
- run: go mod edit -replace github.com/hashicorp/terraform-plugin-go=../
4546
- run: go mod tidy
4647
- run: go test -v ./internal/protocolprovider
@@ -74,6 +75,7 @@ jobs:
7475
with:
7576
terraform_version: ${{ matrix.terraform }}
7677
terraform_wrapper: false
78+
- run: go work use ../terraform-provider-corner
7779
- run: go mod edit -replace github.com/hashicorp/terraform-plugin-go=../
7880
- run: go mod tidy
7981
- run: go test -v ./internal/framework6provider

.github/workflows/ci-protobuf.yml

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,8 @@ jobs:
2323
- uses: actions/setup-go@44694675825211faa026b3c33043df3e48a5fa00 # v6.0.0
2424
with:
2525
go-version-file: 'go.mod'
26-
- uses: arduino/setup-protoc@c65c819552d16ad3c9b72d9dfd5ba5237b9c906b # v3.0.0
27-
with:
28-
# The version string is embedded in protoc generated files, so it is
29-
# pinned here to prevent unexpected differences. Follow the
30-
# https://github.com/protocolbuffers/protobuf repository for protoc
31-
# release updates.
32-
version: '29.3'
33-
repo-token: ${{ secrets.GITHUB_TOKEN }}
3426
- run: go mod download
35-
- run: make tools
36-
- run: make protoc
27+
- run: make protobuf
3728
- name: git diff
3829
run: |
3930
git diff --compact-summary --exit-code || \

Makefile

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,29 +3,10 @@ default: test
33
lint:
44
golangci-lint run ./...
55

6-
tools:
7-
go install google.golang.org/protobuf/cmd/protoc-gen-go
8-
cd tools; go install google.golang.org/grpc/cmd/protoc-gen-go-grpc
9-
106
# Protocol Buffers compilation is done outside of 'go generate' handling since
117
# the 'protoc' tool is not installable via 'go install'.
12-
protoc:
13-
@cd tfprotov5/internal/tfplugin5 && \
14-
protoc \
15-
--proto_path=. \
16-
--go_out=. \
17-
--go_opt=paths=source_relative \
18-
--go-grpc_out=. \
19-
--go-grpc_opt=paths=source_relative \
20-
tfplugin5.proto
21-
@cd tfprotov6/internal/tfplugin6 && \
22-
protoc \
23-
--proto_path=. \
24-
--go_out=. \
25-
--go_opt=paths=source_relative \
26-
--go-grpc_out=. \
27-
--go-grpc_opt=paths=source_relative \
28-
tfplugin6.proto
8+
protobuf:
9+
go run ./tools/protobuf-compile .
2910

3011
test:
3112
go test ./...

README.md

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -177,16 +177,9 @@ Run `golangci-lint run ./...` or `make lint` after any changes.
177177

178178
### Protocol Updates
179179

180-
Ensure the following tooling is installed:
181-
182-
- [`protoc`](https://github.com/protocolbuffers/protobuf): Protocol Buffers compiler. This isn't Go specific tooling, so follow this [installation guide](https://github.com/protocolbuffers/protobuf#protobuf-compiler-installation)
183-
- The Terraform Plugin Protocol uses well-known types (`Timestamp`), so be sure to copy the `include` directory to a folder included in your `PATH` (for example, on MacOS, `/usr/local/include`).
184-
- [`protoc-gen-go`](https://pkg.go.dev/google.golang.org/protobuf/cmd/protoc-gen-go): Go plugin for Protocol Buffers compiler. Install by running `make tools`
185-
- [`protoc-gen-go-grpc`](https://pkg.go.dev/google.golang.org/grpc/cmd/protoc-gen-go-grpc): Go gRPC plugin for Protocol Buffers compiler. Install by running `make tools`
186-
187-
The Protocol Buffers definitions can be found in `tfprotov5/internal/tfplugin5` and `tfprotov6/internal/tfplugin6`.
180+
Run `make protobuf` to install the necessary tooling and to recompile the Protocol Buffers files after any changes.
188181

189-
Run `make protoc` to recompile the Protocol Buffers files after any changes.
182+
The `make protobuf` command uses a script in `./tools/protobuf-compile` to compile the Go code using the Protocol Buffers defined in `tfprotov5/internal/tfplugin5` and `tfprotov6/internal/tfplugin6`. Before generating the code, the script will download `protoc` and build binaries for `protoc-gen-go` and `protoc-gen-go-grpc` using the Go toolchain. This tooling will be saved into a gitignored location in that directory, so it's easy to know which tooling versions are in use when making protocol changes.
190183

191184
## License
192185

go.work

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
go 1.24.4
2+
3+
use (
4+
.
5+
./tools
6+
)

go.work.sum

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

tools/go.mod

Lines changed: 59 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,65 +6,109 @@ toolchain go1.24.4
66

77
require (
88
github.com/hashicorp/copywrite v0.22.0
9+
github.com/hashicorp/go-getter v1.7.8
910
google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.5.1
1011
)
1112

1213
require (
14+
cel.dev/expr v0.24.0 // indirect
15+
cloud.google.com/go v0.120.0 // indirect
16+
cloud.google.com/go/auth v0.16.0 // indirect
17+
cloud.google.com/go/auth/oauth2adapt v0.2.8 // indirect
18+
cloud.google.com/go/compute/metadata v0.7.0 // indirect
19+
cloud.google.com/go/iam v1.5.2 // indirect
20+
cloud.google.com/go/monitoring v1.24.2 // indirect
21+
cloud.google.com/go/storage v1.50.0 // indirect
1322
github.com/AlecAivazis/survey/v2 v2.3.7 // indirect
23+
github.com/GoogleCloudPlatform/opentelemetry-operations-go/detectors/gcp v1.27.0 // indirect
24+
github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/metric v0.50.0 // indirect
25+
github.com/GoogleCloudPlatform/opentelemetry-operations-go/internal/resourcemapping v0.50.0 // indirect
1426
github.com/ProtonMail/go-crypto v0.0.0-20230217124315-7d5c6f04bbb8 // indirect
1527
github.com/asaskevich/govalidator v0.0.0-20200907205600-7a23bdc65eef // indirect
28+
github.com/aws/aws-sdk-go v1.44.122 // indirect
29+
github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d // indirect
1630
github.com/bmatcuk/doublestar/v4 v4.6.0 // indirect
1731
github.com/bradleyfalzon/ghinstallation/v2 v2.5.0 // indirect
32+
github.com/cespare/xxhash/v2 v2.3.0 // indirect
1833
github.com/cli/go-gh/v2 v2.12.1 // indirect
1934
github.com/cli/safeexec v1.0.0 // indirect
2035
github.com/cloudflare/circl v1.6.1 // indirect
36+
github.com/cncf/xds/go v0.0.0-20250501225837-2ac532fd4443 // indirect
37+
github.com/envoyproxy/go-control-plane/envoy v1.32.4 // indirect
38+
github.com/envoyproxy/protoc-gen-validate v1.2.1 // indirect
2139
github.com/fatih/color v1.15.0 // indirect
40+
github.com/felixge/httpsnoop v1.0.4 // indirect
2241
github.com/fsnotify/fsnotify v1.5.4 // indirect
42+
github.com/go-jose/go-jose/v4 v4.0.5 // indirect
43+
github.com/go-logr/logr v1.4.3 // indirect
44+
github.com/go-logr/stdr v1.2.2 // indirect
2345
github.com/go-openapi/errors v0.20.2 // indirect
2446
github.com/go-openapi/strfmt v0.21.3 // indirect
2547
github.com/golang-jwt/jwt/v4 v4.5.2 // indirect
26-
github.com/google/go-cmp v0.6.0 // indirect
2748
github.com/google/go-github/v45 v45.2.0 // indirect
2849
github.com/google/go-github/v53 v53.0.0 // indirect
2950
github.com/google/go-querystring v1.1.0 // indirect
51+
github.com/google/s2a-go v0.1.9 // indirect
52+
github.com/google/uuid v1.6.0 // indirect
53+
github.com/googleapis/enterprise-certificate-proxy v0.3.6 // indirect
54+
github.com/googleapis/gax-go/v2 v2.14.1 // indirect
55+
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
3056
github.com/hashicorp/go-hclog v1.5.0 // indirect
57+
github.com/hashicorp/go-safetemp v1.0.0 // indirect
58+
github.com/hashicorp/go-version v1.6.0 // indirect
3159
github.com/hashicorp/hcl v1.0.0 // indirect
3260
github.com/inconshreveable/mousetrap v1.0.1 // indirect
3361
github.com/jedib0t/go-pretty v4.3.0+incompatible // indirect
3462
github.com/jedib0t/go-pretty/v6 v6.4.6 // indirect
63+
github.com/jmespath/go-jmespath v0.4.0 // indirect
3564
github.com/joho/godotenv v1.3.0 // indirect
3665
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect
66+
github.com/klauspost/compress v1.15.11 // indirect
3767
github.com/knadh/koanf v1.5.0 // indirect
38-
github.com/kr/pretty v0.3.1 // indirect
3968
github.com/mattn/go-colorable v0.1.13 // indirect
4069
github.com/mattn/go-isatty v0.0.20 // indirect
4170
github.com/mattn/go-runewidth v0.0.16 // indirect
4271
github.com/mergestat/timediff v0.0.3 // indirect
4372
github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d // indirect
4473
github.com/mitchellh/copystructure v1.2.0 // indirect
4574
github.com/mitchellh/go-homedir v1.1.0 // indirect
75+
github.com/mitchellh/go-testing-interface v1.14.1 // indirect
4676
github.com/mitchellh/mapstructure v1.5.0 // indirect
4777
github.com/mitchellh/reflectwalk v1.0.2 // indirect
4878
github.com/oklog/ulid v1.3.1 // indirect
79+
github.com/planetscale/vtprotobuf v0.6.1-0.20240319094008-0393e58bdf10 // indirect
4980
github.com/rivo/uniseg v0.4.7 // indirect
50-
github.com/rogpeppe/go-internal v1.10.0 // indirect
5181
github.com/samber/lo v1.37.0 // indirect
52-
github.com/spf13/afero v1.10.0 // indirect
5382
github.com/spf13/cobra v1.6.1 // indirect
5483
github.com/spf13/pflag v1.0.5 // indirect
55-
github.com/stretchr/testify v1.9.0 // indirect
84+
github.com/spiffe/go-spiffe/v2 v2.5.0 // indirect
5685
github.com/thanhpk/randstr v1.0.4 // indirect
86+
github.com/ulikunitz/xz v0.5.10 // indirect
87+
github.com/zeebo/errs v1.4.0 // indirect
5788
go.mongodb.org/mongo-driver v1.10.0 // indirect
58-
golang.org/x/crypto v0.36.0 // indirect
89+
go.opentelemetry.io/auto/sdk v1.1.0 // indirect
90+
go.opentelemetry.io/contrib/detectors/gcp v1.36.0 // indirect
91+
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.60.0 // indirect
92+
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.60.0 // indirect
93+
go.opentelemetry.io/otel v1.36.0 // indirect
94+
go.opentelemetry.io/otel/metric v1.36.0 // indirect
95+
go.opentelemetry.io/otel/sdk v1.36.0 // indirect
96+
go.opentelemetry.io/otel/sdk/metric v1.36.0 // indirect
97+
go.opentelemetry.io/otel/trace v1.36.0 // indirect
98+
golang.org/x/crypto v0.41.0 // indirect
5999
golang.org/x/exp v0.0.0-20231006140011-7918f672742d // indirect
60-
golang.org/x/net v0.38.0 // indirect
61-
golang.org/x/oauth2 v0.27.0 // indirect
62-
golang.org/x/sync v0.12.0 // indirect
63-
golang.org/x/sys v0.31.0 // indirect
64-
golang.org/x/term v0.30.0 // indirect
65-
golang.org/x/text v0.23.0 // indirect
66-
google.golang.org/genproto/googleapis/rpc v0.0.0-20240903143218-8af14fe29dc1 // indirect
67-
google.golang.org/grpc v1.66.0 // indirect
68-
google.golang.org/protobuf v1.34.2 // indirect
100+
golang.org/x/net v0.43.0 // indirect
101+
golang.org/x/oauth2 v0.30.0 // indirect
102+
golang.org/x/sync v0.16.0 // indirect
103+
golang.org/x/sys v0.35.0 // indirect
104+
golang.org/x/term v0.34.0 // indirect
105+
golang.org/x/text v0.28.0 // indirect
106+
golang.org/x/time v0.11.0 // indirect
107+
google.golang.org/api v0.229.0 // indirect
108+
google.golang.org/genproto v0.0.0-20250908214217-97024824d090 // indirect
109+
google.golang.org/genproto/googleapis/api v0.0.0-20250826171959-ef028d996bc1 // indirect
110+
google.golang.org/genproto/googleapis/rpc v0.0.0-20250826171959-ef028d996bc1 // indirect
111+
google.golang.org/grpc v1.74.2 // indirect
112+
google.golang.org/protobuf v1.36.8 // indirect
69113
gopkg.in/yaml.v3 v3.0.1 // indirect
70114
)

0 commit comments

Comments
 (0)