### Key Flow: Terraform Provider Configuration Example Source: https://github.com/stackitcloud/terraform-provider-stackit/blob/main/docs/index.md Example of how to configure the Stackit Terraform Provider using the key flow, either by directly providing the service account key or its path. ```terraform provider "stackit" { # Option 1: Provide the service account key directly service_account_key = "{\"id\": \"...\", \"credentials\": { \"privateKey\": \"...\" }}" # Option 2: Provide the path to the service account key file service_account_key_path = "/path/to/service-account-key.json" # Optionally, if using your own private key: # private_key = "-----BEGIN PRIVATE KEY-----\n...\n-----END PRIVATE KEY-----" # private_key_path = "/path/to/private.pem" } ``` -------------------------------- ### Example Terraform Configuration for STACKIT Resource Source: https://github.com/stackitcloud/terraform-provider-stackit/blob/main/CONTRIBUTION.md An example of how to configure a new STACKIT resource, specifically 'stackit_foo_bar', in Terraform. This includes required and optional fields. ```hcl resource "stackit_foo_bar" "example" { project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" my_required_field = "my-required-field-value" my_optional_field = "my-optional-field-value" } ``` -------------------------------- ### Token Flow: Terraform Provider Configuration Example Source: https://github.com/stackitcloud/terraform-provider-stackit/blob/main/docs/index.md Example of how to configure the Stackit Terraform Provider using the token flow, by providing the service account token directly. ```terraform provider "stackit" { service_account_token = "your-long-lived-token" } ``` -------------------------------- ### Create stackit_network Resource Examples Source: https://github.com/stackitcloud/terraform-provider-stackit/blob/main/docs/resources/network.md Provides examples of how to create a stackit_network resource with different configurations, including basic network creation, routed networks with labels, and non-routed networks with specific IPv4 settings. It also shows how to import an existing network. ```terraform resource "stackit_network" "example_with_name" { project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" name = "example-with-name" } resource "stackit_network" "example_routed_network" { project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" name = "example-routed-network" labels = { "key" = "value" } routed = true } resource "stackit_network" "example_non_routed_network" { project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" name = "example-non-routed-network" ipv4_nameservers = ["1.2.3.4", "5.6.7.8"] ipv4_gateway = "10.1.2.3" ipv4_prefix = "10.1.2.0/24" labels = { "key" = "value" } routed = false } # Only use the import statement, if you want to import an existing network # Note: There will be a conflict which needs to be resolved manually. # These attributes cannot be configured together: [ipv4_prefix,ipv4_prefix_length,ipv4_gateway] import { to = stackit_network.import-example id = "${var.project_id},${var.region},${var.network_id}" } ``` -------------------------------- ### Terraform LogMe Instance Data Source Example Source: https://github.com/stackitcloud/terraform-provider-stackit/blob/main/docs/data-sources/logme_instance.md This Terraform configuration defines a data source for retrieving information about a LogMe instance. It requires the project ID and instance ID as input and fetches details like CF GUID, dashboard URL, and instance parameters. ```terraform data "stackit_logme_instance" "example" { project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" instance_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" } ``` -------------------------------- ### SQLServer Flex Instance Data Source Example Source: https://github.com/stackitcloud/terraform-provider-stackit/blob/main/docs/data-sources/sqlserverflex_instance.md This example demonstrates how to define a stackit_sqlserverflex_instance data source. It requires the project ID and instance ID to be specified. The region can optionally be defined, otherwise the provider's region is used. ```terraform data "stackit_sqlserverflex_instance" "example" { project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" instance_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" } ``` -------------------------------- ### Deploy Test Pod in Example Namespace Source: https://github.com/stackitcloud/terraform-provider-stackit/blob/main/docs/guides/ske_kube_state_metric_alerts.md This HCL snippet creates a Kubernetes namespace named 'example' and then deploys a simple Nginx pod within that namespace. This deployment is intended to test the alert group defined previously, demonstrating how pod status can trigger notifications. ```hcl resource "kubernetes_namespace" "example" { metadata { name = "example" } } resource "kubernetes_pod" "example" { metadata { name = "nginx" namespace = kubernetes_namespace.example.metadata[0].name labels = { app = "nginx" } } spec { container { image = "nginx:latest" name = "nginx" } } } ``` -------------------------------- ### stackit_kms_keyring Data Source Example Source: https://github.com/stackitcloud/terraform-provider-stackit/blob/main/docs/data-sources/kms_keyring.md Example usage of the stackit_kms_keyring data source to retrieve KMS Keyring information. It requires the project ID and keyring ID, with an optional region parameter. ```terraform data "stackit_kms_keyring" "example" { project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" keyring_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" } ``` -------------------------------- ### stackit_kms_wrapping_key Data Source Example Source: https://github.com/stackitcloud/terraform-provider-stackit/blob/main/docs/data-sources/kms_wrapping_key.md This example demonstrates how to use the stackit_kms_wrapping_key data source to retrieve information about a KMS wrapping key. It requires the project ID, keyring ID, and wrapping key ID as input. ```terraform data "stackit_kms_wrapping_key" "example" { project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" keyring_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" wrapping_key_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" } ``` -------------------------------- ### stackit_scf_platform Data Source Example Source: https://github.com/stackitcloud/terraform-provider-stackit/blob/main/docs/data-sources/scf_platform.md This example demonstrates how to use the stackit_scf_platform data source to retrieve details about a specific Cloud Foundry platform. It requires the project ID and platform ID as input. ```terraform data "stackit_scf_platform" "example" { project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" platform_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" } ``` -------------------------------- ### Example Usage of stackit_server_backup_schedules Source: https://github.com/stackitcloud/terraform-provider-stackit/blob/main/docs/data-sources/server_backup_schedules.md This example demonstrates how to use the stackit_server_backup_schedules data source to retrieve backup schedules for a specific server. It requires the project ID and server ID as input. ```terraform data "stackit_server_backup_schedules" "example" { project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" server_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" } ``` -------------------------------- ### stackit_mariadb_credential Data Source Example Source: https://github.com/stackitcloud/terraform-provider-stackit/blob/main/docs/data-sources/mariadb_credential.md Example usage of the stackit_mariadb_credential data source. This block defines the required project_id, instance_id, and credential_id to retrieve MariaDB credential information. ```terraform data "stackit_mariadb_credential" "example" { project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" instance_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" credential_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" } ``` -------------------------------- ### stackit_objectstorage_bucket Data Source Example Source: https://github.com/stackitcloud/terraform-provider-stackit/blob/main/docs/data-sources/objectstorage_bucket.md This example demonstrates how to use the stackit_objectstorage_bucket data source to retrieve information about an ObjectStorage bucket. It requires the `project_id` and `name` of the bucket. The `region` can be optionally specified; otherwise, the provider's region is used. ```terraform data "stackit_objectstorage_bucket" "example" { project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" name = "example-name" } ``` -------------------------------- ### Configure Stackit Server Network Setup (Terraform) Source: https://github.com/stackitcloud/terraform-provider-stackit/blob/main/docs/resources/server.md Sets up networking for a Stackit server, including creating a network, security group, network interface, and then associating them with the server. Also shows how to assign a public IP. ```terraform resource "stackit_network" "network" { project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" name = "example-network" nameservers = ["192.0.2.0", "198.51.100.0", "203.0.113.0"] ipv4_prefix_length = 24 } resource "stackit_security_group" "sec-group" { project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" name = "example-security-group" stateful = true } resource "stackit_security_group_rule" "rule" { project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" security_group_id = stackit_security_group.sec-group.security_group_id direction = "ingress" ether_type = "IPv4" } resource "stackit_network_interface" "nic" { project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" network_id = stackit_network.network.network_id security_group_ids = [stackit_security_group.sec-group.security_group_id] } resource "stackit_server" "server-with-network" { project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" name = "example-server" boot_volume = { size = 64 source_type = "image" source_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" } machine_type = "g2i.1" keypair_name = stackit_key_pair.keypair.name network_interfaces = [ stackit_network_interface.nic.network_interface_id ] } resource "stackit_public_ip" "public-ip" { project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" network_interface_id = stackit_network_interface.nic.network_interface_id } ``` -------------------------------- ### stackit_sfs_resource_pool Data Source Example Source: https://github.com/stackitcloud/terraform-provider-stackit/blob/main/docs/data-sources/sfs_resource_pool.md This example demonstrates how to use the stackit_sfs_resource_pool data source to retrieve information about a specific resource pool. It requires the project ID and resource pool ID as input. ```terraform data "stackit_sfs_resource_pool" "resourcepool" { project_id = "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX" resource_pool_id = "YYYYYYYY-YYYY-YYYY-YYYY-YYYYYYYYYYYY" } ``` -------------------------------- ### stackit_network_interface Data Source Example Source: https://github.com/stackitcloud/terraform-provider-stackit/blob/main/docs/data-sources/network_interface.md Demonstrates how to use the stackit_network_interface data source to retrieve information about a network interface. It requires the project ID, network ID, and network interface ID as input. ```terraform data "stackit_network_interface" "example" { project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" network_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" network_interface_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" } ``` -------------------------------- ### Stackit Edge Cloud Kubeconfig Resource Example Source: https://github.com/stackitcloud/terraform-provider-stackit/blob/main/docs/resources/edgecloud_kubeconfig.md This Terraform code defines the stackit_edgecloud_kubeconfig resource, which is used to manage kubeconfig files for Stackit's Edge Cloud instances. It demonstrates how to create a kubeconfig by referencing an existing Edge Cloud instance either by its display name or its ID. The example also shows how to set the expiration time for the kubeconfig in seconds. Dependencies include the stackit_edgecloud_instance resource and provider-level configurations for project ID and region. ```terraform # the instance resource only exists here to illustrate the usage of it's attribute resource "stackit_edgecloud_instance" "this" { project_id = local.project_id display_name = "example" plan_id = var.plan_id description = "some_description" } resource "stackit_edgecloud_kubeconfig" "by_name" { project_id = var.project_id instance_name = stackit_edgecloud_instance.this.display_name expiration = 3600 # seconds } resource "stackit_edgecloud_kubeconfig" "by_id" { project_id = var.project_id instance_id = stackit_edgecloud_instance.this.instance_id expiration = 3600 # seconds } ``` -------------------------------- ### Example Usage of stackit_git Data Source Source: https://github.com/stackitcloud/terraform-provider-stackit/blob/main/docs/data-sources/git.md This code snippet demonstrates how to use the stackit_git data source to retrieve information about a Git instance. It requires the project ID and instance ID as input. ```terraform data "stackit_git" "git" { project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" instance_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" } ``` -------------------------------- ### Install STACKIT Terraform Provider Source: https://github.com/stackitcloud/terraform-provider-stackit/blob/main/README.md This code snippet shows how to configure your Terraform project to use the STACKIT provider. It specifies the source and version of the provider and includes a basic provider block for configuration. ```hcl terraform { required_providers { stackit = { source = "stackitcloud/stackit" version = "X.X.X" } } } provider "stackit" { # Configuration options } ``` -------------------------------- ### Create Stackit Server Booting from Image Source: https://github.com/stackitcloud/terraform-provider-stackit/blob/main/docs/resources/server.md Configures a Stackit server instance to boot from a specified image. This example demonstrates setting the project ID, boot volume details, server name, machine type, and availability zone. ```terraform resource "stackit_server" "boot-from-volume" { project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" name = "example-server" boot_volume = { size = 64 source_type = "image" source_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" } availability_zone = "eu01-1" machine_type = "g2i.1" keypair_name = "example-keypair" } ``` -------------------------------- ### stackit_secretsmanager_instance Data Source Example Source: https://github.com/stackitcloud/terraform-provider-stackit/blob/main/docs/data-sources/secretsmanager_instance.md Example usage of the stackit_secretsmanager_instance data source to retrieve Secrets Manager instance details. It requires the project ID and instance ID as input. ```terraform data "stackit_secretsmanager_instance" "example" { project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" instance_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" } ``` -------------------------------- ### Create Stackit Server Booting from Existing Volume Source: https://github.com/stackitcloud/terraform-provider-stackit/blob/main/docs/resources/server.md Sets up a Stackit server instance that boots from an already existing volume. This requires defining the volume first and then referencing its ID in the server's boot volume configuration. ```terraform resource "stackit_volume" "example-volume" { project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" size = 12 source = { type = "image" id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" } name = "example-volume" availability_zone = "eu01-1" } resource "stackit_server" "boot-from-volume" { project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" name = "example-server" boot_volume = { source_type = "volume" source_id = stackit_volume.example-volume.volume_id } availability_zone = "eu01-1" machine_type = "g2i.1" keypair_name = stackit_key_pair.keypair.name } ``` -------------------------------- ### Configure and Run Terraform Acceptance Tests Source: https://github.com/stackitcloud/terraform-provider-stackit/blob/main/README.md This snippet demonstrates how to configure environment variables and execute Terraform acceptance tests for a specific service. It requires setting `TF_ACC`, `TF_ACC_PROJECT_ID`, `TF_ACC_REGION`, and optionally `STACKIT_SERVICE_ACCOUNT_KEY_PATH`. The `go test` command is used with a specified timeout and verbosity. ```shell # acc-tests.env export TF_ACC="1" export TF_ACC_REGION="eu01" ... ``` ```shell source acc-tests.env ``` ```shell $ go test -timeout=60m -v stackit/internal/services//_acc_test.go ``` ```shell $ TF_ACC=1 \ TF_ACC_PROJECT_ID= \ TF_ACC_REGION= \ STACKIT_SERVICE_ACCOUNT_KEY_PATH= \ go test -timeout=60m -v stackit/internal/services//_acc_test.go ``` -------------------------------- ### Initialize Terraform Source: https://github.com/stackitcloud/terraform-provider-stackit/blob/main/docs/guides/scf_cloudfoundry.md Initializes the Terraform working directory and downloads necessary provider plugins. This command should be run before applying any Terraform configurations. ```bash terraform init ``` -------------------------------- ### Create STACKIT Server Instance Source: https://context7.com/stackitcloud/terraform-provider-stackit/llms.txt Create and manage virtual machine instances in STACKIT IaaS. This includes setting up SSH key pairs, network infrastructure, security groups, network interfaces, and the server itself with boot volumes and user data. ```hcl # Create SSH key pair resource "stackit_key_pair" "keypair" { name = "my-keypair" public_key = chomp(file("~/.ssh/id_rsa.pub")) } # Create network infrastructure resource "stackit_network" "network" { project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" name = "my-network" ipv4_nameservers = ["8.8.8.8", "8.8.4.4"] ipv4_prefix_length = 24 routed = true } resource "stackit_security_group" "sg" { project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" name = "my-security-group" stateful = true } resource "stackit_security_group_rule" "ssh" { project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" security_group_id = stackit_security_group.sg.security_group_id direction = "ingress" ether_type = "IPv4" protocol = { name = "tcp" } port_range = { min = 22 max = 22 } } resource "stackit_network_interface" "nic" { project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" network_id = stackit_network.network.network_id security_group_ids = [stackit_security_group.sg.security_group_id] } # Create server with boot volume from image resource "stackit_server" "server" { project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" name = "my-server" availability_zone = "eu01-1" machine_type = "g2i.2" # 2 vCPU, 8GB RAM keypair_name = stackit_key_pair.keypair.name boot_volume = { size = 64 source_type = "image" source_id = "59838a89-51b1-4892-b57f-b3caf598ee2f" # Ubuntu 24.04 performance_class = "storage_premium_perf6" } network_interfaces = [stackit_network_interface.nic.network_interface_id] user_data = <<-EOF #cloud-config packages: - nginx runcmd: - systemctl enable nginx - systemctl start nginx EOF } # Assign public IP resource "stackit_public_ip" "public_ip" { project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" network_interface_id = stackit_network_interface.nic.network_interface_id } output "server_public_ip" { value = stackit_public_ip.public_ip.ip } ``` -------------------------------- ### stackit_sfs_share Data Source Example Usage Source: https://github.com/stackitcloud/terraform-provider-stackit/blob/main/docs/data-sources/sfs_share.md Example usage of the stackit_sfs_share data source to retrieve SFS share details. It requires project ID, resource pool ID, and share ID as input. ```terraform data "stackit_sfs_share" "example" { project_id = "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX" resource_pool_id = "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX" share_id = "YYYYYYYY-YYYY-YYYY-YYYY-YYYYYYYYYYYY" } ``` -------------------------------- ### ObjectStorage Credentials Group Data Source Example Source: https://github.com/stackitcloud/terraform-provider-stackit/blob/main/docs/data-sources/objectstorage_credentials_group.md Example usage for the stackit_objectstorage_credentials_group data source. It requires the project ID and credentials group ID. The region can be optionally specified or inherited from the provider configuration. ```terraform data "stackit_objectstorage_credentials_group" "example" { project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" credentials_group_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" } ``` -------------------------------- ### ObjectStorage Credential Data Source Example Source: https://github.com/stackitcloud/terraform-provider-stackit/blob/main/docs/data-sources/objectstorage_credential.md Example usage of the stackit_objectstorage_credential data source to retrieve object storage credential details. It requires project ID, credentials group ID, and credential ID as input. ```terraform data "stackit_objectstorage_credential" "example" { project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" credentials_group_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" credential_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" } ``` -------------------------------- ### Create and Import RabbitMQ Instance Source: https://github.com/stackitcloud/terraform-provider-stackit/blob/main/docs/resources/rabbitmq_instance.md Defines the creation of a RabbitMQ instance with specified project ID, name, version, plan, and parameters. It also includes an example of how to import an existing RabbitMQ instance using its project ID and instance ID. ```terraform resource "stackit_rabbitmq_instance" "example" { project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" name = "example-instance" version = "3.13" plan_name = "stackit-rabbitmq-1.2.10-replica" parameters = { sgw_acl = "193.148.160.0/19,45.129.40.0/21,45.135.244.0/22" consumer_timeout = 18000000 enable_monitoring = false plugins = ["rabbitmq_consistent_hash_exchange", "rabbitmq_federation", "rabbitmq_tracing"] } } # Only use the import statement, if you want to import an existing rabbitmq instance import { to = stackit_rabbitmq_instance.import-example id = "${var.project_id},${var.rabbitmq_instance_id}" } ``` -------------------------------- ### stackit_logme_credential Data Source Example Source: https://github.com/stackitcloud/terraform-provider-stackit/blob/main/docs/data-sources/logme_credential.md Example usage of the stackit_logme_credential data source in Terraform. This snippet demonstrates how to configure the data source with required project, instance, and credential IDs to retrieve LogMe credential information. ```terraform data "stackit_logme_credential" "example" { project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" instance_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" credential_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" } ``` -------------------------------- ### Create and Import PostgresFlex Instance - Terraform Source: https://github.com/stackitcloud/terraform-provider-stackit/blob/main/docs/resources/postgresflex_instance.md Defines a Postgres Flex instance resource with project ID, name, ACL, backup schedule, flavor, replicas, storage, and version. It also shows how to import an existing instance using its project ID, region, and instance ID. ```terraform resource "stackit_postgresflex_instance" "example" { project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" name = "example-instance" acl = ["XXX.XXX.XXX.X/XX", "XX.XXX.XX.X/XX"] backup_schedule = "00 00 * * *" flavor = { cpu = 2 ram = 4 } replicas = 3 storage = { class = "class" size = 5 } version = 14 } # Only use the import statement, if you want to import an existing postgresflex instance import { to = stackit_postgresflex_instance.import-example id = "${var.project_id},${var.region},${var.postgres_instance_id}" } ``` -------------------------------- ### Create STACKIT Server Instance Source: https://github.com/stackitcloud/terraform-provider-stackit/blob/main/docs/guides/using_loadbalancer_with_observability.md Provisions a STACKIT server instance, specifying boot volume details, availability zone, machine type, and key pair for SSH access. Requires project ID, image ID, and network interface. Outputs server name and IP address. ```hcl # Create a key pair for accessing the server instance resource "stackit_key_pair" "keypair" { name = "example-key-pair" # set the path of your public key file here public_key = chomp(file("/home/bob/.ssh/id_ed25519.pub")) } # Create a server instance resource "stackit_server" "boot-from-image" { project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" name = "example-server" boot_volume = { size = 64 source_type = "image" source_id = "59838a89-51b1-4892-b57f-b3caf598ee2f" // Ubuntu 24.04 } availability_zone = "eu01-1" machine_type = "g2i.1" keypair_name = stackit_key_pair.keypair.name network_interfaces = [ stackit_network_interface.nic.network_interface_id ] } ``` -------------------------------- ### STACKIT Provider Authentication - Credentials File Example Source: https://github.com/stackitcloud/terraform-provider-stackit/blob/main/README.md This JSON snippet demonstrates the structure of the STACKIT credentials file. It shows how to specify authentication details, such as the service account token and the path to the service account key file, for the Terraform provider. ```json { "STACKIT_SERVICE_ACCOUNT_TOKEN": "foo_token", "STACKIT_SERVICE_ACCOUNT_KEY_PATH": "path/to/sa_key.json" } ``` -------------------------------- ### Key Flow: Environment Variable Configuration Source: https://github.com/stackitcloud/terraform-provider-stackit/blob/main/docs/index.md Demonstrates how to configure the Stackit Terraform Provider for the key flow using environment variables for the service account key path. ```bash # Set the environment variable for the service account key path export STACKIT_SERVICE_ACCOUNT_KEY_PATH=/path/to/service-account-key.json # Optionally, for private key: # export STACKIT_PRIVATE_KEY_PATH=/path/to/private.pem ``` -------------------------------- ### Install Prometheus Operator with Custom Helm Values Source: https://github.com/stackitcloud/terraform-provider-stackit/blob/main/docs/guides/ske_kube_state_metric_alerts.md Installs the Prometheus Operator using a Helm chart, enabling agent mode and remote write to send metrics to STACKIT Observability. Includes custom values for Prometheus spec and remote write configuration, with specific relabeling rules. ```yaml # helm values # save as prom-values.tftpl prometheus: enabled: true agentMode: true prometheusSpec: enableRemoteWriteReceiver: true scrapeInterval: 60s evaluationInterval: 60s replicas: 1 storageSpec: volumeClaimTemplate: spec: storageClassName: premium-perf4-stackit accessModes: ['ReadWriteOnce'] resources: requests: storage: 80Gi remoteWrite: - url: ${metrics_push_url} queueConfig: batchSendDeadline: '5s' # both values need to be configured according to your observability plan capacity: 30000 maxSamplesPerSend: 3000 writeRelabelConfigs: - sourceLabels: ['__name__'] regex: 'apiserver_.*|etcd_.*|prober_.*|storage_.*|workqueue_(work|queue)_duration_seconds_bucket|kube_pod_tolerations|kubelet_.*|kubernetes_feature_enabled|instance_scrape_target_status' action: 'drop' ``` -------------------------------- ### Terraform Redis Credential Resource Example Source: https://github.com/stackitcloud/terraform-provider-stackit/blob/main/docs/resources/redis_credential.md This Terraform configuration defines a `stackit_redis_credential` resource, which is used to manage credentials for a Redis instance. It requires the project ID and instance ID as input. The example also shows how to import an existing Redis credential using its project ID, instance ID, and credential ID. ```terraform resource "stackit_redis_credential" "example" { project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" instance_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" } # Only use the import statement, if you want to import an existing redis credential import { to = stackit_redis_credential.import-example id = "${var.project_id},${var.redis_instance_id},${var.redis_credential_id}" } ``` -------------------------------- ### Configure Stackit Network and Security for Server Source: https://github.com/stackitcloud/terraform-provider-stackit/blob/main/docs/resources/server.md Demonstrates the setup of network resources, including a network with specified IP addressing and DNS servers, a security group, and a security group rule for ingress traffic. These are then used to configure a network interface for a server. ```terraform resource "stackit_network" "network" { project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" name = "example-network" nameservers = ["192.0.2.0", "198.51.100.0", "203.0.113.0"] ipv4_prefix_length = 24 } resource "stackit_security_group" "sec-group" { project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" name = "example-security-group" stateful = true } resource "stackit_security_group_rule" "rule" { project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" security_group_id = stackit_security_group.sec-group.security_group_id direction = "ingress" ether_type = "IPv4" } resource "stackit_network_interface" "nic" { project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" network_id = stackit_network.network.network_id security_group_ids = [stackit_security_group.sec-group.security_group_id] } ``` -------------------------------- ### Create STACKIT Observability Instance and Credentials Source: https://github.com/stackitcloud/terraform-provider-stackit/blob/main/docs/guides/using_loadbalancer_with_observability.md Creates a STACKIT Observability instance with specified retention policies and generates associated credentials. Requires a valid project ID and plan name. Outputs instance ID, logs push URL, and credential username/password. ```hcl resource "stackit_observability_instance" "observability01" { project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" name = "example-instance" plan_name = "Observability-Monitoring-Medium-EU01" acl = ["0.0.0.0/0"] metrics_retention_days = 90 metrics_retention_days_5m_downsampling = 90 metrics_retention_days_1h_downsampling = 90 } resource "stackit_observability_credential" "observability01-credential" { project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" instance_id = stackit_observability_instance.observability01.instance_id } ``` -------------------------------- ### stackit_cdn_custom_domain Data Source Example Source: https://github.com/stackitcloud/terraform-provider-stackit/blob/main/docs/data-sources/cdn_custom_domain.md Example usage of the stackit_cdn_custom_domain data source in Terraform. This block defines a data source to retrieve information about a CDN custom domain, requiring the project ID, distribution ID, and the custom domain name. It's used to fetch existing CDN distribution configurations. ```terraform data "stackit_cdn_custom_domain" "example" { project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" distribution_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" name = "https://xxx.xxx" } ``` -------------------------------- ### GET /stackit/network_area Source: https://github.com/stackitcloud/terraform-provider-stackit/blob/main/docs/resources/network_area.md Retrieves a list of network areas within a specified STACKIT organization. ```APIDOC ## GET /stackit/network_area ### Description Retrieves a list of network areas within a specified STACKIT organization. ### Method GET ### Endpoint /stackit/network_area ### Parameters #### Query Parameters - **organization_id** (String) - Required - The STACKIT organization ID to filter network areas. ### Response #### Success Response (200 OK) - **network_areas** (Array of Objects) - A list of network area objects. - **id** (String) - The unique identifier for the network area. - **network_area_id** (String) - The ID of the network area. - **organization_id** (String) - The organization ID associated with the network area. - **name** (String) - The name of the network area. - **labels** (Map of String) - Labels associated with the network area. - **project_count** (Number) - The number of projects currently referencing this area. #### Response Example ```json { "network_areas": [ { "id": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx,yyyyyyyy-yyyy-yyyy-yyyy-yyyyyyyyyyyy", "network_area_id": "yyyyyyyy-yyyy-yyyy-yyyy-yyyyyyyyyyyy", "organization_id": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", "name": "example-network-area", "labels": { "key": "value" }, "project_count": 0 } ] } ``` ``` -------------------------------- ### GET /stackit/network_area/{network_area_id} Source: https://github.com/stackitcloud/terraform-provider-stackit/blob/main/docs/resources/network_area.md Retrieves details of a specific network area within a STACKIT organization. ```APIDOC ## GET /stackit/network_area/{network_area_id} ### Description Retrieves details of a specific network area within a STACKIT organization. ### Method GET ### Endpoint /stackit/network_area/{network_area_id} ### Parameters #### Path Parameters - **network_area_id** (String) - Required - The ID of the network area to retrieve. #### Query Parameters - **organization_id** (String) - Required - The STACKIT organization ID to which the network area belongs. ### Response #### Success Response (200 OK) - **id** (String) - The unique identifier for the network area. - **network_area_id** (String) - The ID of the network area. - **organization_id** (String) - The organization ID associated with the network area. - **name** (String) - The name of the network area. - **labels** (Map of String) - Labels associated with the network area. - **project_count** (Number) - The number of projects currently referencing this area. #### Response Example ```json { "id": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx,yyyyyyyy-yyyy-yyyy-yyyy-yyyyyyyyyyyy", "network_area_id": "yyyyyyyy-yyyy-yyyy-yyyy-yyyyyyyyyyyy", "organization_id": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", "name": "example-network-area", "labels": { "key": "value" }, "project_count": 0 } ``` ``` -------------------------------- ### Terraform Public IP Association Example Source: https://github.com/stackitcloud/terraform-provider-stackit/blob/main/docs/resources/public_ip_associate.md This Terraform configuration demonstrates how to associate an existing public IP address with a network interface. It requires the project ID, the ID of the public IP to associate, and the ID of the network interface. An example of importing an existing association is also provided, which requires the project ID, region, public IP ID, and network interface ID. ```terraform resource "stackit_public_ip_associate" "example" { project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" public_ip_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" network_interface_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" } # Only use the import statement, if you want to import an existing public ip associate import { to = stackit_public_ip_associate.import-example id = "${var.project_id},${var.region},${var.public_ip_id},${var.network_interface_id}" } ``` -------------------------------- ### Create SQLServer Flex Instance Source: https://github.com/stackitcloud/terraform-provider-stackit/blob/main/docs/resources/sqlserverflex_instance.md Defines a SQLServer Flex instance resource with essential parameters like project ID, name, ACL, backup schedule, flavor (CPU and RAM), storage (class and size), and version. The region can be specified or inherited from the provider configuration. ```terraform resource "stackit_sqlserverflex_instance" "example" { project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" name = "example-instance" acl = ["XXX.XXX.XXX.X/XX", "XX.XXX.XX.X/XX"] backup_schedule = "00 00 * * *" flavor = { cpu = 4 ram = 16 } storage = { class = "class" size = 5 } version = 2022 } ``` -------------------------------- ### stackit_security_group Data Source Source: https://github.com/stackitcloud/terraform-provider-stackit/blob/main/docs/data-sources/security_group.md Use the stackit_security_group data source to get information about an existing Security Group. ```APIDOC ## stackit_security_group (Data Source) ### Description Security group datasource schema. Must have a `region` specified in the provider configuration. ### Method GET ### Endpoint `/security-groups/{security_group_id}` ### Parameters #### Path Parameters - **security_group_id** (String) - Required - The security group ID. #### Query Parameters - **project_id** (String) - Required - STACKIT project ID to which the security group is associated. - **region** (String) - Optional - The resource region. If not defined, the provider region is used. ### Request Example ```terraform data "stackit_security_group" "example" { project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" security_group_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" } ``` ### Response #### Success Response (200) - **description** (String) - The description of the security group. - **id** (String) - Terraform's internal resource ID. It is structured as "`project_id`,`region`,`security_group_id`". - **labels** (Map of String) - Labels are key-value string pairs which can be attached to a resource container. - **name** (String) - The name of the security group. - **stateful** (Boolean) - Configures if a security group is stateful or stateless. There can only be one type of security groups per network interface/server. #### Response Example ```json { "description": "My security group description", "id": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx,eu-central-1,xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", "labels": { "environment": "production" }, "name": "my-security-group", "stateful": true } ``` ``` -------------------------------- ### Hibernation Configuration Source: https://github.com/stackitcloud/terraform-provider-stackit/blob/main/docs/resources/ske_cluster.md Configure hibernation settings for your STACKIT Kubernetes Engine cluster, including start and end times, and timezone. ```APIDOC ## Hibernation Configuration ### Description Configure hibernation settings for your STACKIT Kubernetes Engine cluster, including start and end times, and timezone. ### Method (Not specified, typically part of a PUT or POST request for cluster configuration) ### Endpoint (Not specified, typically part of a cluster update endpoint) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **hibernations** (Object) - Configuration for cluster hibernation. - **end** (String) - Required - End time of hibernation in crontab syntax. E.g. `0 8 * * *` for waking up the cluster at 8am. - **start** (String) - Required - Start time of cluster hibernation in crontab syntax. E.g. `0 18 * * *` for starting everyday at 6pm. - **timezone** (String) - Optional - Timezone name corresponding to a file in the IANA Time Zone database. i.e. `Europe/Berlin`. ### Request Example ```json { "hibernations": { "start": "0 18 * * *", "end": "0 8 * * *", "timezone": "Europe/Berlin" } } ``` ### Response #### Success Response (200) (Response structure not specified, but would typically echo the updated configuration) #### Response Example ```json { "hibernations": { "start": "0 18 * * *", "end": "0 8 * * *", "timezone": "Europe/Berlin" } } ``` ``` -------------------------------- ### Create and Push Git Tag Source: https://github.com/stackitcloud/terraform-provider-stackit/blob/main/RELEASE.md This snippet demonstrates how to create a new git tag for a release and push it to the origin. This action triggers the release pipeline. ```bash git tag vX.X.X git push origin --tags ``` -------------------------------- ### Define Kubernetes Namespace Resource Source: https://github.com/stackitcloud/terraform-provider-stackit/blob/main/docs/guides/kubernetes_provider_ske.md Creates a Kubernetes Namespace resource. This is an example of a basic Kubernetes resource that can be managed after configuring the Kubernetes provider. ```hcl resource "kubernetes_namespace" "dev" { metadata { name = "dev" } } ``` -------------------------------- ### Complete STACKIT CDN Terraform Configuration Source: https://github.com/stackitcloud/terraform-provider-stackit/blob/main/docs/guides/stackit_cdn_with_custom_domain.md Provides a complete Terraform configuration file (`main.tf`) for setting up a STACKIT CDN distribution. It includes provider configuration, DNS zone, CDN distribution, CNAME record, and custom domain resources in the correct order of operations. ```terraform # This configuration file sets up a complete STACKIT CDN distribution # with a custom domain managed by STACKIT DNS. # ----------------------------------------------------------------------------- # PROVIDER CONFIGURATION ``` -------------------------------- ### Create stackit_git Resource Source: https://github.com/stackitcloud/terraform-provider-stackit/blob/main/docs/resources/git.md Defines a Git instance resource with a project ID and name. Optionally, ACLs and flavor can be specified. If flavor is not provided, it defaults to 'git-100'. ```terraform resource "stackit_git" "git" { project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" name = "git-example-instance" } resource "stackit_git" "git" { project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" name = "git-example-instance" acl = [ "0.0.0.0/0" ] flavor = "git-100" } ``` -------------------------------- ### stackit_affinity_group Data Source Source: https://github.com/stackitcloud/terraform-provider-stackit/blob/main/docs/data-sources/affinity_group.md Use the stackit_affinity_group data source to get information about an existing affinity group. This allows you to reference its properties in your infrastructure configuration. ```APIDOC ## stackit_affinity_group Data Source ### Description Use the `stackit_affinity_group` data source to retrieve details about an existing affinity group. This is useful for referencing its properties, such as name, members, and policy, in other Stackit resources or configurations. ### Method DATA SOURCE ### Endpoint N/A (Data Source) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```terraform data "stackit_affinity_group" "example" { project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" affinity_group_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" } ``` ### Response #### Success Response (200) - **id** (String) - Terraform's internal resource identifier. It is structured as "`project_id`,`region`,`affinity_group_id`". - **members** (List of String) - List of members associated with the affinity group. - **name** (String) - The name of the affinity group. - **policy** (String) - The policy applied to the affinity group. #### Response Example ```json { "id": ",,", "members": [ "member1", "member2" ], "name": "example-affinity-group", "policy": "even-host-distribution" } ``` ``` -------------------------------- ### Create Stackit Server with User Data from File (Terraform) Source: https://github.com/stackitcloud/terraform-provider-stackit/blob/main/docs/resources/server.md Defines a Stackit server resource, specifying project ID, boot volume details, server name, machine type, key pair, and user data loaded from a file. Requires the `stackit_key_pair` resource to be defined. ```terraform resource "stackit_server" "user-data-from-file" { project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" boot_volume = { size = 64 source_type = "image" source_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" } name = "example-server" machine_type = "g2i.1" keypair_name = stackit_key_pair.keypair.name user_data = file("${path.module}/cloud-init.yaml") } ```