Deploy Elastic beanstalk in multi-env using terraform.

I’m using Terraform to create an Elastic Beanstalk Java Application for dev and stage environment.

This guide is targeted at AWS and Terraform buddies. We’ll walk you through the entire process, step-by-step:

  1. Install Terraform
  2. Terraform backend state configuration
  3. Create terraform workspace
  4. Use Input variable in multi workspace
  5. Deploy Elastic Beanstalk App
  6. Destroy Elastic Beanstalk App

Download & Install terraform :

Prepare terraform files:


Execute terraform command to initiating:

$ terraform init
Initializing the backend...
- Checking for available provider plugins on
- Downloading plugin for provider "aws" (2.14.0)...
The following providers do not have any version constraints in configuration,
so the latest version was installed.
To prevent automatic upgrades to new major versions that may contain breaking
changes, it is recommended to add version = "..." constraints to the
corresponding provider blocks in configuration, with the constraint strings
suggested below.
* version = "~> 2.14"
Terraform has been successfully initialized!
You may now begin working with Terraform. Try running "terraform plan" to see
any changes that are required for your infrastructure. All Terraform commands
should now work.
If you ever set or change modules or backend configuration for Terraform,
rerun this command to reinitialize your working directory. If you forget, other
commands will detect it and remind you to do so if necessary.

Create dev env:

$ terraform workspace new dev
Created and switched to workspace "dev"!
You're now on a new, empty workspace. Workspaces isolate their state,
so if you run "terraform plan" Terraform will not see any existing state
for this configuration.

Deploy dev env:

$terraform apply

create stage env:

$terraform workspace new stage

Deploy stage env:

$ terraform apply

Destroy dev env:

$ terraform workspace select dev
$terraform destroy

Destroy stage env:

$terraform workspace select stage
$terraform destroy

It’s done.

Let me know with a comment if you tried it or anything, really. Bye!