CFT Template error: unresolved condition dependency UseDBSnapshot in Fn::If

Viewed 372

Trying to create a CFT for RDS which can handle both the scenarios creating a new RDS Aurora MySQL cluster and create a RDS cluster with a existing DB Cluster Snapshot

Here is what I tried,

I have provide the below conditions section of the template

"UseDbSnapshot" : {
              "Fn::Not" : [
                  {
                      "Fn::Equals":[
                            {"Ref": "DBSnapshotName"},
                            ""
                        ]
                    }
                ]
            }

and referenced in Resource section as below

"RDSCluster1": {
        "Type": "AWS::RDS::DBCluster",
        "Condition": "isResourceCreate",
        "Properties": {
            "Engine": "aurora",
            "DBSubnetGroupName": {
                "Ref": "DBSubnetGroup"
            },
            "DBClusterParameterGroupName": {
                "Ref": "RDSDBClusterParameterGroup"
            },
            "DBSnapshotIdentifier" : {
                "Fn::If" : [
                  "UseDBSnapshot",
                  {"Ref" : "DBSnapshotName"},
                  {"Ref" : "AWS::NoValue"}
                ]
              },
            "MasterUsername": {
                "Ref": "DbUser"
            },
            "MasterUserPassword": {
                "Ref": "MasterUserPassword"
            },
            "StorageEncrypted" : true,
            "KmsKeyId" : {
                "Ref": "KmsKeyId"
            },
            "VpcSecurityGroupIds": [
                {
                    "Fn::GetAtt": [
                        "DBAccessSecurityGroup",
                        "GroupId"
                    ]
                }
            ],
            "Port": "3306",
            "BackupRetentionPeriod": "1"
        },
        "DeletionPolicy": "Snapshot"
    }

The condition "isResourceCreate" is satisfied but I am getting below error

Template error: unresolved condition dependency UseDBSnapshot in Fn::If

Could you please help me here.

Have looked up online link https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/conditions-sample-templates.html and created this CFT.

Let me know if you require any more details.

1 Answers

If you are restoring DB from snapshot, you can't provide MasterUsername and MasterUserPassword. These values will be inherited from the snapshot, so you have to make them optional.

If you specify the SourceDBInstanceIdentifier or DBSnapshotIdentifier property, don't specify this property. The value is inherited from the source DB instance or snapshot.

Related