Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[v15] tf-provider: fix bool option on gitlab token #41429

Merged
merged 2 commits into from
May 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion integrations/terraform/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,18 @@ endif
--terraform_out=config=protoc-gen-terraform-teleport.yaml:./tfschema \
teleport/legacy/types/types.proto

mv ./tfschema/github.com/gravitational/teleport/api/types/types_terraform.go ./tfschema/

@protoc \
-I=../../api/proto \
-I=$(PROTOBUF_MOD_PATH) \
--plugin=$(GENTERRAFORMPATH)/protoc-gen-terraform \
--terraform_out=config=protoc-gen-terraform-teleport-token.yaml:./tfschema \
teleport/legacy/types/types.proto

mkdir -p ./tfschema/token
mv ./tfschema/github.com/gravitational/teleport/api/types/types_terraform.go ./tfschema/token/

@protoc \
-I=../../api/proto \
-I=$(PROTOBUF_MOD_PATH) \
Expand All @@ -86,7 +98,6 @@ endif
--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/
Expand Down
5 changes: 4 additions & 1 deletion integrations/terraform/gen/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import (
accesslistSchema "github.com/gravitational/teleport/integrations/terraform/tfschema/accesslist/v1"
devicetrustSchema "github.com/gravitational/teleport/integrations/terraform/tfschema/devicetrust/v1"
loginruleSchema "github.com/gravitational/teleport/integrations/terraform/tfschema/loginrule/v1"
tokenSchema "github.com/gravitational/teleport/integrations/terraform/tfschema/token"
)

// payload represents template payload
Expand Down Expand Up @@ -289,6 +290,8 @@ var (
Kind: "token",
HasStaticID: false,
ExtraImports: []string{"strconv"},
SchemaPackage: "token",
SchemaPackagePath: "github.com/gravitational/teleport/integrations/terraform/tfschema/token",
TerraformResourceType: "teleport_provision_token",
HasCheckAndSetDefaults: true,
}
Expand Down Expand Up @@ -564,7 +567,7 @@ var (
"login_rule": loginruleSchema.GenSchemaLoginRule,
"okta_import_rule": tfschema.GenSchemaOktaImportRuleV1,
"oidc_connector": tfschema.GenSchemaOIDCConnectorV3,
"provision_token": tfschema.GenSchemaProvisionTokenV2,
"provision_token": tokenSchema.GenSchemaProvisionTokenV2,
"role": tfschema.GenSchemaRoleV6,
"saml_connector": tfschema.GenSchemaSAMLConnectorV2,
"session_recording_config": tfschema.GenSchemaSessionRecordingConfigV2,
Expand Down
89 changes: 89 additions & 0 deletions integrations/terraform/protoc-gen-terraform-teleport-token.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
---
target_package_name: "token"
default_package_name: "github.com/gravitational/teleport/api/types"
duration_custom_type: Duration
use_state_for_unknown_by_default: true

# Top-level type names to export
types:
- "ProvisionTokenV2"

# These import paths were not being automatically picked up by
# protoc-gen-terraform without these overrides
import_path_overrides:
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:
ProvisionTokenV2:
-
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)
- "Metadata.ID"

name_overrides:

# These fields will be marked as Computed: true
computed_fields:
# Metadata
- "Metadata.Namespace"

# Provision token
- "ProvisionTokenV2.Spec.AWSIIDTTL"
- "ProvisionTokenV2.Kind"
- "ProvisionTokenV2.Metadata.Name"

# These fields will be marked as Required: true
required_fields:
# Provision token
- "ProvisionTokenV2.Spec"
- "ProvisionTokenV2.Spec.Options"
- "ProvisionTokenV2.Spec.Roles"
- "ProvisionTokenV2.Version"

# These fields must be marked as sensitive
sensitive_fields:
- "ProvisionTokenV2.Metadata.Name"

# These suffixes for custom methods called when field has custom_type flag. By default they might be weird.
suffixes:
"BoolOption": "BoolOptionNullable"
"Labels": "Labels"
"github.com/gravitational/teleport/api/types/wrappers.Traits": "Traits"
"github.com/gravitational/teleport/api/types/wrappers.Strings": "Strings"

plan_modifiers:
# Force to recreate resource if it's name changes
Metadata.Name:
- "github.com/hashicorp/terraform-plugin-framework/tfsdk.RequiresReplace()"
ProvisionTokenV2.Metadata.Name:
- "github.com/hashicorp/terraform-plugin-framework/tfsdk.RequiresReplace()"
- "github.com/hashicorp/terraform-plugin-framework/tfsdk.UseStateForUnknown()"

validators:
# Expires must be in the future
Metadata.Expires:
- github_com_gravitational_teleport_integrations_terraform_tfschema.MustTimeBeInFuture()
ProvisionTokenV2.Version:
- github_com_gravitational_teleport_integrations_terraform_tfschema.UseVersionBetween(2,2)

time_type:
type: "github.com/gravitational/teleport/integrations/terraform/tfschema.TimeType"
value_type: "github.com/gravitational/teleport/integrations/terraform/tfschema.TimeValue"
cast_to_type: "time.Time"
cast_from_type: "time.Time"
type_constructor: "github.com/gravitational/teleport/integrations/terraform/tfschema.UseRFC3339Time()"

duration_type:
type: "github.com/gravitational/teleport/integrations/terraform/tfschema.DurationType"
value_type: "github.com/gravitational/teleport/integrations/terraform/tfschema.DurationValue"
cast_to_type: "time.Duration"
cast_from_type: "time.Duration"
25 changes: 0 additions & 25 deletions integrations/terraform/protoc-gen-terraform-teleport.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ types:
- "GithubConnectorV3"
- "OIDCConnectorV3"
- "OktaImportRuleV1"
- "ProvisionTokenV2"
- "RoleV6"
- "SAMLConnectorV2"
- "ServerV2"
Expand Down Expand Up @@ -81,13 +80,6 @@ injected_fields:
computed: true
plan_modifiers:
- "github.com/hashicorp/terraform-plugin-framework/tfsdk.UseStateForUnknown()"
ProvisionTokenV2:
-
name: id
type: github.com/hashicorp/terraform-plugin-framework/types.StringType
computed: true
plan_modifiers:
- "github.com/hashicorp/terraform-plugin-framework/tfsdk.UseStateForUnknown()"
RoleV6:
-
name: id
Expand Down Expand Up @@ -198,11 +190,6 @@ computed_fields:
# Github connector
- "GithubConnectorV3.Kind"

# Provision token
- "ProvisionTokenV2.Spec.AWSIIDTTL"
- "ProvisionTokenV2.Kind"
- "ProvisionTokenV2.Metadata.Name"

# OIDC connector
- "OIDCConnectorV3.Kind"

Expand Down Expand Up @@ -311,12 +298,6 @@ required_fields:
- "OktaImportRuleV1.Metadata.Name"
- "OktaImportRuleV1.Version"

# Provision token
- "ProvisionTokenV2.Spec"
- "ProvisionTokenV2.Spec.Options"
- "ProvisionTokenV2.Spec.Roles"
- "ProvisionTokenV2.Version"

# Role
- "RoleV6.Metadata.Name"
- "RoleV6.Version"
Expand Down Expand Up @@ -347,7 +328,6 @@ required_fields:

# These fields must be marked as sensitive
sensitive_fields:
- "ProvisionTokenV2.Metadata.Name"
- "SAMLConnectorV2.Spec.Cert"
- "SAMLConnectorV2.Spec.SigningKeyPair.PrivateKey"
- "SAMLConnectorV2.Spec.EncryptionKeyPair.PrivateKey"
Expand All @@ -368,9 +348,6 @@ plan_modifiers:
# Force to recreate resource if it's name changes
Metadata.Name:
- "github.com/hashicorp/terraform-plugin-framework/tfsdk.RequiresReplace()"
ProvisionTokenV2.Metadata.Name:
- "github.com/hashicorp/terraform-plugin-framework/tfsdk.RequiresReplace()"
- "github.com/hashicorp/terraform-plugin-framework/tfsdk.UseStateForUnknown()"
ServerV2.Metadata.Name:
- "github.com/hashicorp/terraform-plugin-framework/tfsdk.UseStateForUnknown()"
- "github.com/hashicorp/terraform-plugin-framework/tfsdk.RequiresReplace()"
Expand Down Expand Up @@ -399,8 +376,6 @@ validators:
- UseVersionBetween(3,3)
OktaImportRuleV1.Version:
- UseVersionBetween(1,1)
ProvisionTokenV2.Version:
- UseVersionBetween(2,2)
RoleV6.Version:
- UseVersionBetween(3,7)
SAMLConnectorV2.Version:
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading