### Install Dependencies for spectro-tf-format Source: https://github.com/spectrocloud/terraform-provider-spectrocloud/blob/main/spectrocloud/scripts/README.md Installs dependencies and makes the spectro-tf-format script executable. ```bash pip install -r spectrocloud/scripts/requirements.txt chmod +x spectrocloud/scripts/spectro-tf-format ``` -------------------------------- ### Show Help for spectro-tf-format Source: https://github.com/spectrocloud/terraform-provider-spectrocloud/blob/main/spectrocloud/scripts/README.md Shows the script's built-in help for advanced configuration options and detailed examples. ```bash spectro-tf-format --help ``` -------------------------------- ### Example Output Structure Source: https://github.com/spectrocloud/terraform-provider-spectrocloud/blob/main/spectrocloud/scripts/README.md Example output directory structure after processing, showing the updated Terraform file and the generated YAML files. ```text ├── generated.tf # Updated with file() references ├── cluster_configs_yaml/ │ ├── cluster_cloud_config.yaml # Clean YAML format │ ├── cluster_control-plane-pool_config.yaml │ └── cluster_worker-pool_config.yaml ``` -------------------------------- ### Install dependencies with pip install -r requirements.txt Source: https://github.com/spectrocloud/terraform-provider-spectrocloud/blob/main/spectrocloud/scripts/requirements.txt Two equivalent commands to install dependencies from requirements.txt: one using the pip command directly alerting PATH, the other explicitly invoking pip via python3 -m. Either works for installing PyYAML and all listed optional packages. ```bash pip install -r requirements.txt ``` ```bash python3 -m pip install -r requirements.txt ``` -------------------------------- ### Tenant-Level Template Example Source: https://github.com/spectrocloud/terraform-provider-spectrocloud/blob/main/docs/data-sources/cluster_config_template.md Retrieves a cluster config template with context 'tenant' and outputs its cluster_profile. ```terraform data "spectrocloud_cluster_config_template" "tenant_template" { name = "organization-wide-template" context = "tenant" } output "tenant_template_cluster_profile" { value = data.spectrocloud_cluster_config_template.tenant_template.cluster_profile } ``` -------------------------------- ### Create a VM with default with all available day2 attributes Source: https://github.com/spectrocloud/terraform-provider-spectrocloud/blob/main/docs/resources/virtual_machine.md This example creates a virtual machine with all available day-2 attributes, including commented-out options for priority class, scheduler, node selector, eviction strategy, termination grace period, hostname, subdomain, DNS policy, tolerations, pod DNS config, and affinity. It includes a container disk, a cloud-init disk, and resource requests with over-commit guest overhead set to false. ```hcl resource "spectrocloud_virtual_machine" "tf-test-vm-all-option-template-spec" { cluster_uid = data.spectrocloud_cluster.vm_enabled_base_cluster.id cluster_context = data.spectrocloud_cluster.vm_enabled_base_cluster.context name = "tf-test-vm-all-option-spec-day2" namespace = "default" run_on_launch = true labels = { "key1" = "value1" } # Sample Day 2 Operation attributes # priority_class_name = "high" # scheduler_name = "test" # node_selector = { # "test_vmi" = "node_labels" # } # eviction_strategy = "LiveMigrate" # termination_grace_period_seconds = 60 # hostname = "spectro-com" # subdomain = "test-spectro-com" # dns_policy = "Default" //["ClusterFirstWithHostNet", "ClusterFirst", "Default", "None"] # tolerations { # effect = "NoExecute" // ["NoSchedule", "PreferNoSchedule", "NoExecute"] # key = "tolerationKey" # operator = "Equal" // ["Exists", "Equal"] # toleration_seconds = "60" # value = "taintValue" # } # pod_dns_config { # nameservers = ["10.0.0.10", "10.0.0.11"] # option { # name = "test_dns_name" # value = "dns_value" # } # searches = ["policy1", "policy2"] # } # affinity { # pod_anti_affinity { # preferred_during_scheduling_ignored_during_execution { # weight = 10 # pod_affinity_term { # label_selector { # match_labels = { # anti-affinity-key = "anti-affinity-val" # } # } # topology_key = "kubernetes.io/hostname" # } # } # } # } volume { name = "test-vm-containerdisk1" volume_source { container_disk { image_url = "quay.io/kubevirt/fedora-cloud-container-disk-demo" } } } volume { name = "cloudintdisk" volume_source { cloud_init_config_drive { user_data = "\n#cloud-config\nssh_pwauth: True\nchpasswd: { expire: False }\npassword: spectro\ndisable_root: false\n" } } } resources { requests = { memory = "2G" cpu = 1 } # Sample Day 2 Operation disk # limits = { # "test_limit" = "10" # } over_commit_guest_overhead = false } } ``` -------------------------------- ### Project-Level Template Example Source: https://github.com/spectrocloud/terraform-provider-spectrocloud/blob/main/docs/data-sources/cluster_config_template.md Retrieves a cluster config template with context 'project' and outputs its cloud_type, tags, and description. ```terraform data "spectrocloud_cluster_config_template" "template" { name = var.template_name context = "project" } output "template_cloud_type" { value = data.spectrocloud_cluster_config_template.template.cloud_type } output "template_tags" { value = data.spectrocloud_cluster_config_template.template.tags } output "template_description" { value = data.spectrocloud_cluster_config_template.template.description } ``` -------------------------------- ### Create a VM with default cloud init disk, container disk, multus network interface with interface binding method as sr-iov and network model Source: https://github.com/spectrocloud/terraform-provider-spectrocloud/blob/main/docs/resources/virtual_machine.md This example creates a virtual machine with a container disk and a cloud-init disk, two network interfaces (one masquerade, one bridge), and two networks (pod and multus). It sets CPU, memory, and resource requests. The interface binding method is 'InterfaceMasquerade' for the main interface and 'InterfaceBridge' for the additional interface. ```hcl resource "spectrocloud_virtual_machine" "tf-test-vm-multi-networks" { cluster_uid = data.spectrocloud_cluster.vm_enabled_base_cluster.id cluster_context = data.spectrocloud_cluster.vm_enabled_base_cluster.context name = "tf-test-vm-multi-network-interface" namespace = "default" run_on_launch = true labels = { "key1" = "value1" } volume { name = "test-vm-containerdisk1" volume_source { container_disk { image_url = "quay.io/kubevirt/fedora-cloud-container-disk-demo" } } } volume { name = "cloudintdisk" volume_source { cloud_init_config_drive { user_data = "\n#cloud-config\nssh_pwauth: True\nchpasswd: { expire: False }\npassword: spectro\ndisable_root: false\n" } } } resources { requests = { memory = "2G" cpu = 1 } } disk { name = "test-vm-containerdisk1" disk_device { disk { bus = "virtio" } } } disk { name = "cloudintdisk" disk_device { disk { bus = "virtio" } } } interface { name = "main" interface_binding_method = "InterfaceMasquerade" model = "virtio" } interface { name = "additional" interface_binding_method = "InterfaceBridge" model = "e1000e" } network { name = "main" network_source { pod {} } } network { name = "additional" network_source { multus { network_name = "macvlan-conf" default = false } } } } ``` -------------------------------- ### Retrieve Application Profile Details Source: https://github.com/spectrocloud/terraform-provider-spectrocloud/blob/main/docs/data-sources/application_profile.md Use this data source to retrieve details of an existing application profile by name. The example defines a data source block and an output block that displays the version of the retrieved profile. ```hcl # Retrieve details of a specific application profile data "spectrocloud_application_profile" "example_profile" { name = "my-app-profile" # Specify the name of the application profile } # Output the retrieved application profile details output "application_profile_version" { value = data.spectrocloud_application_profile.example_profile.version } ``` -------------------------------- ### Retrieve SSH Key Data with spectrocloud_ssh_key Source: https://github.com/spectrocloud/terraform-provider-spectrocloud/blob/main/docs/data-sources/ssh_key.md These examples retrieve SSH key data from Palette using the spectrocloud_ssh_key data source. The first example uses the project context, while the second uses the tenant context. The context determines where the SSH key is sourced from, with project being the default. ```hcl data "spectrocloud_ssh_key" "ssh_project" { name = "test-tf-ssh" context = "project" } ``` ```hcl data "spectrocloud_ssh_key" "ssh_project" { name = "global-tf-ssh" context = "tenant" } ``` -------------------------------- ### Create spectrocloud_datavolume resource Source: https://github.com/spectrocloud/terraform-provider-spectrocloud/blob/main/docs/resources/datavolume.md Creates a KubeVirt data volume attached to a virtual machine in Spectro Cloud. The example sets the cluster context to 'project', specifies the cluster UID, VM name and namespace, and defines metadata, an empty spec, and add_volume_options with a virtio disk and a hotpluggable data volume source. ```hcl resource "spectrocloud_datavolume" "example" { cluster_context = "project" cluster_uid = "cluster-uid" vm_name = "vm-example" vm_namespace = "default" metadata { name = "data-volume-example" namespace = "default" } # Full spec omitted for brevity. spec {} add_volume_options { name = "data-volume-example" disk { name = "data-volume-example" bus = "virtio" } volume_source { data_volume { name = "data-volume-example" hotpluggable = true } } } } ``` -------------------------------- ### Retrieve pack details with name and version Source: https://github.com/spectrocloud/terraform-provider-spectrocloud/blob/main/docs/data-sources/pack.md Fetches a specific pack from the community registry using its name and version. The pack name and version are required; the example shows typical values like 'nginx-pack' and '1.2.3'. ```hcl data "spectrocloud_pack" "example" { name = "nginx-pack" # Pack name (e.g., "nginx-pack", "k8s-core", "monitoring-stack") version = "1.2.3" # Pack version (e.g., "1.2.3", "latest", "stable") } ``` -------------------------------- ### Import spectrocloud_resource_limit using terraform import command Source: https://github.com/spectrocloud/terraform-provider-spectrocloud/blob/main/docs/resources/resource_limit.md Imports the resource using the terraform import CLI command. The import syntax uses the tenant_uid or tenant_name separated by a colon, followed by the context. The example shows the command with placeholder values. ```console terraform import spectrocloud_resource_limit.example tenant_uid/tenant_name ``` -------------------------------- ### Retrieve Private Cloud Gateway by name and output ID and name Source: https://github.com/spectrocloud/terraform-provider-spectrocloud/blob/main/docs/data-sources/private_cloud_gateway.md Use this HCL example to fetch a Private Cloud Gateway by its name and output its ID and name. The data source requires the 'name' attribute to specify the PCG. ```hcl # Retrieve details of a specific Private Cloud Gateway (PCG) by name data "spectrocloud_private_cloud_gateway" "example_pcg" { name = "my-private-cloud-gateway" # Specify the name of the PCG } # Output the retrieved PCG ID output "pcg_id" { value = data.spectrocloud_private_cloud_gateway.example_pcg.id } # Output the retrieved PCG name output "pcg_name" { value = data.spectrocloud_private_cloud_gateway.example_pcg.name } ``` -------------------------------- ### Look up a registration token by name and output its value Source: https://github.com/spectrocloud/terraform-provider-spectrocloud/blob/main/docs/data-sources/registration_token.md Use this data source to retrieve a specific registration token in Palette by name. The example sets the name to 'ran-dev-test' and optionally comments out the id field. The token value is exposed as a sensitive output. ```hcl data "spectrocloud_registration_token" "tf" { name = "ran-dev-test" # id = "657ec9a27afca71b0dc98027" } output "token" { value = data.spectrocloud_registration_token.tf.token } ``` -------------------------------- ### Register an existing Kubernetes cluster with spectrocloud_cluster_brownfield Source: https://github.com/spectrocloud/terraform-provider-spectrocloud/blob/main/docs/resources/cluster_brownfield.md Register an existing Kubernetes cluster as a brownfield resource with Palette. The example configures a cluster with provider data sources, RBAC bindings, namespaces, a machine pool, and output values for the manifest URL and kubectl command. ```terraform data "spectrocloud_cluster_profile" "profile" { # id = name = var.cluster_cluster_profile_name } data "spectrocloud_backup_storage_location" "bsl" { name = var.backup_storage_location_name } resource "spectrocloud_cluster_brownfield" "cluster" { name = var.cluster_name cloud_type = "generic" # Options: aws, azure, gcp, generic, apache-cloudstack. context = "project" # Optional, defaults to "project" import_mode = "full" # Options: "read_only" or "full" (default: "full") description = "My existing Kubernetes cluster" cluster_timezone = "America/New_York" tags = ["environment:production", "team:platform", "managed-by:terraform"] cluster_profile { id = data.spectrocloud_cluster_profile.profile.id } scan_policy { configuration_scan_schedule = "0 0 * * SUN" penetration_scan_schedule = "0 0 * * SUN" conformance_scan_schedule = "0 0 1 * *" } backup_policy { schedule = "0 0 * * SUN" backup_location_id = data.spectrocloud_backup_storage_location.bsl.id prefix = "cluster-backup" expiry_in_hour = 7200 include_disks = true include_cluster_resources = true } cluster_rbac_binding { type = "ClusterRoleBinding" role = { kind = "ClusterRole" name = "cluster-admin" } subjects { type = "User" name = "admin-user@example.com" } subjects { type = "Group" name = "platform-admins" } subjects { type = "ServiceAccount" name = "cluster-admin-sa" namespace = "kube-system" } } namespaces { name = "production" resource_allocation = { cpu_cores = "4" memory_MiB = "8192" } } machine_pool { name = "worker-pool" node { node_name = "worker-node-1" action = "uncordon" # Options: "cordon" or "uncordon" } } } # Output the manifest URL and kubectl command for easy access output "manifest_url" { value = spectrocloud_cluster_brownfield.cluster.manifest_url sensitive = false } output "kubectl_command" { value = spectrocloud_cluster_brownfield.cluster.kubectl_command sensitive = false } ``` -------------------------------- ### Configure spectrocloud_sso with SAML and optional OIDC Source: https://github.com/spectrocloud/terraform-provider-spectrocloud/blob/main/docs/resources/sso.md Example usage of the spectrocloud_sso resource. It sets SSO authentication type to SAML, specifies domains and auth providers, and includes a SAML block with service provider, identity provider metadata, and team mappings. The OIDC block is commented out as an alternative. ```hcl data "spectrocloud_team" "team" { name = "Tenant Admin" } resource "spectrocloud_sso" "sso_setting" { sso_auth_type = "saml" # oidc or none domains = ["test.com", "test-login.com"] auth_providers = ["github", "google"] saml { service_provider = "Microsoft ADFS" identity_provider_metadata = "test" default_team_ids = [data.spectrocloud_team.team.id] enable_single_logout = true name_id_format = "name_id_format" first_name = "testfirst" last_name = "testlast" email = "test@test.com" spectro_team = "SpectroTeam" } # oidc { # issuer_url = "https://login.microsoftonline.com/sd8/v2.0" # identity_provider_ca_certificate = "test certificate content" # insecure_skip_tls_verify = false # client_id = "" # client_secret = "" # default_team_ids = [data.spectrocloud_team.team.id] # scopes = ["profile", "email"] # first_name = "test" # last_name = "last" # email = "test@test.com" # spectro_team = "groups" # user_info_endpoint { # first_name = "test" # last_name = "last" # email = "test@test.com" # spectro_team = "groups" # } # } } ``` -------------------------------- ### Import existing role state & config Source: https://github.com/spectrocloud/terraform-provider-spectrocloud/blob/main/docs/resources/role.md Use this example to import an existing role into Terraform state and generate its configuration. The import block specifies the resource address and role UID, then the terraform plan command generates the configuration file, and the terraform import command imports the role using the role UID and name. ```hcl # import existing user example import { to = spectrocloud_role.test_role id = "{roleUID}" } # To generate TF configuration. terraform plan -generate-config-out=test_role.tf ``` ```bash terraform import spectrocloud_role.test_role {roleUID}/{role_name} ``` -------------------------------- ### Create IP Pool with Subnet Source: https://github.com/spectrocloud/terraform-provider-spectrocloud/blob/main/docs/resources/privatecloudgateway_ippool.md Creates an IP pool for a Private Cloud Gateway using a subnet of IP addresses. The example sets network_type to "subnet" and provides a subnet_cidr instead of start and end IP addresses. ```hcl data "spectrocloud_private_cloud_gateway" "pcg" { name = "east-3-pcg" } resource "spectrocloud_privatecloudgateway_ippool" "ippool" { gateway = "10.10.192.1" name = "backup-compute-pool" network_type = "subnet" prefix = "24" subnet_cidr = "10.10.100.0/24" private_cloud_gateway_id = data.spectrocloud_private_cloud_gateway.pcg.id nameserver_addresses = ["192.168.1.8"] } ``` -------------------------------- ### Create IP Pool with IP Range Source: https://github.com/spectrocloud/terraform-provider-spectrocloud/blob/main/docs/resources/privatecloudgateway_ippool.md Creates an IP pool for a Private Cloud Gateway using a range of IP addresses and restricts the pool to a single cluster. The example references a data source for the gateway and sets network_type to "range" with start and end IP addresses. ```hcl data "spectrocloud_private_cloud_gateway" "pcg" { name = "wst-1-pcg" } resource "spectrocloud_privatecloudgateway_ippool" "ippool" { gateway = "192.168.1.1" name = "primary-compute-pool-1" network_type = "range" prefix = "24" private_cloud_gateway_id = data.spectrocloud_private_cloud_gateway.pcg.id ip_start_range = "192.168.1.10" ip_end_range = "192.168.1.100" nameserver_addresses = ["192.168.1.8"] restrict_to_single_cluster = true } ``` -------------------------------- ### Initialize and apply Terraform configuration Source: https://github.com/spectrocloud/terraform-provider-spectrocloud/blob/main/docs/index.md Run terraform init and apply to provision resources after configuring the provider and variables. ```console terraform init && terraform apply ``` -------------------------------- ### Create a simple project Source: https://github.com/spectrocloud/terraform-provider-spectrocloud/blob/main/docs/resources/project.md Defines a basic spectrocloud_project resource with only a name. ```terraform resource "spectrocloud_project" "project" { name = "dev1" } ``` -------------------------------- ### Create, clone, and use data volume template for spectrocloud_virtual_machine Source: https://github.com/spectrocloud/terraform-provider-spectrocloud/blob/main/docs/resources/virtual_machine.md The first block defines a data source for an existing Spectro Cloud cluster and a local variable for the storage class name. The second block creates a basic KubeVirt VM with container disk, cloud-init disk, CPU, memory, resources, interface, and network. The third block clones a VM from a base VM using base_vm_name, with optional disk, volume, interface, cpu, memory, and network configurations. The fourth block creates a VM using a data volume template with a registry source and PVC storage. ```terraform data "spectrocloud_cluster" "vm_enabled_base_cluster" { name = "tenant-cluster-002" context = "project" } locals { storage_class_name = "spectro-storage-class" } ``` ```terraform // Create a VM with default cloud init disk, container disk , interface and network #/* resource "spectrocloud_virtual_machine" "tf-test-vm-basic-type" { cluster_uid = data.spectrocloud_cluster.vm_enabled_base_cluster.id cluster_context = data.spectrocloud_cluster.vm_enabled_base_cluster.context run_on_launch = true name = "tf-test-vm-basic-type" namespace = "default" labels = { "tf" = "test" } volume { name = "containerdisk" volume_source { container_disk { image_url = "gcr.io/spectro-images-public/release/vm-dashboard/os/ubuntu-container-disk:20.04" } } } volume { name = "cloudintdisk" volume_source { cloud_init_config_drive { user_data = "\n#cloud-config\nssh_pwauth: True\nchpasswd: { expire: False }\npassword: spectro\ndisable_root: false\n" } } } disk { name = "containerdisk" disk_device { disk { bus = "virtio" } } } disk { name = "cloudintdisk" disk_device { disk { bus = "virtio" } } } cpu { cores = 2 sockets = 1 threads = 10 } memory { guest = "1Gi" } resources { requests = { memory = "1Gi" cpu = 1 } limits = { cpu = 2 memory = "1Gi" } } interface { name = "default" interface_binding_method = "InterfaceMasquerade" } network { name = "default" network_source { pod {} } } } #*/ ``` ```terraform // Cloning VM with base_vm_name "tf-test-vm-basic-type" /* resource "spectrocloud_virtual_machine" "tf-test-vm-clone-default" { cluster_uid = data.spectrocloud_cluster.vm_enabled_base_cluster.id cluster_context = data.spectrocloud_cluster.vm_enabled_base_cluster.context base_vm_name = spectrocloud_virtual_machine.tf-test-vm-basic-type.name name = "tf-test-vm-clone" namespace = "default" run_on_launch = true labels = { "tf" = "test" } resources { requests = { memory = "1Gi" cpu = 2 } limits = { cpu = 2 memory = "1Gi" } } // For Cloning VM's disk, volume, interface, cpu, memory and network or optional, Those configuration will get cloned from base vm. volume { name = "containerdisk" volume_source { container_disk { image_url = "gcr.io/spectro-images-public/release/vm-dashboard/os/ubuntu-container-disk:20.04" } } } volume { name = "cloudintdisk" volume_source { cloud_init_config_drive { user_data = "\n#cloud-config\nssh_pwauth: True\nchpasswd: { expire: False }\npassword: spectro\ndisable_root: false\n" } } } disk { name = "containerdisk" disk_device { disk { bus = "virtio" } } } disk { name = "cloudintdisk" disk_device { disk { bus = "virtio" } } } cpu { cores = 2 sockets = 1 threads = 10 } memory { guest = "1Gi" } interface { name = "default" interface_binding_method = "InterfaceMasquerade" } network { name = "default" network_source { pod {} } } } */ ``` ```terraform // Creating VM with data volume template /* resource "spectrocloud_virtual_machine" "tf-test-vm-data-volume-template" { cluster_uid = data.spectrocloud_cluster.vm_enabled_base_cluster.id cluster_context = data.spectrocloud_cluster.vm_enabled_base_cluster.context # run_on_launch = true run_strategy = "Manual" name = "tf-test-vm-data-volume-template" namespace = "default" labels = { "tf" = "test" } data_volume_templates { metadata { name = "test-vm-bootvolume" namespace = "default" } spec { source { registry { image_url = "gcr.io/spectro-images-public/release/vm-dashboard/os/ubuntu-container-disk:20.04" } #http { # url = "https://cloud.centos.org/centos/7/images/CentOS-7-x86_64-GenericCloud.qcow2" #} } pvc { access_modes = ["ReadWriteOnce"] resources { requests = { storage = "5Gi" } } storage_class_name = local.storage_class_name } } } volume { name = "test-vm-datavolumedisk1" volume_source { data_volume { name = "test-vm-bootvolume" } } } ``` -------------------------------- ### Create spectrocloud_user with only teams Source: https://github.com/spectrocloud/terraform-provider-spectrocloud/blob/main/docs/resources/user.md Creates a spectrocloud_user resource with only assigned teams. This is a minimal example that omits role assignments. ```hcl resource "spectrocloud_user" "user-test"{ first_name = "tf" last_name = "test" email = "test-tf@spectrocloud.com" team_ids = [data.spectrocloud_team.team2.id] } ``` -------------------------------- ### Complete Workflow for spectro-tf-format Source: https://github.com/spectrocloud/terraform-provider-spectrocloud/blob/main/spectrocloud/scripts/README.md Complete workflow: import an existing cluster, generate and process Terraform configuration, review results, and clean up. ```bash # Import existing cluster cat > import.tf << EOF import { to = spectrocloud_cluster_custom_cloud.example id = "cluster123:project:nutanix" } EOF # Generate and process terraform plan -generate-config-out=generated.tf spectro-tf-format generated.tf # Review results ls cluster_configs_yaml/ terraform plan # Clean up rm import.tf ``` -------------------------------- ### Look up a SpectroCloud registry pack by name Source: https://github.com/spectrocloud/terraform-provider-spectrocloud/blob/main/docs/data-sources/registry_pack.md Example usage of the spectrocloud_registry_pack data source. It retrieves a registry pack by name and outputs its ID. ```terraform # Data source to retrieve details of a specific SpectroCloud registry pack by name data "spectrocloud_registry_pack" "my_pack" { name = "my-pack" # Name of the registry pack to look up } # Output the ID of the retrieved registry pack output "registry_pack_id" { value = data.spectrocloud_registry_pack.my_pack.id } ``` -------------------------------- ### Import SSH Key (Simple Context) Source: https://github.com/spectrocloud/terraform-provider-spectrocloud/blob/main/docs/resources/ssh_key.md Imports an SSH key using the simple ID format, defaulting to project context. ```bash terraform import spectrocloud_ssh_key.example ``` -------------------------------- ### Retrieve AWS cloud account by name (alternative) Source: https://github.com/spectrocloud/terraform-provider-spectrocloud/blob/main/docs/data-sources/cloudaccount_aws.md Alternative example that retrieves the details of an AWS cloud account by specifying the name attribute. ```hcl data "spectrocloud_cloudaccount_aws" "aws_account" { name = "primary-aws-account" } ``` -------------------------------- ### Import spectrocloud_platform_setting with terraform import Source: https://github.com/spectrocloud/terraform-provider-spectrocloud/blob/main/docs/resources/platform_setting.md CLI commands to import the platform setting using tenant/project UID or name, colon-separated with the context (project or tenant). ```console terraform import spectrocloud_platform_setting.example /:/ terraform import spectrocloud_platform_setting.example /:/ ``` -------------------------------- ### Troubleshooting: Script Not Found Source: https://github.com/spectrocloud/terraform-provider-spectrocloud/blob/main/spectrocloud/scripts/README.md Troubleshooting: run the script with python3 if it is not found as an executable. ```bash python3 spectrocloud/scripts/spectro-tf-format generated.tf ``` -------------------------------- ### Look up backup storage location by name Source: https://github.com/spectrocloud/terraform-provider-spectrocloud/blob/main/docs/data-sources/backup_storage_location.md Retrieves a backup storage location by name. This example looks up the location named "default-backup-location". ```terraform data "spectrocloud_backup_storage_location" "example" { name = "default-backup-location" } ``` -------------------------------- ### Configure Spectro Cloud provider and credentials Source: https://github.com/spectrocloud/terraform-provider-spectrocloud/blob/main/docs/index.md Create a providers.tf file with the required provider block and a terraform.tfvars file with credentials. The provider block uses variables for host, API key, and project name, with defaults and environment variable fallback for the API key. ```terraform terraform { required_providers { spectrocloud = { version = ">= 0.1" source = "spectrocloud/spectrocloud" } } } provider "spectrocloud" { host = var.sc_host # Spectro Cloud endpoint (defaults to api.spectrocloud.com) api_key = var.sc_api_key # API key (or specify with SPECTROCLOUD_APIKEY env var) project_name = var.sc_project_name # Project name (e.g: Default) } ``` ```terraform ################################################################################## # Spectro Cloud credentials ################################################################################## sc_host = "{Enter Spectro Cloud API Host}" #e.g: api.spectrocloud.com (for SaaS) sc_api_key = "{Enter Spectro Cloud API Key}" sc_project_name = "{Enter Spectro Cloud Project Name}" #e.g: Default ``` -------------------------------- ### Cluster Profile with Profile Variables Source: https://github.com/spectrocloud/terraform-provider-spectrocloud/blob/main/docs/resources/cluster_profile.md Example of a cluster profile with profile variables. Refer to the Profile Variables nested schema section for more information. The is_sensitive attribute masks sensitive variable values. ```terraform resource "spectrocloud_cluster_profile" "profile" { name = "vsphere-picard-4" description = "basic cp" tags = ["dev", "department:devops", "owner:bob"] cloud = "vsphere" type = "cluster" pack { name = "ubuntu-vsphere" tag = "LTS__18.4.x" uid = data.spectrocloud_pack.ubuntu.id values = "foo: 1" } pack { name = "kubernetes" tag = "1.21.5" uid = data.spectrocloud_pack.k8s.id values = data.spectrocloud_pack.k8s.values } pack { name = "cni-calico" tag = "3.16.x" uid = data.spectrocloud_pack.cni.id values = data.spectrocloud_pack.cni.values } pack { name = "csi-vsphere-csi" tag = "2.3.x" uid = data.spectrocloud_pack.csi.id values = data.spectrocloud_pack.csi.values } profile_variables{ variable { name = "default_password" display_name = "Default Password" format = "string" is_sensitive = true // For sensitive variables like passwords, setting hidden to true will mask the variable value. } variable { name = "default_version" display_name = "Version" format = "version" description = "description hard-version" default_value = "0.0.1" regex = "*.*" required = true immutable = false } } } ``` -------------------------------- ### Create MaaS Cloud Account Source: https://github.com/spectrocloud/terraform-provider-spectrocloud/blob/main/docs/resources/cloudaccount_maas.md Creates a MaaS cloud account resource in Spectro Cloud. The example uses variables for the API endpoint and API key, and sets the name to "maas-1". ```terraform resource "spectrocloud_cloudaccount_maas" "maas-1" { name = "maas-1" maas_api_endpoint = var.maas_api_endpoint maas_api_key = var.maas_api_key } ``` -------------------------------- ### Create a workspace with clusters, RBAC bindings, namespaces, and backup policy Source: https://github.com/spectrocloud/terraform-provider-spectrocloud/blob/main/docs/resources/workspace.md Defines a spectrocloud_workspace resource named 'workspace' with name 'wsp-tf'. It attaches a cluster via data source, configures two cluster_rbac_binding blocks (ClusterRoleBinding and RoleBinding), sets a namespace with resource allocation and image blacklist, and defines a backup_policy with schedule, location, prefix, expiry, and cluster selection. Requires data sources for cluster and backup storage location. ```terraform data "spectrocloud_cluster" "cluster1" { name = "vsphere-picard-2" } resource "spectrocloud_workspace" "workspace" { name = "wsp-tf" clusters { uid = data.spectrocloud_cluster.cluster1.id } cluster_rbac_binding { type = "ClusterRoleBinding" role = { kind = "ClusterRole" name = "testrole3" } subjects { type = "User" name = "testRoleUser4" } subjects { type = "Group" name = "testRoleGroup4" } subjects { type = "ServiceAccount" name = "testrolesubject3" namespace = "testrolenamespace" } } cluster_rbac_binding { type = "RoleBinding" namespace = "test5ns" role = { kind = "Role" name = "testrolefromns3" } subjects { type = "User" name = "testUserRoleFromNS3" } subjects { type = "Group" name = "testGroupFromNS3" } subjects { type = "ServiceAccount" name = "testrolesubject3" namespace = "testrolenamespace" } } namespaces { name = "test5ns" resource_allocation = { cpu_cores = "2" memory_MiB = "2048" } images_blacklist = ["1", "2", "3"] } backup_policy { schedule = "0 0 * * SUN" backup_location_id = data.spectrocloud_backup_storage_location.bsl.id prefix = "prod-backup" expiry_in_hour = 7200 include_disks = false include_cluster_resources = true //namespaces = ["test5ns"] include_all_clusters = true cluster_uids = [data.spectrocloud_cluster.cluster1.id] } } data "spectrocloud_backup_storage_location" "bsl" { name = "backups-nikolay" } ``` -------------------------------- ### terraform data source spectrocloud_cluster_config_policy Source: https://github.com/spectrocloud/terraform-provider-spectrocloud/blob/main/docs/data-sources/cluster_config_policy.md Use this data source to fetch a cluster config policy by name and context. The example looks up the policy named 'weekly-maintenance-policy' in the 'project' context and then outputs its schedules and tags. ```terraform data "spectrocloud_cluster_config_policy" "policy" { name = "weekly-maintenance-policy" context = "project" } output "policy_schedules" { value = data.spectrocloud_cluster_config_policy.policy.schedules } output "policy_tags" { value = data.spectrocloud_cluster_config_policy.policy.tags } ``` -------------------------------- ### Create a project with tags and description Source: https://github.com/spectrocloud/terraform-provider-spectrocloud/blob/main/docs/resources/project.md Defines a spectrocloud_project resource with tags and a description. ```terraform resource "spectrocloud_project" "project" { name = "dev2" tags = ["owner:jdoe@emxaple.com", "cost-center:12345"] description = "This is the primary devoplent environment for team Yellow." } ``` -------------------------------- ### Retrieve Apache CloudStack Cloud Account by ID Source: https://github.com/spectrocloud/terraform-provider-spectrocloud/blob/main/docs/data-sources/cloudaccount_apache_cloudstack.md Retrieve an Apache CloudStack cloud account by its unique ID. The `id` argument is required if `name` is not provided. The example outputs the `private_cloud_gateway_id` attribute from the retrieved account. ```terraform # Retrieve details of an Apache CloudStack cloud account using ID data "spectrocloud_cloudaccount_apache_cloudstack" "by_id" { id = "123e4567-e89b-12d3-a456-426614174000" # Required if 'name' is not provided } # Use the retrieved account in other resources output "pcg_id" { value = data.spectrocloud_cloudaccount_apache_cloudstack.by_id.private_cloud_gateway_id } ``` -------------------------------- ### Import spectrocloud_macros using terraform import CLI Source: https://github.com/spectrocloud/terraform-provider-spectrocloud/blob/main/docs/resources/macros.md Shows the terraform import CLI commands for importing macros using either tenant_uid/project_uid or tenant_name/project_name, each followed by the context separated by a colon. ```console terraform import spectrocloud_macros.example /:/ terraform import spectrocloud_macros.example /:/ ``` -------------------------------- ### Import a project Source: https://github.com/spectrocloud/terraform-provider-spectrocloud/blob/main/docs/resources/project.md Shows the terraform import command for spectrocloud_project, using project_uid and project_name. ```console terraform import spectrocloud_project.{project_uid}/{project_name} ``` -------------------------------- ### Import block structure Source: https://github.com/spectrocloud/terraform-provider-spectrocloud/blob/main/docs/index.md Shows the general structure of a Terraform import block. The to argument specifies the resource type and name, and the id argument provides the unique identifier for the resource. Available starting with Terraform v1.5.0. ```terraform import { to = . id = "" } ``` -------------------------------- ### Look up workspace by name and output its ID Source: https://github.com/spectrocloud/terraform-provider-spectrocloud/blob/main/docs/data-sources/workspace.md Retrieves a Spectro Cloud workspace by name using the spectrocloud_workspace data source. The example specifies the workspace name and outputs the retrieved workspace ID. The name is required, and the id is read-only. ```terraform # Retrieve details of a specific workspace data "spectrocloud_workspace" "example_workspace" { name = "my-workspace" # Specify the name of the workspace } # Output the retrieved workspace id output "workspace_name" { value = data.spectrocloud_workspace.example_workspace.id } ``` -------------------------------- ### Import application by UID/NAME Source: https://github.com/spectrocloud/terraform-provider-spectrocloud/blob/main/docs/resources/application.md Imports an existing application using its UID and name. The import automatically detects the cluster context and populates the configuration from the Spectro Cloud API. ```bash terraform import spectrocloud_application.example application_uid/application_name ``` -------------------------------- ### Simple Import Command for Backup Storage Location Source: https://github.com/spectrocloud/terraform-provider-spectrocloud/blob/main/docs/resources/backup_storage_location.md Imports a backup storage location using the simple ID format, which defaults to project context. The format is {bsl_id}/{bsl_name}:project. ```bash terraform import spectrocloud_backup_storage_location.example {bsl_id}/{bsl_name}:project ``` -------------------------------- ### Import spectrocloud_appliance using terraform import Source: https://github.com/spectrocloud/terraform-provider-spectrocloud/blob/main/docs/resources/appliance.md Imports an existing appliance using its UID and name. The import populates all configuration fields from the API, and the wait field is set to false by default. ```bash terraform import spectrocloud_appliance.example / ``` -------------------------------- ### Import spectrocloud_resource_limit using import block Source: https://github.com/spectrocloud/terraform-provider-spectrocloud/blob/main/docs/resources/resource_limit.md Imports the resource using Terraform's import block (v1.5.0+). The id is the tenant UID, and the context is separated by a colon. The example shows the id as '{tenantUID}' with a comment indicating the tenant UID. ```terraform import { to = spectrocloud_resource_limit.resource_limit id = "{tenantUID}" // tenant-uid } ``` -------------------------------- ### Create spectrocloud_developer_setting resource Source: https://github.com/spectrocloud/terraform-provider-spectrocloud/blob/main/docs/resources/developer_setting.md Defines a spectrocloud_developer_setting resource with virtual_clusters_limit, cpu, memory, storage, and hide_system_cluster_group attributes. Use this to configure tenant-level developer quotas. Note that every new virtual cluster consumes about 3 CPU and 3 GiB memory even without user workloads. ```hcl resource "spectrocloud_developer_setting" "dev_setting" { virtual_clusters_limit = 10 cpu = 20 memory = 100 storage = 100 hide_system_cluster_group = false } ``` -------------------------------- ### Look up a SpectroCloud user by ID or email Source: https://github.com/spectrocloud/terraform-provider-spectrocloud/blob/main/docs/data-sources/user.md Use this data source to fetch details of a specific user in SpectroCloud by providing either `id` or `email`, but not both. The example shows how to reference the user by ID and output the user's ID and email. ```terraform # Fetch details of a specific user in SpectroCloud data "spectrocloud_user" "example" { # Provide either `id` or `email`, but not both. id = "user-12345" # email = "user@example.com" # Alternative way to reference a user by email } # Output user details for reference output "user_info" { value = { id = data.spectrocloud_user.example.id email = data.spectrocloud_user.example.email } } ``` -------------------------------- ### Context-specific Import Command for Backup Storage Location Source: https://github.com/spectrocloud/terraform-provider-spectrocloud/blob/main/docs/resources/backup_storage_location.md Imports a backup storage location with explicit context specification. The format is /: or . If no context is specified, it defaults to project context. ```bash terraform import spectrocloud_backup_storage_location.example /: ``` -------------------------------- ### Import resource using import block Source: https://github.com/spectrocloud/terraform-provider-spectrocloud/blob/main/docs/resources/cloudaccount_vsphere.md Shows how to import the spectrocloud_cloudaccount_vsphere resource using an import block with the id and context separated by a colon. ```terraform import { to = spectrocloud_cloudaccount_vsphere.example id = "example_id:context" } ``` -------------------------------- ### Fetch project details with spectrocloud_project data source Source: https://github.com/spectrocloud/terraform-provider-spectrocloud/blob/main/docs/data-sources/project.md Use this Terraform configuration to look up a Spectro Cloud project by ID or name. Provide either `id` or `name`, but not both. The example also outputs the project's ID and name for reference. ```terraform # Fetch details of a specific project in SpectroCloud data "spectrocloud_project" "example" { # Provide either `id` or `name`, but not both. id = "project-12345" # name = "MyProject" # Alternative way to reference a project by name } # Output project details for reference output "project_info" { value = { id = data.spectrocloud_project.example.id name = data.spectrocloud_project.example.name } } ``` -------------------------------- ### Import virtual cluster using terraform import command Source: https://github.com/spectrocloud/terraform-provider-spectrocloud/blob/main/docs/resources/virtual_cluster.md Shows the terraform import command to import the cluster using either the cluster_name or id, separated by context. Two examples are provided: one using the id and one using the cluster_name. ```console terraform import spectrocloud_virtual_cluster.example example_id ``` ```console terraform import spectrocloud_virtual_cluster.example cluster_name ``` -------------------------------- ### Fetch SpectroCloud team by ID or name Source: https://github.com/spectrocloud/terraform-provider-spectrocloud/blob/main/docs/data-sources/team.md Use this Terraform configuration to fetch details of a specific team in SpectroCloud. The data source requires either `id` or `name`, but not both. The example uses `id` and outputs the team's `id`, `name`, and `role_ids`. ```terraform # Fetch details of a specific team in SpectroCloud data "spectrocloud_team" "example" { # Provide either `id` or `name`, but not both. # Allowed values: # - `id`: A unique identifier for the team (e.g., "team-12345"). # - `name`: The readable name of the team (e.g., "DevOps Team"). id = "team-12345" # name = "DevOps Team" # Alternative way to reference a team by name } output "team_info" { value = { id = data.spectrocloud_team.example.id name = data.spectrocloud_team.example.name role_ids = data.spectrocloud_team.example.role_ids } } ``` -------------------------------- ### Configuration Options for spectro-tf-format Source: https://github.com/spectrocloud/terraform-provider-spectrocloud/blob/main/spectrocloud/scripts/README.md Configuration options: custom output directory, skip backup creation, and skip terraform formatting. ```bash # Custom output directory spectro-tf-format --output-dir=configs generated.tf # Skip backup creation spectro-tf-format --no-backup generated.tf # Skip terraform formatting spectro-tf-format --no-format generated.tf ```