Skip to content

Commit dfc94ff

Browse files
Dl 718 update terraform aws data lake syntax (#60)
* Update TF modules syntax to v 0.12+
1 parent 3ba5f9f commit dfc94ff

File tree

13 files changed

+82
-82
lines changed

13 files changed

+82
-82
lines changed

README.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Terraform modules which create AWS resources for a Segment Data Lake.
55
# Prerequisites
66

77
* Authorized [AWS account](https://aws.amazon.com/account/).
8-
* Ability to run Terraform with your AWS Account. Terraform 0.11+ (you can download tfswitch to help with switching your terraform version)
8+
* Ability to run Terraform with your AWS Account. Terraform 0.12+ (you can download tfswitch to help with switching your terraform version)
99
* A subnet within a VPC for the EMR cluster to run in.
1010
* An [S3 Bucket](https://github.com/terraform-aws-modules/terraform-aws-s3-bucket) for Segment to load data into. You can create a new one just for this, or re-use an existing one you already have.
1111

@@ -94,22 +94,22 @@ module "iam" {
9494
# names.
9595
suffix = "-prod"
9696
97-
s3_bucket = "${aws_s3_bucket.segment_datalake_s3.id}"
98-
external_ids = "${values(local.external_ids)}"
97+
s3_bucket = aws_s3_bucket.segment_datalake_s3.id
98+
external_ids = values(local.external_ids)
9999
}
100100
101101
# Creates an EMR Cluster that Segment uses for performing the final ETL on your
102102
# data that lands in S3.
103103
module "emr" {
104104
source = "[email protected]:segmentio/terraform-aws-data-lake//modules/emr?ref=v0.6.0"
105105
106-
s3_bucket = "${aws_s3_bucket.segment_datalake_s3.id}"
106+
s3_bucket = aws_s3_bucket.segment_datalake_s3.id
107107
subnet_id = "subnet-XXX" # Replace this with the subnet ID you want the EMR cluster to run in.
108108
109109
# LEAVE THIS AS-IS
110-
iam_emr_autoscaling_role = "${module.iam.iam_emr_autoscaling_role}"
111-
iam_emr_service_role = "${module.iam.iam_emr_service_role}"
112-
iam_emr_instance_profile = "${module.iam.iam_emr_instance_profile}"
110+
iam_emr_autoscaling_role = module.iam.iam_emr_autoscaling_role
111+
iam_emr_service_role = module.iam.iam_emr_service_role
112+
iam_emr_instance_profile = module.iam.iam_emr_instance_profile
113113
}
114114
115115
# Use the code below if you want to add lake-formation setup using terraform.
@@ -122,8 +122,8 @@ module "emr" {
122122
# for_each = local.glue_db_list
123123
# name = each.key
124124
# iam_roles = {
125-
# datalake_role = "${module.iam.segment_datalake_iam_role_arn}",
126-
# emr_instance_profile_role = "${module.iam.iam_emr_instance_profile}"
125+
# datalake_role = module.iam.segment_datalake_iam_role_arn,
126+
# emr_instance_profile_role = module.iam.iam_emr_instance_profile
127127
# }
128128
# }
129129
```
@@ -227,7 +227,7 @@ code to accomplish this.
227227

228228
To develop in this repository, you'll want the following tools set up:
229229

230-
* [Terraform](https://www.terraform.io/downloads.html), >= 0.12 (note that 0.12 is used to develop this module, even though 0.11 is supported)
230+
* [Terraform](https://www.terraform.io/downloads.html), >= 0.12 (note that 0.12 is used to develop this module, 0.11 is no longer supported)
231231
* [terraform-docs](https://github.com/segmentio/terraform-docs)
232232
* [tflint](https://github.com/terraform-linters/tflint)
233233
* [Ruby](https://www.ruby-lang.org/en/documentation/installation/), [>= 2.4.2](https://rvm.io)

modules/emr/main.tf

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11
# Creates an EMR cluster that will be used to transform and load events into the Data Lake.
22
# https://www.terraform.io/docs/providers/aws/r/emr_cluster.html
33
resource "aws_emr_cluster" "segment_data_lake_emr_cluster" {
4-
name = "${var.cluster_name}"
4+
name = var.cluster_name
55
release_label = "emr-5.33.0"
66
applications = ["Hadoop", "Hive", "Spark"]
77

88
log_uri = "s3://${var.s3_bucket}/${var.emr_logs_s3_prefix}"
99

1010
ec2_attributes {
11-
subnet_id = "${var.subnet_id}"
12-
emr_managed_master_security_group = "${var.master_security_group}"
13-
emr_managed_slave_security_group = "${var.slave_security_group}"
14-
instance_profile = "${var.iam_emr_instance_profile}"
11+
subnet_id = var.subnet_id
12+
emr_managed_master_security_group = var.master_security_group
13+
emr_managed_slave_security_group = var.slave_security_group
14+
instance_profile = var.iam_emr_instance_profile
1515
}
1616

17-
service_role = "${var.iam_emr_service_role}"
18-
autoscaling_role = "${var.iam_emr_autoscaling_role}"
17+
service_role = var.iam_emr_service_role
18+
autoscaling_role = var.iam_emr_autoscaling_role
1919

2020
master_instance_group {
21-
instance_type = "${var.master_instance_type}"
21+
instance_type = var.master_instance_type
2222
name = "master_group"
2323

2424
ebs_config {
@@ -29,8 +29,8 @@ resource "aws_emr_cluster" "segment_data_lake_emr_cluster" {
2929
}
3030

3131
core_instance_group {
32-
instance_type = "${var.core_instance_type}"
33-
instance_count = "${var.core_instance_count}"
32+
instance_type = var.core_instance_type
33+
instance_count = var.core_instance_count
3434
name = "core_group"
3535

3636
ebs_config {
@@ -110,15 +110,15 @@ EOF
110110
]
111111
EOF
112112

113-
tags = "${local.tags}"
113+
tags = local.tags
114114
}
115115

116116
resource "aws_emr_instance_group" "task" {
117117
name = "task_group"
118-
cluster_id = "${aws_emr_cluster.segment_data_lake_emr_cluster.id}"
118+
cluster_id = aws_emr_cluster.segment_data_lake_emr_cluster.id
119119

120-
instance_type = "${var.task_instance_type}"
121-
instance_count = "${var.task_instance_count}"
120+
instance_type = var.task_instance_type
121+
instance_count = var.task_instance_count
122122

123123
ebs_config {
124124
size = "64"

modules/emr/output.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
output "cluster_id" {
2-
value = "${aws_emr_cluster.segment_data_lake_emr_cluster.id}"
2+
value = aws_emr_cluster.segment_data_lake_emr_cluster.id
33
}

modules/emr/variables.tf

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,100 +1,100 @@
11
variable "s3_bucket" {
22
description = "Name of the S3 bucket used by the Data Lake. The EMR cluster will be configured to store logs in this bucket."
3-
type = "string"
3+
type = string
44
}
55

66
variable "subnet_id" {
77
description = "VPC subnet id where you want the job flow to launch. Cannot specify the cc1.4xlarge instance type for nodes of a job flow launched in a Amazon VPC."
8-
type = "string"
8+
type = string
99
}
1010

1111
variable "master_security_group" {
1212
description = "Identifier of the Amazon EC2 EMR-Managed security group for the master node."
13-
type = "string"
13+
type = string
1414
default = ""
1515
}
1616

1717
variable "slave_security_group" {
1818
description = "Identifier of the Amazon EC2 EMR-Managed security group for the slave nodes."
19-
type = "string"
19+
type = string
2020
default = ""
2121
}
2222

2323
variable "tags" {
2424
description = "A map of tags to add to all resources. A vendor=segment tag will be added automatically (which is also used by the IAM policy to provide Segment access to submit jobs)."
25-
type = "map"
25+
type = map(string)
2626
default = {}
2727
}
2828

2929
variable "cluster_name" {
3030
description = "Name of the EMR cluster that the module creates"
31-
type = "string"
31+
type = string
3232
default = "segment-data-lake"
3333
}
3434

3535
variable "emr_logs_s3_prefix" {
3636
description = "Prefix for writing EMR cluster logs to S3. Make sure to include a trailing slash (/) when setting this."
37-
type = "string"
37+
type = string
3838
default = "logs/"
3939
}
4040

4141
variable "iam_emr_service_role" {
4242
description = "Name of the EMR service role"
43-
type = "string"
43+
type = string
4444
}
4545

4646
variable "iam_emr_autoscaling_role" {
4747
description = "Name of the EMR autoscaling role"
48-
type = "string"
48+
type = string
4949
}
5050

5151
variable "iam_emr_instance_profile" {
5252
description = "Name of the EMR EC2 instance profile"
53-
type = "string"
53+
type = string
5454
}
5555

5656
variable "master_instance_type" {
5757
description = "EC2 Instance Type for Master"
58-
type = "string"
58+
type = string
5959
default = "m5.xlarge"
6060
}
6161

6262
variable "core_instance_type" {
6363
description = "EC2 Instance Type for Core Nodes"
64-
type = "string"
64+
type = string
6565
default = "m5.xlarge"
6666
}
6767

6868
variable "task_instance_type" {
6969
description = "EC2 Instance Type for Task Nodes"
70-
type = "string"
70+
type = string
7171
default = "m5.xlarge"
7272
}
7373

7474
variable "core_instance_count" {
7575
description = "Number of Core Nodes"
76-
type = "string"
76+
type = string
7777
default = "2"
7878
}
7979

8080
variable "core_instance_max_count" {
8181
description = "Max number of Core Nodes used on autoscale"
82-
type = "string"
82+
type = string
8383
default = "4"
8484
}
8585

8686
variable "task_instance_count" {
8787
description = "Number of instances of Task Nodes"
88-
type = "string"
88+
type = string
8989
default = "2"
9090
}
9191

9292
variable "task_instance_max_count" {
9393
description = "Max number of Task Nodes used on autoscale"
94-
type = "string"
94+
type = string
9595
default = "4"
9696
}
9797

9898
locals {
99-
tags = "${merge(map("vendor", "segment"), var.tags)}"
99+
tags = merge(tomap({"vendor" = "segment"}), var.tags)
100100
}

modules/glue/main.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44
# makes the schema available to various tools like Athena, Spectrum, EMR etc.
55
# https://www.terraform.io/docs/providers/aws/r/glue_catalog_database.html
66
resource "aws_glue_catalog_database" "segment_data_lake_glue_catalog" {
7-
name = "${var.name}"
8-
description = "${var.description}"
7+
name = var.name
8+
description = var.description
99
}

modules/glue/output.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
output "database_name" {
2-
value = "${aws_glue_catalog_database.segment_data_lake_glue_catalog.name}"
2+
value = aws_glue_catalog_database.segment_data_lake_glue_catalog.name
33
}

modules/glue/variables.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
variable "name" {
22
description = "The name of the database."
3-
type = "string"
3+
type = string
44
}
55

66
variable "description" {
77
description = "Description of the database."
8-
type = "string"
8+
type = string
99
default = "Segment Data Lake"
1010
}

modules/iam/main.tf

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
resource "aws_iam_role" "segment_data_lake_iam_role" {
44
name = "SegmentDataLakeRole${var.suffix}"
55
description = "IAM Role used by Segment"
6-
assume_role_policy = "${data.aws_iam_policy_document.segment_data_lake_assume_role_policy_document.json}"
7-
tags = "${local.tags}"
6+
assume_role_policy = data.aws_iam_policy_document.segment_data_lake_assume_role_policy_document.json
7+
tags = local.tags
88
}
99

1010
# Policy attached to the IAM role.
@@ -20,15 +20,15 @@ data "aws_iam_policy_document" "segment_data_lake_assume_role_policy_document" {
2020

2121
principals {
2222
type = "AWS"
23-
identifiers = "${var.segment_aws_accounts}"
23+
identifiers = var.segment_aws_accounts
2424
}
2525

2626
effect = "Allow"
2727

2828
condition {
2929
test = "StringEquals"
3030
variable = "sts:ExternalId"
31-
values = "${var.external_ids}"
31+
values = var.external_ids
3232
}
3333
}
3434
}
@@ -43,7 +43,7 @@ resource "aws_iam_policy" "segment_data_lake_policy" {
4343
name = "SegmentDataLakePolicy${var.suffix}"
4444
path = "/"
4545
description = "Gives access to resources in your Data Lake"
46-
policy = "${data.aws_iam_policy_document.segment_data_lake_policy_document.json}"
46+
policy = data.aws_iam_policy_document.segment_data_lake_policy_document.json
4747
}
4848

4949
data "aws_iam_policy_document" "segment_data_lake_policy_document" {
@@ -154,8 +154,8 @@ data "aws_iam_policy_document" "segment_data_lake_policy_document" {
154154
}
155155

156156
resource "aws_iam_role_policy_attachment" "segment_data_lake_role_policy_attachment" {
157-
role = "${aws_iam_role.segment_data_lake_iam_role.name}"
158-
policy_arn = "${aws_iam_policy.segment_data_lake_policy.arn}"
157+
role = aws_iam_role.segment_data_lake_iam_role.name
158+
policy_arn = aws_iam_policy.segment_data_lake_policy.arn
159159
}
160160

161161
# IAM role for EMR Service
@@ -178,12 +178,12 @@ resource "aws_iam_role" "segment_emr_service_role" {
178178
}
179179
EOF
180180

181-
tags = "${local.tags}"
181+
tags = local.tags
182182
}
183183

184184
resource "aws_iam_role_policy" "segment_emr_service_policy" {
185185
name = "SegmentEMRServicePolicy${var.suffix}"
186-
role = "${aws_iam_role.segment_emr_service_role.id}"
186+
role = aws_iam_role.segment_emr_service_role.id
187187

188188
policy = <<EOF
189189
{
@@ -281,17 +281,17 @@ resource "aws_iam_role" "segment_emr_instance_profile_role" {
281281
}
282282
EOF
283283

284-
tags = "${local.tags}"
284+
tags = local.tags
285285
}
286286

287287
resource "aws_iam_instance_profile" "segment_emr_instance_profile" {
288288
name = "SegmentEMRInstanceProfile${var.suffix}"
289-
role = "${aws_iam_role.segment_emr_instance_profile_role.name}"
289+
role = aws_iam_role.segment_emr_instance_profile_role.name
290290
}
291291

292292
resource "aws_iam_role_policy" "segment_emr_instance_profile_policy" {
293293
name = "SegmentEMRInstanceProfilePolicy${var.suffix}"
294-
role = "${aws_iam_role.segment_emr_instance_profile_role.id}"
294+
role = aws_iam_role.segment_emr_instance_profile_role.id
295295

296296
policy = <<EOF
297297
{
@@ -386,12 +386,12 @@ resource "aws_iam_role" "segment_emr_autoscaling_role" {
386386
}
387387
EOF
388388

389-
tags = "${local.tags}"
389+
tags = local.tags
390390
}
391391

392392
resource "aws_iam_role_policy" "segmnet_emr_autoscaling_policy" {
393393
name = "SegmentEMRAutoscalingPolicy${var.suffix}"
394-
role = "${aws_iam_role.segment_emr_autoscaling_role.id}"
394+
role = aws_iam_role.segment_emr_autoscaling_role.id
395395

396396
policy = <<EOF
397397
{

modules/iam/output.tf

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
output "iam_emr_instance_profile" {
2-
value = "${aws_iam_instance_profile.segment_emr_instance_profile.name}"
2+
value = aws_iam_instance_profile.segment_emr_instance_profile.name
33
}
44

55
output "iam_emr_service_role" {
6-
value = "${aws_iam_role.segment_emr_service_role.name}"
6+
value = aws_iam_role.segment_emr_service_role.name
77
}
88

99
output "iam_emr_autoscaling_role" {
10-
value = "${aws_iam_role.segment_emr_autoscaling_role.name}"
10+
value = aws_iam_role.segment_emr_autoscaling_role.name
1111
}
1212

1313
output "segment_datalake_iam_role_arn" {
14-
value = "${aws_iam_role.segment_data_lake_iam_role.arn}"
14+
value = aws_iam_role.segment_data_lake_iam_role.arn
1515
}
1616

1717
output "iam_emr_instance_profile_role_arn" {
18-
value = "${aws_iam_role.segment_emr_instance_profile_role.arn}"
18+
value = aws_iam_role.segment_emr_instance_profile_role.arn
1919
}
2020

2121

0 commit comments

Comments
 (0)