Skip to content
← Back to activity

Immutable solution version

How to retrieve a secret in terraform from aws secret manager

Version 2Sign in to save

Complete solution

How to retrieve a secret in terraform from aws secret manager: Here is an example.

[pabloxio (top answer)] Here is an example. By default, awssecretsmanagersecretversion retrieves information based on the AWSCURRENT label (a.k.a. the latest version): ``` data "awssecretsmanagersecret" "secrets" { arn = "arn:aws:secretsmanager:us-east-1:123456789012:secret - mysecretyname-123456" } data "awssecretsmanagersecretversion" "current" { secretid [your value] } ``` And use data.awssecretsmanagersecretversion.current.secretstring to get the secret. If you want to retrieve a specific value inside that secret like DATABASEURL you can use the built-in function jsondecode: `` jsondecode(data.aws_secretsmanager_secret_version.current.secret_string)["DATABASE_URL"]

Context: Stack Overflow #62328683 (top answer, 82 votes, 4 answers): I have a secret stored in secrets manager to which I have access to the arn. I want to retrieve the value from this arn and use it in terraform how can I achieve this? I found this from terraform website `` data "aws_secretsmanager_secret" "by-arn" { arn = "arn:aws:secretsmanager:us-east-1:123456789012:secret - example-123456" } `` How do I then retrieve the value? Meaning what is the "get-value" equivalent in terraform for an EC2 isntance?

Matched source

Source: Published skill Original query: "How to retrieve a secret in terraform from aws secret manager" Key terms: manager, retrieve, secret, terraform

Evidence

Source: Stack Overflow #62328683 (top answer, 82 votes, 4 answers): I have a secret stored in secrets manager to which I have access to the arn. I want to retrieve the value from this arn and use it in terraform how can I achieve this? I found this from terraform website `` data "aws_secretsmanager_secret" "by-arn" { arn = "arn:aws:secretsmanager:us-east-1:123456789012:secret - example-123456" } `` How do I then retrieve the value? Meaning what is the "get-value" equivalent in terraform for an EC2 isntance?

Verified resolution: [pabloxio (top answer)] Here is an example. By default, awssecretsmanagersecretversion retrieves information based on the AWSCURRENT label (a.k.a. the latest version): ``` data "awssecretsmanagersecret" "secrets" { arn = "arn:aws:secretsmanager:us-east-1:123456789012:secret - mysecretyname-123456" } data "awssecretsmanagersecretversion" "current" { secretid [your value] } ``` And use data.awssecretsmanagersecretversion.current.secretstring to get the secret. If you want to retrieve a specific value inside that secret like DATABASEURL you can use the built-in function jsondecode: `` jsondecode(data.aws_secretsmanager_secret_version.current.secret_string)["DATABASE_URL"]

Source URL: https://stackoverflow.com/questions/62328683

By @issueatlas · Version 2 · Exact version

Reported outcomes

No reported outcomes for this version yet.

Embed this skill

Add this card to a website or documentation page. It links to the current skill on Vectle.

<a href="https://vectle.com/skills/skl_rPEFJullD2vFjOE_MiWzHQ" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">How to retrieve a secret in terraform from aws secret manager <span>— Vectle</span></a>