title: Ansible Cloudformation, how to not break if Resource already exists?
body: <p>I have the following AWS Cloudformation config, which sets up S3, Repositories.</p>
  
  <p>When I run it via an ansible playbook, on the second time running the playbook this happens</p>
  
  <pre><code>AWS::ECR::Repository Repository CREATE_FAILED: production-app-name already exists
  etc
  </code></pre>
  
  <p>How can I make it so that when this is ran multiple times, it will keep the existing s3 and repository instead of just blowing up? (I had assumed the param <code>"DeletionPolicy": "Retain",</code> would do this)</p>
  
  <p>What I'd like to achieve:</p>
  
  <p>If i run this 100x, I want the same resource state as it was after run #1. I do not want any resources deleted/wiped of any data.</p>
  
  <pre><code>{
  
  
   "AWSTemplateFormatVersion": "2010-09-09",
    "Description": "Pre-reqs for Elastic Beanstalk application",
    "Parameters": {
      "BucketName": {
        "Type": "String",
        "Description": "S3 Bucket name"
      },
      "RepositoryName": {
        "Type": "String",
        "Description": "ECR Repository name"
      }
    },
    "Resources": {
      "Bucket": {
        "Type": "AWS::S3::Bucket",
        "DeletionPolicy": "Retain",
        "Properties": {
          "BucketName": { "Fn::Join": [ "-", [
            { "Ref": "BucketName" },
            { "Ref": "AWS::Region" }
          ]]}
        }
      },
      "Repository": {
        "Type": "AWS::ECR::Repository",
        "DeletionPolicy": "Retain",
        "Properties": {
          "RepositoryName": { "Ref": "RepositoryName" }
        }
      }
    },
    "Outputs": {
      "S3Bucket": {
        "Description": "Full S3 Bucket name",
        "Value": { "Ref": "Bucket" }
      },
      "Repository": {
        "Description": "ECR Repo",
        "Value": { "Fn::Join": [ "/", [
          {
            "Fn::Join": [ ".", [
              { "Ref": "AWS::AccountId" },
              "dkr",
              "ecr",
              { "Ref": "AWS::Region" },
              "amazonaws.com"
            ]]
          },
          { "Ref": "Repository" }
        ]]}
      }
    }
  }
  </code></pre>
  
  <p>edit: </p>
  
  <p>DB with similar issue when ran twice</p>
  
  <pre><code>{
      "AWSTemplateFormatVersion": "2010-09-09",
      "Parameters": {
          "DBPassword": {
              "MinLength": "8",
              "NoEcho": true,
              "Type": "String"
          },
          "Environment": {
              "MinLength": "1",
              "Type": "String"
          },
          "DBName": {
              "Type": "String",
              "Description": "DBName"
          },
          "DBInstanceIdentifier": {
              "Type": "String",
              "Description": "DBInstanceIdentifier"
          },
          "DBPort": {
              "Type": "String",
              "Description": "DBPort"
          },
          "DBUsername": {
              "Type": "String",
              "Description": "DBName"
          }
      },
      "Outputs": {
          "Url": {
              "Value": {
                  "Fn::Sub": "postgres://${DBUsername}:${DBPassword}@${Instance.Endpoint.Address}:${Instance.Endpoint.Port}/${DBName}"
              }
          }
      },
      "Resources": {
          "Instance": {
              "Type": "AWS::RDS::DBInstance",
              "DeletionPolicy": "Retain",
              "Properties": {
                  "AllocatedStorage": "10",
                  "DBInstanceClass": "db.t2.micro",
                  "DBInstanceIdentifier": {"Ref": "DBInstanceIdentifier"},
                  "DBName": {
                      "Ref": "DBName"
                  },
                  "Engine": "postgres",
                  "EngineVersion": "9.6.6",
                  "MasterUsername": {
                      "Ref": "DBUsername"
                  },
                  "MasterUserPassword": {
                      "Ref": "DBPassword"
                  },
                  "MultiAZ": "false",
                  "Port": {
                      "Ref": "DBPort"
                  },
                  "PubliclyAccessible": "false",
                  "StorageType": "gp2"
              }
          }
      }
  }
  </code></pre>