From b8bab6b05c05685ba4a676955e75201278e27be6 Mon Sep 17 00:00:00 2001 From: "Ulich, Timo" Date: Tue, 13 Feb 2018 21:17:29 +0100 Subject: [PATCH] Import into terraform state --- README.md | 44 ++++++++++++++++++++++++++++++++++++++++++++ terraform.tf | 9 +++++++++ 2 files changed, 53 insertions(+) create mode 100644 terraform.tf diff --git a/README.md b/README.md index 23c7701..6d095ba 100644 --- a/README.md +++ b/README.md @@ -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 . +``` + +If the resource is defined in a module, it would be +``` +terraform import module.. +``` + +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. diff --git a/terraform.tf b/terraform.tf new file mode 100644 index 0000000..d0f0d24 --- /dev/null +++ b/terraform.tf @@ -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" { +}