This project is the official Terraform provider for STACKIT.
Check one of the examples in the examples folder.
To authenticate, you will need a service account. Create it in the STACKIT Portal an assign it the necessary permissions, e.g. project.owner. There are multiple ways to authenticate:
- Key flow (recommended)
- Token flow
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 seting the field
stackit_service_account_key_pathin the provider block (see example below) -
Environment variable, e.g. by setting
STACKIT_SERVICE_ACCOUNT_KEY_PATH -
Credentials file
The SDK will check the credentials file located in the path defined by the
STACKIT_CREDENTIALS_PATHenv var, if specified, or in$HOME/.stackit/credentials.jsonas 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 it the necessary permissions, 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 CLI, 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 CLI, additionaly to the service account key. Check the STACKIT Knowledge Base for an example of how to create your own key-pair.
To configure the key flow, follow this steps:
- Create a service account key:
- Use the STACKIT Portal: go to the
Service Accountstab, choose aService Accountand go toService Account Keysto create a key. For more details, see Create a service account key
-
Save 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": "my-sa@sa.stackit.cloud",
"sub": "uuid",
"aud": "string",
(optional) "privateKey": "private key when generated by the SA service"
}
}-
Configure the service account key for authentication in the SDK by following one of the alternatives below:
- setting the fiels in the provider block:
service_account_keyorservice_account_key_path - setting the environment variable:
STACKIT_SERVICE_ACCOUNT_KEY_PATH - setting
STACKIT_SERVICE_ACCOUNT_KEY_PATHin the credentials file (see above)
- setting the fiels in the provider block:
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_PATH- setting
STACKIT_PRIVATE_KEY_PATHin the credentials file (see above)
Using this flow is less secure since the token is long-lived. You can provide the token in several ways:
- Setting the field
service_account_tokenin the provider - Setting the environment variable
STACKIT_SERVICE_ACCOUNT_TOKEN - Setting it in the credentials file (see above)
Terraform acceptance tests are run using the command make test-acceptance-tf. For all services,
- The env var
TF_ACC_PROJECT_IDmust be set with the ID of the STACKIT test project to test it. - Authentication is set as usual.
- Optionally, the env var
TF_ACC_XXXXXX_CUSTOM_ENDPOINT(whereXXXXXXis the uppercase name of the service) can be set to use endpoints other than the default value.
Additionally, for the Resource Manager service,
- A service account with permissions to create and delete projects is required.
- The env var
TF_ACC_TEST_PROJECT_SERVICE_ACCOUNT_EMAILmust be set as the email of the service account. - The env var
TF_ACC_TEST_PROJECT_SERVICE_ACCOUNT_TOKENmust be set as a valid token of the service account. Can also be set in the credentials file used by authentication (see Authentication for more details) - The env var
TF_ACC_PROJECT_IDis ignored.
WARNING: Acceptance tests will create real resources, which may incur in costs.
For guidance on how to migrate to using this provider, please see our Migration Guide.
If you encounter any issues or have suggestions for improvements, please open an issue in the repository.
Your contribution is welcome! For more details on how to contribute, refer to our Contribution Guide.
Apache 2.0