AWS 'Bucket already exists' - how to "migrate" existing resources to CloudFormation?

Viewed 8602

We have already created some infrastructure manually and with terraform, including some s3 buckets. In the future I would like to use pure CloudFormation to define the infrastructure as code.

So I created a CloudFormation yaml definition which references an existing bucket:

AWSTemplateFormatVersion: '2010-09-09'
Resources:
  TheBucket:
    Type: AWS::S3::Bucket
    Properties:
      BucketName: my-existing-bucket-name

When I try to apply it, execution fails, with CloudFormation stack event:

The following resource(s) failed to update: [TheBucket].
12:33:47 UTC+0200   UPDATE_FAILED   AWS::S3::Bucket TheBucket
  my-existing-bucket-name already exists

How can I start managing existing resources with CloudFormation without recreating them? Or is it impossible by design?

3 Answers
Related