STACKIT 的官方 Terraform 提供商
This project is the official Terraform Provider for STACKIT, which allows you to manage STACKIT resources through Terraform.
To install the STACKIT Terraform Provider, copy and paste this code into your Terraform configuration. Then, run terraform init.
terraform {
required_providers {
stackit = {
source = "stackitcloud/stackit"
version = "X.X.X"
}
}
}
provider "stackit" {
# Configuration options
}Check one of the examples in the examples folder.
To authenticate, you will need a service account. Create it in the STACKIT Portal and assign the necessary permissions to it, e.g. project.owner. There are multiple ways to authenticate:
When setting up authentication, the provider will always try to use the key flow first and search for credentials in several locations, following a specific order:
Explicit configuration, e.g. by setting the field service_account_key_path in the provider block (see example below)
Environment variable, e.g. by setting STACKIT_SERVICE_ACCOUNT_KEY_PATH or STACKIT_SERVICE_ACCOUNT_KEY
Credentials file
The provider will check the credentials file located in the path defined by the STACKIT_CREDENTIALS_PATH env var, if specified,
or in $HOME/.stackit/credentials.json as a fallback.
The credentials file should be a JSON and each credential should be set using the name of the respective environment variable, as stated below in each flow. Example:
{
"STACKIT_SERVICE_ACCOUNT_TOKEN": "foo_token",
"STACKIT_SERVICE_ACCOUNT_KEY_PATH": "path/to/sa_key.json"
}The following instructions assume that you have created a service account and assigned the necessary permissions to it, e.g. `project.owner`.To use the key flow, you need to have a service account key, which must have an RSA key-pair attached to it.
When creating the service account key, a new pair can be created automatically, which will be included in the service account key. This will make it much easier to configure the key flow authentication in the STACKIT Terraform Provider, by just providing the service account key.
Optionally, you can provide your own private key when creating the service account key, which will then require you to also provide it explicitly to the STACKIT Terraform Provider, additionally to the service account key. Check the STACKIT Docs for an example of how to create your own key-pair.
To configure the key flow, follow this steps:
Service Accounts tab, choose a Service Account and go to Service Account Keys to create a key. For more details, see Create a service account keySave the content of the service account key by copying it and saving it in a JSON file.
The expected format of the service account key is a JSON with the following structure:
{
"id": "uuid",
"publicKey": "public key",
"createdAt": "2023-08-24T14:15:22Z",
"validUntil": "2023-08-24T14:15:22Z",
"keyType": "USER_MANAGED",
"keyOrigin": "USER_PROVIDED",
"keyAlgorithm": "RSA_2048",
"active": true,
"credentials": {
"kid": "string",
"iss": "[email protected]",
"sub": "uuid",
"aud": "string",
(optional) "privateKey": "private key when generated by the SA service"
}
}Configure the service account key for authentication in the provider by following one of the alternatives below:
service_account_key or service_account_key_pathSTACKIT_SERVICE_ACCOUNT_KEY_PATH or STACKIT_SERVICE_ACCOUNT_KEYSTACKIT_SERVICE_ACCOUNT_KEY is correctly formatted. Use e.g.
$ export STACKIT_SERVICE_ACCOUNT_KEY=$(cat ./service-account-key.json)STACKIT_SERVICE_ACCOUNT_KEY_PATH in the credentials file (see above)Optionally, only if you have provided your own RSA key-pair when creating the service account key, you also need to configure your private key (takes precedence over the one included in the service account key, if present). The private key must be PEM encoded and can be provided using one of the options below:
- setting the field in the provider block:
private_keyorprivate_key_path- setting the environment variable:
STACKIT_PRIVATE_KEY_PATHorSTACKIT_PRIVATE_KEY- setting
STACKIT_PRIVATE_KEY_PATHin the credentials file (see above)
Is scheduled for deprecation and will be removed on December 17, 2025.
Using this flow is less secure since the token is long-lived. You can provide the token in several ways:
service_account_token in the providerSTACKIT_SERVICE_ACCOUNT_TOKEN[!WARNING]
As of now settinguse_lockfile=truefor the S3 Backend will have no effect when using STACKIT Object Storage S3 buckets. If you want to make use of Terraforms state locking feature refer to the PostgreSQL backend described below.
To keep track of your Terraform state, you can configure an S3 backend using STACKIT Object Storage.
To do so, you need an Object Storage S3 bucket and credentials to access it. If you need to create them, check Create and delete Object Storage buckets and Create and delete Object Storage credentials.
Once you have everything setup, you can configure the backend by adding the following block to your Terraform configuration:
terraform {
backend "s3" {
bucket = "BUCKET_NAME"
key = "path/to/key"
endpoints = {
s3 = "https://object.storage.eu01.onstackit.cloud"
}
region = "eu01"
skip_credentials_validation = true
skip_region_validation = true
skip_s3_checksum = true
skip_requesting_account_id = true
secret_key = "SECRET_KEY"
access_key = "ACCESS_KEY"
}
}Note: AWS specific checks must be skipped as they do not work on STACKIT. For details on what those validations do, see here.
See this example how to use a STACKIT PostgreSQL instance for your Terraform state with state locking.
To use beta resources in the STACKIT Terraform provider, follow these steps:
Provider Configuration Option
Set the enable_beta_resources option in the provider configuration. This is a boolean attribute that can be either true or false.
provider "stackit" {
default_region = "eu01"
enable_beta_resources = true
}Environment Variable
Set the STACKIT_TF_ENABLE_BETA_RESOURCES environment variable to "true" or "false". Other values will be ignored and will produce a warning.
export STACKIT_TF_ENABLE_BETA_RESOURCES=trueNote: The environment variable takes precedence over the provider configuration option. This means that if the
STACKIT_TF_ENABLE_BETA_RESOURCESenvironment variable is set to a valid value ("true"or"false"), it will override theenable_beta_resourcesoption specified in the provider configuration.
For more details, please refer to the beta resources configuration guide.
Experiments are features that are even less mature and stable than Beta Resources. While there is some assumed stability in beta resources, will have to expect breaking changes while using experimental resources. Experimental Resources do not come with any support or warranty.
To enable experiments set the experiments field in the provider definition:
provider "stackit" {
default_region = "eu01"
experiments = ["iam", "routing-tables", "network", "dremio", "ske"]
}iamEnables IAM management features in the Terraform provider. The underlying IAM API is expected to undergo a redesign in the future, which leads to it being considered experimental.
routing-tablesThis feature enables experimental routing table capabilities in the Terraform Provider, available only to designated SNAs at this time.
networkThe stackit_network provides the fields region and routing_table_id when the experiment flag network is set.
The underlying API is not stable yet and could change in the future.
If you don't need these fields, don't set the experiment flag network, to use the stable api.
dremioEnables the usage and provisioning of STACKIT Dremio resources. The STACKIT Dremio API is currently in alpha state. The fields of the resources are still subject to change.
skeEnables experimental SKE features. These features are subject to change and may be removed or redesigned in future releases.
[!WARNING] Acceptance tests will create real resources, which may incur in costs. Some resource may leftover after a test run. This could happen if the tests are modified, tests are stopped during the run or losing the network connection. These resource must be removed manually with the STACKIT CLI or the STACKIT Portal.
Terraform acceptance tests are run using the command make test-acceptance-tf. For all services,
TF_ACC_PROJECT_ID must be set with the ID of the STACKIT test project to test it.TF_ACC_REGION must be set with the region in which the tests should be run.TF_ACC_XXXXXX_CUSTOM_ENDPOINT (where XXXXXX is the uppercase name of the service) can be set to use endpoints other than the default value.Additiona
暂无开放 Issues,或尚未同步最近议题。