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:
- Install Terraform
- Terraform backend state configuration
- Create terraform workspace
- Use Input variable in multi workspace
- Deploy Elastic Beanstalk App
- Destroy Elastic Beanstalk App
Download & Install terraform : https://www.terraform.io/downloads.html
Prepare terraform files:
Execute terraform command to initiating:
$ terraform init
Initializing the backend...
- Checking for available provider plugins on https://releases.hashicorp.com...
- 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
* provider.aws: 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:
create stage env:
$terraform workspace new stage
Deploy stage env:
$ terraform apply
Destroy dev env:
$ terraform workspace select dev
Destroy stage env:
$terraform workspace select stage
Let me know with a comment if you tried it or anything, really. Bye!