-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for WorkloadIdentity resource to the Teleport Terraform P…
…rovider (#50382) * First pass at trying to generate terraform provider * Wire up types * Fix generation of docs * Add godoc comments * Add tests * Tflint and add example
- Loading branch information
1 parent
b1b6bb2
commit 3796023
Showing
17 changed files
with
2,124 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
docs/pages/reference/terraform-provider/data-sources/workload_identity.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
--- | ||
title: Reference for the teleport_workload_identity Terraform data-source | ||
sidebar_label: workload_identity | ||
description: This page describes the supported values of the teleport_workload_identity data-source of the Teleport Terraform provider. | ||
--- | ||
|
||
{/*Auto-generated file. Do not edit.*/} | ||
{/*To regenerate, navigate to integrations/terraform and run `make docs`.*/} | ||
|
||
|
||
|
||
|
||
|
||
{/* schema generated by tfplugindocs */} | ||
## Schema | ||
|
||
### Optional | ||
|
||
- `metadata` (Attributes) Common metadata that all resources share. (see [below for nested schema](#nested-schema-for-metadata)) | ||
- `spec` (Attributes) The configured properties of the WorkloadIdentity (see [below for nested schema](#nested-schema-for-spec)) | ||
- `sub_kind` (String) Differentiates variations of the same kind. All resources should contain one, even if it is never populated. | ||
- `version` (String) The version of the resource being represented. | ||
|
||
### Nested Schema for `metadata` | ||
|
||
Optional: | ||
|
||
- `description` (String) description is object description. | ||
- `expires` (String) expires is a global expiry time header can be set on any resource in the system. | ||
- `labels` (Map of String) labels is a set of labels. | ||
- `name` (String) name is an object name. | ||
|
||
|
||
### Nested Schema for `spec` | ||
|
||
Optional: | ||
|
||
- `rules` (Attributes) The rules which are evaluated before the WorkloadIdentity can be issued. (see [below for nested schema](#nested-schema-for-specrules)) | ||
- `spiffe` (Attributes) Configuration pertaining to the issuance of SPIFFE-compatible workload identity credentials. (see [below for nested schema](#nested-schema-for-specspiffe)) | ||
|
||
### Nested Schema for `spec.rules` | ||
|
||
Optional: | ||
|
||
- `allow` (Attributes List) A list of rules used to determine if a WorkloadIdentity can be issued. If none are provided, it will be considered a pass. If any are provided, then at least one must pass for the rules to be considered passed. (see [below for nested schema](#nested-schema-for-specrulesallow)) | ||
|
||
### Nested Schema for `spec.rules.allow` | ||
|
||
Optional: | ||
|
||
- `conditions` (Attributes List) The conditions that must be met for this rule to be considered passed. (see [below for nested schema](#nested-schema-for-specrulesallowconditions)) | ||
|
||
### Nested Schema for `spec.rules.allow.conditions` | ||
|
||
Optional: | ||
|
||
- `attribute` (String) The name of the attribute to evaluate the condition against. | ||
- `equals` (String) An exact string that the attribute must match. | ||
|
||
|
||
|
||
|
||
### Nested Schema for `spec.spiffe` | ||
|
||
Optional: | ||
|
||
- `hint` (String) A freeform text field which is provided to workloads along with a credential produced by this WorkloadIdentity. This can be used to provide additional context that can be used to select between multiple credentials. | ||
- `id` (String) The path of the SPIFFE ID that will be issued to the workload. This should be prefixed with a forward-slash ("/"). This field supports templating using attributes. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
94 changes: 94 additions & 0 deletions
94
docs/pages/reference/terraform-provider/resources/workload_identity.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
--- | ||
title: Reference for the teleport_workload_identity Terraform resource | ||
sidebar_label: workload_identity | ||
description: This page describes the supported values of the teleport_workload_identity resource of the Teleport Terraform provider. | ||
--- | ||
|
||
{/*Auto-generated file. Do not edit.*/} | ||
{/*To regenerate, navigate to integrations/terraform and run `make docs`.*/} | ||
|
||
|
||
|
||
## Example Usage | ||
|
||
```hcl | ||
resource "teleport_workload_identity" "example" { | ||
version = "v1" | ||
metadata = { | ||
name = "example" | ||
} | ||
spec = { | ||
rules = { | ||
allow = [ | ||
{ | ||
conditions = [{ | ||
attribute = "user.name" | ||
equals = "noah" | ||
}] | ||
} | ||
] | ||
} | ||
spiffe = { | ||
id = "/my/spiffe/id/path" | ||
hint = "my-hint" | ||
} | ||
} | ||
} | ||
``` | ||
|
||
{/* schema generated by tfplugindocs */} | ||
## Schema | ||
|
||
### Optional | ||
|
||
- `metadata` (Attributes) Common metadata that all resources share. (see [below for nested schema](#nested-schema-for-metadata)) | ||
- `spec` (Attributes) The configured properties of the WorkloadIdentity (see [below for nested schema](#nested-schema-for-spec)) | ||
- `sub_kind` (String) Differentiates variations of the same kind. All resources should contain one, even if it is never populated. | ||
- `version` (String) The version of the resource being represented. | ||
|
||
### Nested Schema for `metadata` | ||
|
||
Optional: | ||
|
||
- `description` (String) description is object description. | ||
- `expires` (String) expires is a global expiry time header can be set on any resource in the system. | ||
- `labels` (Map of String) labels is a set of labels. | ||
- `name` (String) name is an object name. | ||
|
||
|
||
### Nested Schema for `spec` | ||
|
||
Optional: | ||
|
||
- `rules` (Attributes) The rules which are evaluated before the WorkloadIdentity can be issued. (see [below for nested schema](#nested-schema-for-specrules)) | ||
- `spiffe` (Attributes) Configuration pertaining to the issuance of SPIFFE-compatible workload identity credentials. (see [below for nested schema](#nested-schema-for-specspiffe)) | ||
|
||
### Nested Schema for `spec.rules` | ||
|
||
Optional: | ||
|
||
- `allow` (Attributes List) A list of rules used to determine if a WorkloadIdentity can be issued. If none are provided, it will be considered a pass. If any are provided, then at least one must pass for the rules to be considered passed. (see [below for nested schema](#nested-schema-for-specrulesallow)) | ||
|
||
### Nested Schema for `spec.rules.allow` | ||
|
||
Optional: | ||
|
||
- `conditions` (Attributes List) The conditions that must be met for this rule to be considered passed. (see [below for nested schema](#nested-schema-for-specrulesallowconditions)) | ||
|
||
### Nested Schema for `spec.rules.allow.conditions` | ||
|
||
Optional: | ||
|
||
- `attribute` (String) The name of the attribute to evaluate the condition against. | ||
- `equals` (String) An exact string that the attribute must match. | ||
|
||
|
||
|
||
|
||
### Nested Schema for `spec.spiffe` | ||
|
||
Optional: | ||
|
||
- `hint` (String) A freeform text field which is provided to workloads along with a credential produced by this WorkloadIdentity. This can be used to provide additional context that can be used to select between multiple credentials. | ||
- `id` (String) The path of the SPIFFE ID that will be issued to the workload. This should be prefixed with a forward-slash ("/"). This field supports templating using attributes. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
integrations/terraform/examples/resources/teleport_workload_identity/resource.tf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
resource "teleport_workload_identity" "example" { | ||
version = "v1" | ||
metadata = { | ||
name = "example" | ||
} | ||
spec = { | ||
rules = { | ||
allow = [ | ||
{ | ||
conditions = [{ | ||
attribute = "user.name" | ||
equals = "noah" | ||
}] | ||
} | ||
] | ||
} | ||
spiffe = { | ||
id = "/my/spiffe/id/path" | ||
hint = "my-hint" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
integrations/terraform/protoc-gen-terraform-workloadidentity.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
--- | ||
target_package_name: "v1" | ||
default_package_name: "github.com/gravitational/teleport/api/gen/proto/go/teleport/workloadidentity/v1" | ||
duration_custom_type: Duration | ||
use_state_for_unknown_by_default: true | ||
|
||
# Top-level type names to export | ||
types: | ||
- "WorkloadIdentity" | ||
|
||
# These import paths were not being automatically picked up by | ||
# protoc-gen-terraform without these overrides | ||
import_path_overrides: | ||
"types": "github.com/gravitational/teleport/api/types" | ||
"wrappers": "github.com/gravitational/teleport/api/types/wrappers" | ||
"durationpb": "google.golang.org/protobuf/types/known/durationpb" | ||
"timestamppb": "google.golang.org/protobuf/types/known/timestamppb" | ||
"structpb": "google.golang.org/protobuf/types/known/structpb" | ||
"v1": "github.com/gravitational/teleport/api/gen/proto/go/teleport/header/v1" | ||
"v11": "github.com/gravitational/teleport/api/gen/proto/go/teleport/label/v1" | ||
"github_com_gravitational_teleport_integrations_terraform_tfschema": "github.com/gravitational/teleport/integrations/terraform/tfschema" | ||
|
||
|
||
# id field is required for integration tests. It is not used by provider. | ||
# We have to add it manually (might be removed in the future versions). | ||
injected_fields: | ||
WorkloadIdentity: | ||
- name: id | ||
type: github.com/hashicorp/terraform-plugin-framework/types.StringType | ||
computed: true | ||
plan_modifiers: | ||
- "github.com/hashicorp/terraform-plugin-framework/tfsdk.UseStateForUnknown()" | ||
|
||
# These fields will be excluded | ||
exclude_fields: | ||
# Metadata (we id resources by name on our side) | ||
- "WorkloadIdentity.metadata.id" | ||
|
||
# These fields will be marked as Computed: true | ||
computed_fields: | ||
# Metadata | ||
- "WorkloadIdentity.metadata.namespace" | ||
- "WorkloadIdentity.kind" | ||
|
||
# These fields will be marked as Required: true | ||
required_fields: [] | ||
|
||
|
||
plan_modifiers: | ||
# Force to recreate resource if it's name changes | ||
Metadata.name: | ||
- "github.com/hashicorp/terraform-plugin-framework/tfsdk.RequiresReplace()" | ||
|
||
# This must be defined for the generator to be happy, but in reality all time | ||
# fields are overridden (because the protobuf timestamps contain locks and the | ||
# linter gets mad if we use raw structs instead of pointers). | ||
time_type: | ||
type: "PlaceholderType" | ||
duration_type: | ||
type: "PlaceholderType" | ||
|
||
validators: | ||
# Expires must be in the future | ||
Metadata.expires: | ||
- github_com_gravitational_teleport_integrations_terraform_tfschema.MustTimeBeInFuture() | ||
|
||
custom_types: | ||
"WorkloadIdentity.metadata.expires": Timestamp |
Oops, something went wrong.