Skip to content
This repository has been archived by the owner on Jun 4, 2024. It is now read-only.

Commit

Permalink
terraform: access list support (#916)
Browse files Browse the repository at this point in the history
This PR adds access list support to the Terraform provider. Since we
stopped using gogoproto, generating new resources became increasingly
complex.

The access list terraform schema was generated from the protobuf types
and not the ones in `api/types`, which causes all kind of small oddities
from a user PoV, and made this PR way more complex.

User-facing limitations:
- the `metadata` field is nested under the `header` one because of the
  protobuf structure
- the traits is not a map but a list of structs, each struct with a key
  and a value attribute

Non user-facing limitations the PR had to work around:
- the protobuf time is different from go's time, I initially wanted to
  create `ProtoTimeType`/`ProtoTimeValue` but we cannot embbed a
  protobuf timestamp directly (because it contains a lock, the terraform
  value must be a reference, which is not supported by the protoc
  generator). The workaround is to use custom types (`Timestamp` and
  `Duration`).
- the provider has to do the conversion between the proto type and the
  api/type.
- The time type difference caused conversion issues fixed by
  gravitational/teleport#32135
  • Loading branch information
hugoShaka authored Sep 27, 2023
1 parent 68a52ad commit bbc3714
Show file tree
Hide file tree
Showing 42 changed files with 3,874 additions and 454 deletions.
10 changes: 9 additions & 1 deletion terraform/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,19 @@ endif
--terraform_out=config=protoc-gen-terraform-devicetrust.yaml:./tfschema \
teleport/legacy/types/device.proto

@go run ./gen/main.go
@protoc \
-I$(API_MOD_PATH)/proto \
-I$(PROTOBUF_MOD_PATH) \
--plugin=$(GENTERRAFORMPATH)/protoc-gen-terraform \
--terraform_out=config=protoc-gen-terraform-accesslist.yaml:./tfschema \
teleport/accesslist/v1/accesslist.proto

mv ./tfschema/github.com/gravitational/teleport/api/types/types_terraform.go ./tfschema/
mv ./tfschema/github.com/gravitational/teleport/api/gen/proto/go/teleport/loginrule/v1/loginrule_terraform.go ./tfschema/loginrule/v1/
mv ./tfschema/github.com/gravitational/teleport/api/gen/proto/go/teleport/accesslist/v1/accesslist_terraform.go ./tfschema/accesslist/v1/
mv ./tfschema/github.com/gravitational/teleport/api/types/device_terraform.go ./tfschema/devicetrust/v1/
rm -r ./tfschema/github.com/
@go run ./gen/main.go
@go run ./gen/main.go docs

.PHONY: release
Expand Down
36 changes: 36 additions & 0 deletions terraform/example/access_list.tf.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
resource "teleport_access_list" "crane-operation" {
header = {
metadata = {
name = "crane-operation"
labels = {
example = "yes"
}
}
}
spec = {
description = "Used to grant access to the crane."
owners = [
{
name = "gru"
description = "The supervillain."
}
]
membership_requires = {
roles = ["minion"]
}
ownership_requires = {
roles = ["supervillain"]
}
grants = {
roles = ["crane-operator"]
traits = [{
key = "allowed-machines"
values = ["crane", "forklift"]
}]
}
title = "Crane operation"
audit = {
frequency = "3600h" // 150 days
}
}
}
1 change: 1 addition & 0 deletions terraform/example/terraform.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ spec:
- login_rule
- device
- okta_import_rule
- access_list
verbs: ['list','create','read','update','delete']
version: v6
---
Expand Down
Loading

0 comments on commit bbc3714

Please sign in to comment.