How can I refer to an output in the remote state? #1353
-
I'm using version 2.50.0 of the DigitalOcean Terraform Provider. I also finally got remote states working. However, the challenging thing now is to refer to an output within a remote state file. For example, I got: resource "digitalocean_project" "staging" {
name = "POC"
description = "Proof-of-Concept project for DigitalOcean and Terraform"
environment = var.environment
resources = [data.terraform_remote_state.s3.outputs.terraform_state_storage_bucket]
} To use that, I will have to refer to 'create' a data source so I can refer to it. I'm used to AWS, so I tried: data "terraform_remote_state" "s3" {
backend = "s3"
config = {
bucket = "techlab-staging-terraform-state-storage-staging"
region = var.region
key = "s3.tfstate"
}
} Variables: variable "region" {
type = string
}
variable "environment" {
type = string
}
variable "company" {
type = string
}
variable "DIGITALOCEAN_TOKEN" {
type = string
sensitive = true
}
variable "AWS_ACCESS_KEY_ID" {
type = string
sensitive = true
}
variable "AWS_SECRET_ACCESS_KEY" {
type = string
sensitive = true
} region = "ams3"
environment = "staging"
company = "REDACTED" However, when executing a
So it expects an AWS region, while I'm obviously using DigitalOcean's provider. I found out that this is the way for AWS, so I looked for a DO kind of way here: https://developer.hashicorp.com/terraform/language/state/remote-state-data. There's nothing related to it. How would I then refer to an output in another stack (see the resource |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 5 replies
-
Hi! Thanks for the write up. I'm able to reproduce this as well. Still investigating... |
Beta Was this translation helpful? Give feedback.
-
Can you see if this works for you...
|
Beta Was this translation helpful? Give feedback.
Remote state management is a feature of Terraform itself. It is not implemented by individual providers. The
terraform_remote_state
data source is a built-in provider provided byterraform.io/builtin/terraform
. Unfortunately this can sometime make it difficult to use with S3 alternatives as they can use AWS-specific functionality by default.The S3 remote state offers options to disable those for compatibility with S3 alternatives like DigitalOcean Spaces. You can find documentation on those here:
https://docs.digitalocean.com/products/spaces/reference/terraform-backend/
The
config
fo…