Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ authority to manage resources in the cluster. To prepare credentials using a loc
- user
- access_list
- node
- installer
verbs: ['list','create','read','update','delete']
version: v7
```
Expand Down
2 changes: 1 addition & 1 deletion integrations/terraform/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## Usage

Please, refer to [official documentation](https://goteleport.com/docs/setup/guides/terraform-provider/).
Please, refer to [official documentation](https://goteleport.com/docs/admin-guides/infrastructure-as-code/terraform-provider/).

## Development

Expand Down
70 changes: 70 additions & 0 deletions integrations/terraform/example/installer.tf.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# Teleport Installer resource

resource "teleport_installer" "example" {
version = "v1"
metadata = {
name = "example"
description = "Example Teleport Installer"
labels = {
example = "yes"
}
}

spec = {
# This is the default installer script. For more details about the installer script
# see https://goteleport.com/docs/enroll-resources/auto-discovery/servers/ec2-discovery/#step-67-optional-customize-the-default-installer-script
script = <<EOF
#!/usr/bin/env sh
set -eu

cdnBaseURL='https://cdn.teleport.dev'
teleportVersion='v{{.MajorVersion}}'
teleportFlavor='teleport-ent' # teleport or teleport-ent
successMessage='Teleport is installed and running.'
teleportArgs='install autodiscover-node --public-proxy-addr={{.PublicProxyAddr}} --teleport-package={{.TeleportPackage}} --repo-channel={{.RepoChannel}} --auto-upgrade={{.AutomaticUpgrades}} --azure-client-id={{.AzureClientID}}'

# shellcheck disable=all
# Use $HOME or / as base dir
tempDir=$(mktemp -d -p $${HOME:-}/)
OS=$(uname -s)
ARCH=$(uname -m)
# shellcheck enable=all

trap 'rm -rf -- "$tempDir"' EXIT

teleportTarballName() {
if [ $${OS} = "Darwin" ]; then
echo $${teleportFlavor}-$${teleportVersion}-darwin-universal-bin.tar.gz
return 0
fi;

if [ $${OS} != "Linux" ]; then
echo "Only MacOS and Linux are supported." >&2
return 1
fi;

if [ $${ARCH} = "armv7l" ]; then echo "$${teleportFlavor}-$${teleportVersion}-linux-arm-bin.tar.gz"
elif [ $${ARCH} = "aarch64" ]; then echo "$${teleportFlavor}-$${teleportVersion}-linux-arm64-bin.tar.gz"
elif [ $${ARCH} = "x86_64" ]; then echo "$${teleportFlavor}-$${teleportVersion}-linux-amd64-bin.tar.gz"
elif [ $${ARCH} = "i686" ]; then echo "$${teleportFlavor}-$${teleportVersion}-linux-386-bin.tar.gz"
else
echo "Invalid Linux architecture $${ARCH}." >&2
return 1
fi;
}

main() {
tarballName=$(teleportTarballName)
echo "Downloading from $${cdnBaseURL}/$${tarballName} and extracting teleport to $${tempDir} ..."
curl --show-error --fail --location $${cdnBaseURL}/$${tarballName} | tar xzf - -C $${tempDir} $${teleportFlavor}/teleport

mkdir -p $${tempDir}/bin
mv $${tempDir}/$${teleportFlavor}/teleport $${tempDir}/bin/teleport
echo "> $${tempDir}/bin/teleport $${teleportArgs} $@"
sudo $${tempDir}/bin/teleport $${teleportArgs} $@ && echo $successMessage
}

main $@
EOF
}
}
1 change: 1 addition & 0 deletions integrations/terraform/example/terraform.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ spec:
- device
- okta_import_rule
- access_list
- installer
verbs: ['list','create','read','update','delete']
version: v6
---
Expand Down
18 changes: 18 additions & 0 deletions integrations/terraform/gen/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,21 @@ var (
Namespaced: true,
ForceSetKind: "apitypes.KindNode",
}

installer = payload{
Name: "Installer",
TypeName: "InstallerV1",
VarName: "installer",
GetMethod: "GetInstaller",
CreateMethod: "SetInstaller",
UpdateMethod: "SetInstaller",
DeleteMethod: "DeleteInstaller",
ID: `"installer"`,
Kind: "installer",
HasStaticID: false,
TerraformResourceType: "teleport_installer",
HasCheckAndSetDefaults: true,
}
)

func main() {
Expand Down Expand Up @@ -502,6 +517,8 @@ func genTFSchema() {
generateDataSource(accessList, pluralDataSource)
generateResource(server, pluralResource)
generateDataSource(server, pluralDataSource)
generateResource(installer, pluralResource)
generateDataSource(installer, pluralDataSource)
}

func generateResource(p payload, tpl string) {
Expand Down Expand Up @@ -574,6 +591,7 @@ var (
"trusted_cluster": tfschema.GenSchemaTrustedClusterV2,
"user": tfschema.GenSchemaUserV2,
"server": tfschema.GenSchemaServerV2,
"installer": tfschema.GenSchemaInstallerV1,
}

// hiddenFields are fields that are not outputted to the reference doc.
Expand Down
33 changes: 26 additions & 7 deletions integrations/terraform/protoc-gen-terraform-teleport.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ types:
- "SessionRecordingConfigV2"
- "TrustedClusterV2"
- "UserV2"
- "InstallerV1"

# id field is required for integration tests. It is not used by provider.
# 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:
AppV3:
Expand Down Expand Up @@ -122,6 +123,13 @@ injected_fields:
computed: true
plan_modifiers:
- "github.com/hashicorp/terraform-plugin-framework/tfsdk.UseStateForUnknown()"
InstallerV1:
-
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:
Expand Down Expand Up @@ -255,7 +263,7 @@ computed_fields:
# back into the state.
- "ServerV2.Metadata"

# Session recording
# Session recording
- "SessionRecordingConfigV2.Spec.Mode"
- "SessionRecordingConfigV2.Kind"

Expand All @@ -265,7 +273,10 @@ computed_fields:
# User
- "UserV2.Kind"

# These fields will be marked as Required: true
# Installer
- "InstallerV1.Kind"

# These fields will be marked as Required: true
required_fields:
# App
- "AppV3.Metadata.Name"
Expand All @@ -276,8 +287,8 @@ required_fields:
- "AuthPreferenceV2.Metadata.Name"

# Database
- "DatabaseV3.Spec.Protocol"
- "DatabaseV3.Spec.URI"
- "DatabaseV3.Spec.Protocol"
- "DatabaseV3.Spec.URI"
- "DatabaseV3.Metadata.Name"
- "DatabaseV3.Version"

Expand Down Expand Up @@ -326,12 +337,18 @@ required_fields:
- "ClusterMaintenanceConfigV1.Version"
- "AuthPreferenceV2.Version"

# Installer
- "InstallerV1.Spec"
- "InstallerV1.Spec.Script"
- "InstallerV1.Metadata.Name"
- "InstallerV1.Version"

# These fields must be marked as sensitive
sensitive_fields:
- "SAMLConnectorV2.Spec.Cert"
- "SAMLConnectorV2.Spec.SigningKeyPair.PrivateKey"
- "SAMLConnectorV2.Spec.EncryptionKeyPair.PrivateKey"
- "SAMLConnectorV2.Spec.EntityDescriptor"
- "SAMLConnectorV2.Spec.EntityDescriptor"
- "GithubConnectorV3.Spec.ClientSecret"
- "OIDCConnectorV3.Spec.ClientSecret"
- "OIDCConnectorV3.Spec.GoogleServiceAccount"
Expand Down Expand Up @@ -394,13 +411,15 @@ validators:
- UseVersionBetween(2,2)
ClusterMaintenanceConfigV1.Version:
- UseVersionBetween(1,1)
InstallerV1.Version:
- UseVersionBetween(1,1)

time_type:
type: "TimeType"
value_type: "TimeValue"
cast_to_type: "time.Time"
cast_from_type: "time.Time"
type_constructor: UseRFC3339Time()
type_constructor: UseRFC3339Time()

duration_type:
type: "DurationType"
Expand Down
82 changes: 82 additions & 0 deletions integrations/terraform/provider/data_source_teleport_installer.go

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

2 changes: 2 additions & 0 deletions integrations/terraform/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,7 @@ func (p *Provider) GetResources(_ context.Context) (map[string]tfsdk.ResourceTyp
"teleport_okta_import_rule": resourceTeleportOktaImportRuleType{},
"teleport_access_list": resourceTeleportAccessListType{},
"teleport_server": resourceTeleportServerType{},
"teleport_installer": resourceTeleportInstallerType{},
}, nil
}

Expand All @@ -606,5 +607,6 @@ func (p *Provider) GetDataSources(_ context.Context) (map[string]tfsdk.DataSourc
"teleport_trusted_device": dataSourceTeleportDeviceV1Type{},
"teleport_okta_import_rule": dataSourceTeleportOktaImportRuleType{},
"teleport_access_list": dataSourceTeleportAccessListType{},
"teleport_installer": dataSourceTeleportInstallerType{},
}, nil
}
Loading