Home > OS >  Reference Secrets Manager Parameters to Secret String
Reference Secrets Manager Parameters to Secret String

Time:10-10

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"}'

CodePudding user response:

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}"}'
  • Related