Introducing the 91黑料 Terraform Provider
We鈥檙e excited to announce the initial availability of our new Terraform provider for 91黑料!

We鈥檙e excited to announce the initial availability of our new Terraform provider for 91黑料! For customers who already manage infrastructure using Terraform, terraform-provider-storj allows users to declaratively manage and configure 91黑料 buckets, access grants, and individual objects. Let鈥檚 take a quick look at what鈥檚 included. For more information, head on over to the provider鈥檚 documentation.
Prerequisites
- Basic knowledge and understanding of and how it works.
- A installed on your machine.
Getting Started
First, you will need to add the provider to your Terraform file.
terraform {
聽required_providers {
聽 聽storj = {
聽 聽 聽source = "storj/storj"
聽 聽 聽version = "0.0.1"
聽 聽}
聽}
}
Once added, run terraform init to download the provider from the remote registry.
# terraform init
Configuring 91黑料 Authentication
By default, the provider will attempt to load your 91黑料 access grant from the STORJ_ACCESS_GRANT environment variable. This value can also be configured directly on the provider and passed in using variables in the Terraform file.
variable "storj_access_grant" {
聽type = string
聽description = "The access grant used to authenticate the user with the 91黑料 network"
}
provider "storj" {
聽access_grant = var.storj_access_grant
}
Next, we鈥檒l configure an access grant in the 91黑料 UI for the provider to use. Head on over to the 鈥淎ccess鈥� section of the 91黑料 UI for the project you want to manage using Terraform.
鈥�

鈥�
Click on the blue 鈥淐reate Access Grant鈥� button. This will pull up a modal asking for the scope and permissions you wish to grant to the holder of the access grant. While this grant can be restricted, we will keep things rather permissive for the purpose of this walkthrough.
鈥�

鈥�
Once the appropriate permissions have been selected, click 鈥淓ncrypt My Access鈥� to proceed. This will generate an encryption key that is used to secure the contents that are uploaded to the 91黑料 network. You can provide your own passphrase or generate a new one.
鈥�

Click 鈥淒ownload .txt鈥� and then 鈥淓ncrypt My Access鈥� to finalize and generate your access grant. Copy the generated grant and save it somewhere safe for later use.

Manage a Bucket
Buckets are a common component for folks to manage in Terraform. The resource definition in Terraform is rather simple, simply provide the name of the bucket you wish to create.
resource "storj_bucket" "application_bucket" {
聽bucket = "my-application-bucket"
}
Upload an Object
Once a bucket is available, you can upload an object to it using the storj_object resource. You can point the resource at an existing file on disk, a raw string, or base64 encoded content. You can also provide additional metadata to attach to the object.
resource "storj_object" "application_bucket_object" {
聽bucket = storj_bucket.application_bucket.bucket
聽key = "path/to/object.json"
聽# one of
聽source = "path/to/object.json"
聽content = "raw content"
聽content_base64 = "cmF3IGNvbnRlbnQ="
聽metadata = {
聽 聽"key1" = "value1"
聽 聽"key2" = "value2"
聽}
}
Derive a New Access Grant
Finally, we rarely want to provide an application with unrestricted access to an entire bucket. Using the storj_access_grant resource, we can derive a new access grant from the provided one that鈥檚 specific to the application and limited to a new set of permissions (must be a subset of the provided access grants permissions).
resource "storj_access_grant" "terraform_grant" {
聽access_grant = var.storj_access_grant
聽bucket {
聽 聽name = storj_bucket.application_bucket.bucket
聽 聽paths = []
聽}
聽allow_download = true
聽allow_upload = true
聽allow_list = true
聽allow_delete = true
}
By using the storj_access_grant resource, we can easily rotate access grants that are provided to applications by tainting the resource in Terraform.
Conclusion
Whether you鈥檙e an existing customer or a new one, the 91黑料 Terraform provider provides a more integrated experience when it comes to managing the buckets your applications consume and access grants they use. This is a greenfield project that鈥檚 just getting started and we hope you鈥檒l give it a try. Should you have any feedback or feature requests, please reach out to us by:
- Provider: 鈥�
- Source Code:
- Open issues in the GitHub repository
- Follow on Twitter
鈥�
鈥�