Daniel Fulgido
Daniel Fulgido

Reputation: 137

Reference Secrets Manager Parameters to Secret String

Is there any way to reference parameters in SecretString field in Secrets Manager via CloudFormation?

The way I made the script, the !Ref parameter is a text and not a reference to the parameter.

AWSTemplateFormatVersion: 2010-09-09

Parameters:

  Name:
    Type: String
  myuserparameter:
    Type: String
  mypasswordparameter:
    Type: String

Resources:  
  
  SecretsManager:
    Type: AWS::SecretsManager::Secret
    Properties:
      Name: !Ref Name
      SecretString: '{"username":"!Ref myuserparameter,"password":"Ref mypasswordparameter"}'

Upvotes: 3

Views: 1753

Answers (1)

Derek Menénedez
Derek Menénedez

Reputation: 2377

this will work:

AWSTemplateFormatVersion: 2010-09-09

Parameters:

  Name:
    Type: String
  myuserparameter:
    Type: String
  mypasswordparameter:
    Type: String

Resources:  
  
  SecretsManager:
    Type: AWS::SecretsManager::Secret
    Properties:
      Name: !Ref Name
      SecretString: !Sub '{"username": "${myuserparameter}","password": "${mypasswordparameter}"}'

Upvotes: 3

Related Questions