-
Notifications
You must be signed in to change notification settings - Fork 5
/
eb_app.tf
60 lines (52 loc) · 2.42 KB
/
eb_app.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
terraform {
required_providers {
aws = {
source = "hashicorp/aws" # required
version = "~> 3.27" # required
}
}
backend "s3" {
bucket = "enes-mybucket" # S3 bucket name
key = "path/to/my/key" # S3 key name
region = "us-east-2" # S3 region
}
}
# AWS Provider configuration
provider "aws" {
profile = "default" # AWS profile
region = "us-east-2" # AWS region
}
# Create S3 bucket for Python Flask app
resource "aws_s3_bucket" "eb_bucket" {
bucket = "enes-eb-python-flask" # Name of S3 bucket to create for Flask app deployment needs to be unique
}
# Define App files to be uploaded to S3
resource "aws_s3_bucket_object" "eb_bucket_obj" {
bucket = aws_s3_bucket.eb_bucket.id
key = "beanstalk/app.zip" # S3 Bucket path to upload app files
source = "app.zip" # Name of the file on GitHub repo to upload to S3
}
# Define Elastic Beanstalk application
resource "aws_elastic_beanstalk_application" "eb_app" {
name = "enes-eb-tf-app" # Name of the Elastic Beanstalk application
description = "simple flask app" # Description of the Elastic Beanstalk application
}
# Create Elastic Beanstalk environment for application with defining environment settings
resource "aws_elastic_beanstalk_application_version" "eb_app_ver" {
bucket = aws_s3_bucket.eb_bucket.id # S3 bucket name
key = aws_s3_bucket_object.eb_bucket_obj.id # S3 key path
application = aws_elastic_beanstalk_application.eb_app.name # Elastic Beanstalk application name
name = "enes-eb-tf-app-version-lable" # Version label for Elastic Beanstalk application
}
resource "aws_elastic_beanstalk_environment" "tfenv" {
name = "enes-eb-tf-env"
application = aws_elastic_beanstalk_application.eb_app.name # Elastic Beanstalk application name
solution_stack_name = "64bit Amazon Linux 2 v3.3.11 running Python 3.8" # Define current version of the platform
description = "environment for flask app" # Define environment description
version_label = aws_elastic_beanstalk_application_version.eb_app_ver.name # Define version label
setting {
namespace = "aws:autoscaling:launchconfiguration" # Define namespace
name = "IamInstanceProfile" # Define name
value = "aws-elasticbeanstalk-ec2-role" # Define value
}
}