-
Notifications
You must be signed in to change notification settings - Fork 43
/
main.tf
134 lines (113 loc) · 3.73 KB
/
main.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
locals{
domain = "${var.namespace}-${var.environment}-${substr(uuid(),0 , 8)}"
domain_url = "http://${local.domain}.eu-west-1.elasticbeanstalk.com"
}
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 3.27"
}
}
required_version = ">= 0.14.9"
}
provider "aws" {
profile = var.aws_profile
region = var.aws_region
}
// Compressing our FAT Jar into a Zip file
data "archive_file" "api_dist_zip" {
type = "zip"
source_file = "${path.root}/${var.api_dist}.jar"
output_path = "${path.root}/${var.api_dist}.zip"
}
//Creating an AWS S3 Bucket
resource "aws_s3_bucket" "dist_bucket" {
bucket = "${var.namespace}-elb-dist"
acl = "private"
}
// Pushing our ZIP file on the S3 bucket
resource "aws_s3_bucket_object" "dist_item" {
key = "${var.environment}/dist-${uuid()}"
bucket = aws_s3_bucket.dist_bucket.id
source = "${path.root}/${var.api_dist}.zip"
}
// Creating a new Beanstalk application
resource "aws_elastic_beanstalk_application" "adyen_test_application" {
name = "adyen-test-application"
description = "An Adyen test checkout application running on AWS"
}
// Creating a new version for our application, with our ZIP file and a version number
resource "aws_elastic_beanstalk_application_version" "adyen_test_application_version" {
application = aws_elastic_beanstalk_application.adyen_test_application.name
bucket = aws_s3_bucket.dist_bucket.id
key = aws_s3_bucket_object.dist_item.id
name = "${var.namespace}-1.0.0"
}
// Creating a new Beanstalk environment with our application and version
resource "aws_elastic_beanstalk_environment" "adyen_test_application_environment" {
name = "adyen-test-application-environment"
application = aws_elastic_beanstalk_application.adyen_test_application.name
solution_stack_name = "64bit Amazon Linux 2 v3.2.8 running Corretto 11"
version_label = aws_elastic_beanstalk_application_version.adyen_test_application_version.name
cname_prefix = local.domain
setting {
namespace = "aws:ec2:instances"
name = "InstanceTypes"
value = "t2.micro"
}
// Default Beanstalk role
setting {
namespace = "aws:autoscaling:launchconfiguration"
name = "IamInstanceProfile"
value = "aws-elasticbeanstalk-ec2-role"
}
// Sends logs to Cloudwatch
setting {
namespace = "aws:elasticbeanstalk:cloudwatch:logs"
name = "StreamLogs"
value = "true"
}
setting {
name = "PORT"
namespace = "aws:elasticbeanstalk:application:environment"
value = "8080"
}
setting {
name = "ADYEN_CLIENT_KEY"
namespace = "aws:elasticbeanstalk:application:environment"
value = var.adyen_client_key
}
setting {
name = "ADYEN_API_KEY"
namespace = "aws:elasticbeanstalk:application:environment"
value = var.adyen_api_key
}
setting {
name = "ADYEN_HMAC_KEY"
namespace = "aws:elasticbeanstalk:application:environment"
value = var.adyen_hmac_key
}
setting {
name = "ADYEN_MERCHANT_ACCOUNT"
namespace = "aws:elasticbeanstalk:application:environment"
value = var.adyen_merchant_account
}
setting {
name = "ADYEN_RETURN_URL"
namespace = "aws:elasticbeanstalk:application:environment"
value = local.domain_url
}
}
output "demo_url" {
value = local.domain_url
description = "The URL of the demo that is being hosted"
}
output "environment_url" {
value = "https://${var.aws_region}.console.aws.amazon.com/elasticbeanstalk/home?region=${var.aws_region}#/applications"
description = "The URL to access the Beanstalk environments"
}
output "adyen_url" {
value = "https://ca-test.adyen.com/ca/ca/config/showthirdparty.shtml"
description = "The URL to access the Webhooks part of the Adyen Customer Area"
}