Scale up as you grow — whether you're running one virtual machine or ten thousand.

From GPU-powered inference and Kubernetes to managed databases and storage, get everything you need to build, scale, and deploy intelligent applications.

Hello,
We created our first project on DO called “A”. Now, we want to create another project called “Dev”, where we wish to deploy our development environment with a few resources (droplets, load balancer, k8s, etc.) using Terraform.
I already read all the articles on https://www.digitalocean.com/community/tutorial_series/how-to-manage-infrastructure-with-terraform and none specify how to resolve my problem.
The problem is that every time I terraform apply the resource ends up in project “A” (it is not only with the DO Spaces).
I want to use TF to provision a droplet test and publish our terraform.tfstate using a DO Spaces as the backend.
Firstly, I created (using the GUI) the DO Spaces called tf-state under “Dev” then executed TF commands. I discovered that is necessary to create the DO Spaces beforehand terraform init, otherwise it won’t work.
So, I proceed to execute my TF folder, like so:
# Provider
terraform {
required_providers {
digitalocean = {
source = "digitalocean/digitalocean"
version = "2.7.0"
}
}
required_version = ">=0.14.9"
}
provider "digitalocean" {
token = var.do_token
spaces_access_id = var.access_id
spaces_secret_key = var.secret_key
}
# Project
resource "digitalocean_project" "dev" {
name = "dev"
description = "Development details..."
purpose = "Service or API"
environment = "Development"
resources = [
digitalocean_droplet.test.urn,
digitalocean_spaces_bucket.tf-state.urn
]
}
# Backend
terraform {
backend "s3" {
endpoint = "fra1.digitaloceanspaces.com/"
region = "us-west-1"
key = "terraform.tfstate"
bucket = "tf-state"
skip_credentials_validation = true
skip_metadata_api_check = true
}
}
# Bucket
resource "digitalocean_spaces_bucket" "tf-state" {
name = "tf-state"
region = var.region
}
# Droplet
resource "digitalocean_droplet" "test" {
name = "test"
size = "s-1vcpu-1gb"
image = var.image
region = var.region
}
Everything goes well when running:
terraform init \
-backend-config="access_key=$SPACES_ACCESS_KEY_ID" \
-backend-config="secret_key=$SPACES_SECRET_ACCESS_KEY"
But, when running terraform apply I get a message:
Error: Error creating Spaces bucket: BucketAlreadyExists: Bucket already exists
status code: 409, request id: , host id:
A solution is to comment # Bucket and the called line in the resource:
# Project
resource "digitalocean_project" "dev" {
name = "dev"
description = "Development details..."
purpose = "Service or API"
environment = "Development"
resources = [
digitalocean_droplet.test.urn,
# digitalocean_spaces_bucket.tf-state.urn <= commented line
]
}
# Commented block
# # Bucket
# resource "digitalocean_spaces_bucket" "tf-state" {
# name = "tf-state"
# region = var.region
# }
By doing this, all works, but the DO Spaces tf-state is transfered to the project “A”.
It is quite cumbersome to track all the resources in "digitalocean_project" "dev" that are related to “Dev”. Is it possible to instruct TF to apply by default the provisioning to a specific project, like “Dev” (i.e. create another token for the new project)?
How to create a DO Spaces bound to a specific project?
Any help is greatly appreciated.
Thanks,
SarkariResultht
KFSys
Arne van Hoorn
alexdo
4287c71658bd4ea39bef277d491b1c
4287c71658bd4ea39bef277d491b1c
Demanix
Demanix
devjk1
Jordan
LC Labs Sp. z o.o.
a0cd9be01b14447384f79073fc121f