Skip to content

Commit

Permalink
Import into terraform state
Browse files Browse the repository at this point in the history
  • Loading branch information
ulich committed Feb 13, 2018
1 parent 10ba726 commit b8bab6b
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
44 changes: 44 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,47 @@ but it could also be done resource by resource.
```
aws cloudformation update-stack --stack-name migrationtest --template-body file://cloudformation-template.json
```


## 3.

Now we create a small terraform project that just defines the resources we want to migrate without any configuration:

```
git checkout step-3
```

We initialize the terraform project:

```
terraform init
```

and we can import the existing resouces into terraform's state. This is done with the command
```
terraform import <type>.<resource name> <aws id>
```

If the resource is defined in a module, it would be
```
terraform import module.<module name>.<resource name> <aws id>
```

The format of the aws ID is always specific to the resource type. For ElasticBeanstalk,
the application's ID is its name, the environment is an auto-generated ID which can be
identified via the aws cli for example.

```
aws elasticbeanstalk describe-environments
```

Identify the environment you want to migrate and note the `EnvironmentId`.

In our example it would be:

```
terraform import aws_elastic_beanstalk_application.my_ebs coffee-service
terraform import aws_elastic_beanstalk_environment.my_ebs_staging e-pcpeep3b3z
```

Terraform now imported the resources into it's state.
9 changes: 9 additions & 0 deletions terraform.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
provider "aws" {
region = "eu-west-1"
}

resource "aws_elastic_beanstalk_application" "my_ebs" {
}

resource "aws_elastic_beanstalk_environment" "my_ebs_staging" {
}

0 comments on commit b8bab6b

Please sign in to comment.