Terraform Provider Quickstart
Learn how to use the Rabata Terraform provider to manage your Rabata.io object storage resources using Infrastructure as Code.
Installation
If you don’t have Terraform installed, follow the official installation guide for your operating system.
Configure Terraform to Use the Rabata Provider
Create a new directory for your Terraform configuration and create a file named main.tf with the following content:
terraform {
required_providers {
rabata = {
source = "rabataio/rabata"
version = "~> 1.0" # Use the latest version available
}
}
}
provider "rabata" {
region = "eu-west-1" # Replace with your preferred region
access_key = "your-access-key"
secret_key = "your-secret-key"
}
Authentication
The Rabata provider offers multiple ways to provide credentials for authentication:
Method 1: Provider Configuration
You can directly specify your credentials in the provider block as shown above. However, it’s generally not recommended to hardcode credentials in your Terraform files.
Method 2: Environment Variables
You can use environment variables to provide your Rabata credentials:
export RABATA_ACCESS_KEY="your-access-key"
export RABATA_SECRET_KEY="your-secret-key"
export RABATA_REGION="eu-west-1"
Then, your provider configuration can be simplified:
provider "rabata" {}
Method 3: Shared Credentials File
You can also use a shared credentials file, similar to AWS CLI:
provider "rabata" {
shared_credentials_file = "~/.aws/credentials"
profile = "rabata"
}
Creating Your First Resources
Create a Bucket
To create a bucket in Rabata.io, add the following to your main.tf file:
resource "rabata_s3_bucket" "example_bucket" {
bucket = "my-example-bucket"
acl = "private"
}
Upload an Object to the Bucket
To upload an object to your bucket:
resource "rabata_s3_bucket_object" "example_object" {
bucket = rabata_s3_bucket.example_bucket.bucket
key = "example-object.txt"
source = "path/to/local/file.txt"
etag = filemd5("path/to/local/file.txt")
}
Initialize and Apply
After configuring your Terraform files, initialize the working directory:
terraform init
This will download the Rabata provider plugin. Then, apply your configuration:
terraform plan
terraform apply
Review the planned changes and type yes to apply them.
Advanced Configuration
Custom Endpoints
If you need to use a custom endpoint for the S3 service:
provider "rabata" {
region = "eu-west-1"
access_key = "your-access-key"
secret_key = "your-secret-key"
endpoints {
s3 = "https://s3.eu-west-1.rabata.io"
}
}
Path-Style Access
To force path-style addressing (http://s3.rcs.rabata.io/BUCKET/KEY) instead of virtual hosted bucket addressing:
provider "rabata" {
region = "eu-west-1"
access_key = "your-access-key"
secret_key = "your-secret-key"
s3_force_path_style = true
}
Complete Example
Here’s a complete example that creates a bucket, sets up a bucket policy, and uploads an object:
terraform {
required_providers {
rabata = {
source = "rabataio/rabata"
version = "~> 1.0"
}
}
}
provider "rabata" {
region = "eu-west-1"
access_key = "your-access-key"
secret_key = "your-secret-key"
endpoints {
s3 = "https://s3.eu-west-1.rabata.io"
}
}
resource "rabata_s3_bucket" "storage_bucket" {
bucket = "my-storage-bucket"
acl = "private"
tags = {
Environment = "Production"
Project = "Data Storage"
}
}
resource "rabata_s3_bucket_object" "readme" {
bucket = rabata_s3_bucket.storage_bucket.bucket
key = "README.md"
content = "# This is a README file for my bucket"
content_type = "text/markdown"
}
output "bucket_domain_name" {
value = rabata_s3_bucket.storage_bucket.bucket_domain_name
}
Next Steps
Now that you’ve set up your first resources with the Rabata Terraform provider, you can:
- Learn more about Bucket Management
- Understand Access Control for your objects
- Explore the full Rabata Terraform provider documentation
Troubleshooting
Common Issues
Provider Installation Fails
If you encounter issues during terraform init, ensure you have the correct provider source:
terraform {
required_providers {
rabata = {
source = "rabataio/rabata"
}
}
}
Authentication Errors
If you receive authentication errors, verify that:
- Your access key and secret key are correct
- You’ve specified the correct region
- Your credentials have the necessary permissions
S3 Endpoint Issues
If you have connectivity issues, try explicitly setting the S3 endpoint:
provider "rabata" {
endpoints {
s3 = "https://s3.eu-west-1.rabata.io"
}
}
Need Help?
If you need assistance, contact Rabata.io Support.