Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

905
Views
Cómo utilizar la variable account_id de AWS en Terraform

Quiero acceder a mi ID de cuenta de AWS en terraform. Puedo acceder a él con aws_caller_identity según la documentación . ¿Cómo uso entonces la variable que creé? En el siguiente caso, estoy tratando de usarlo en un nombre de depósito S3:

 data "aws_caller_identity" "current" {} output "account_id" { value = data.aws_caller_identity.current.account_id } resource "aws_s3_bucket" "test-bucket" { bucket = "test-bucket-${account_id}" }

Intentar usar la variable account_id de esta manera me da el error A reference to a resource type must be followed by at least one attribute access, specifying the resource name. Supongo que no lo estoy llamando correctamente.

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

Cada vez que cree una fuente de datos en terraform, exportará algunos atributos relacionados con esa fuente de datos para que pueda hacer referencia a ella en otro lugar de su configuración e interpolarla de varias maneras.

En su caso, ya está haciendo referencia al valor de su ID de cuenta en el bloque de output

De la misma manera, puede construir la cadena para el nombre del depósito de la siguiente manera.

 resource "aws_s3_bucket" "test-bucket" { bucket = "test-bucket-${data.aws_caller_identity.current.account_id}" }

Recomiendo encarecidamente que revise la sintaxis de terrraform que puede ayudarlo a comprender mejor el recurso, la fuente de datos y las expresiones.

https://www.terraform.io/docs/language/expresiones/referencias.html

over 4 years ago · Santiago Trujillo Report

0

Si tienes un

 data "aws_caller_identity" "current" {}

entonces necesitas definir un local para ese valor:

 locals { account_id = data.aws_caller_identity.current.account_id }

y luego usarlo como

 output "account_id" { value = local.account_id } resource "aws_s3_bucket" "test-bucket" { bucket = "test-bucket-${local.account_id}" }

Terraform resuelve los locals en función de sus dependencias para que pueda crear locals que dependan de otros locals , resources , bloques de data , etc.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!