Provider
Last updated
Was this helpful?
Last updated
Was this helpful?
What would you say if you could manage Spacelift resources - that is , , , and - using Spacelift? We hate ClickOps as much as anyone, so we designed everything from the ground up to be easily managed using a Terraform provider. We hope that advanced users will define most of their resources programmatically.
Our Terraform provider is open source and its always contains the latest available documentation. It's also distributed as part of our and available through our . The purpose of this article isn't as much to document the provider itself but to show how it can be used to incorporate Spacelift resources into your infra-as-code.
So, without further ado, let's define a stack:
That's awesome. But can we put Terraform to good use and integrate it with resources from a completely different provider? Sure we can, and we have a good excuse, too. Stacks accessibility can be managed , so why don't we define some?
In order to set up the provider to use an API key, you will need the key ID, secret, and the API key endpoint:
These values can also be passed using environment variables, though this will only work to set up the provider for a single Spacelift account:
SPACELIFT_API_KEY_ENDPOINT
for api_key_endpoint
;
SPACELIFT_API_KEY_ID
for api_key_id
;
SPACELIFT_API_KEY_SECRET
for api_key_secret
;
If you're running from inside Spacelift, you can still use the default, zero-setup provider for the current account with providers for accounts set up through API keys:
We suggest to first manually create a single administrative stack, and then use it to programmatically define other stacks as necessary. If you're using an integration like AWS, you should probably give the role associated with this stack full IAM access too, allowing it to create separate roles and policies for individual stacks.
In general, we believe that things like runs or tasks do not fit the (relatively static) Terraform resource lifecycle model and that hiding those parts of the API from Terraform helps us ensure the integrity of potentially sensitive data - just see the example above.
Now that we programmatically combine Spacelift and GitHub resources, let's add AWS to the mix and give our new stack a dedicated :
OK, so who wants to go back to clicking on things in the web GUI? Because you will likely need to do some clicking, too, .
Depending on whether you're using Terraform 0.12.x or higher, the Spacelift provider is distributed slightly differently. For 0.12.x users, the provider is distributed as a binary available in the in the same folder we put the Terraform binary. If you're using Terraform 0.13 and above, you can benefit from pulling our provider directly from our own provider registry. In order to do that, just point Terraform to the right location:
Within Spacelift, the provider is configured by an environment variable SPACELIFT_API_TOKEN
injected into each run and task belonging to marked as . This value is a bearer token that contains all the details necessary for the provider to work, including the full address of the to talk to. It's technically valid for 3 hours but only when the responsible for generating it is in , or (for ) state and throughout that time it provides full administrative access to Spacelift entities within the same Spacelift account.
If you want to run the Spacelift provider outside of Spacelift, or you need to manage resources across multiple Spacelift accounts from the same Terraform project, the preferred method is to generate and use dedicated . Note that unless you're just accessing whitelisted data resources, the Terraform use case will normally require marking the API key as administrative.
If you want to talk to multiple Spacelift accounts, you just need to set up like this:
If you want to share data between stacks, please consider programmatically creating and attaching .
Spacelift administrative tokens are not like user tokens. Specifically, they allow access to a much smaller subset of the . They allow managing the lifecycles of , , , and , but they won't allow you to create or even access , or , or their associated logs.
Administrative tokens have no superpowers either. They can't read write-only configuration elements any more than you can as a user. Unlike human users with user tokens, administrative tokens won't allow you to run env
in a and read back the logs.