Skip to content

Commit 0e82d74

Browse files
authored
Merge pull request #21 from DNXLabs/feature/record-type
feature: add `record_type` variable
2 parents c014550 + fd192ff commit 0e82d74

File tree

7 files changed

+64
-50
lines changed

7 files changed

+64
-50
lines changed

.github/workflows/lint.yml

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,17 @@ jobs:
88
runs-on: ubuntu-latest
99
steps:
1010
- uses: actions/checkout@master
11-
- name: TFLint
12-
uses: docker://wata727/tflint
11+
- uses: terraform-linters/setup-tflint@v4
12+
name: Setup TFLint
13+
with:
14+
tflint_version: v0.52.0
15+
- name: Init TFLint
16+
run: tflint --init
17+
env:
18+
# https://github.com/terraform-linters/tflint/blob/master/docs/user-guide/plugins.md#avoiding-rate-limiting
19+
GITHUB_TOKEN: ${{ github.token }}
20+
- name: Run TFLint
21+
run: tflint -f compact
1322

1423
fmt:
1524
name: Code Format
@@ -47,18 +56,18 @@ jobs:
4756
cd -
4857
done
4958
50-
minimum:
51-
name: Minimum version check
52-
runs-on: ubuntu-latest
53-
container:
54-
image: hashicorp/terraform:0.13.0
55-
steps:
56-
- uses: actions/checkout@master
57-
- name: Validate Code
58-
env:
59-
AWS_REGION: 'us-east-1'
60-
TF_WARN_OUTPUT_ERRORS: 1
61-
run: |
62-
sed -i -e 's/>=/=/' -e 's/ \(\d\+\.\d\+\)"/ \1.0"/' versions.tf
63-
terraform init
64-
terraform validate -var "region=${AWS_REGION}" -var "vpc_id=vpc-123456" -var "subnets=[\"subnet-12345a\"]" -var "workers_ami_id=ami-123456" -var "cluster_ingress_cidrs=[]" -var "cluster_name=test_cluster"
59+
# minimum:
60+
# name: Minimum version check
61+
# runs-on: ubuntu-latest
62+
# container:
63+
# image: hashicorp/terraform:1.3.0
64+
# steps:
65+
# - uses: actions/checkout@master
66+
# - name: Validate Code
67+
# env:
68+
# AWS_REGION: 'us-east-1'
69+
# TF_WARN_OUTPUT_ERRORS: 1
70+
# run: |
71+
# sed -i -e 's/>=/=/' -e 's/ \(\d\+\.\d\+\)"/ \1.0"/' versions.tf
72+
# terraform init
73+
# terraform validate -var "region=${AWS_REGION}" -var "vpc_id=vpc-123456" -var "subnets=[\"subnet-12345a\"]" -var "workers_ami_id=ami-123456" -var "cluster_ingress_cidrs=[]"

README.md

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -38,47 +38,46 @@ If you have specified cloudfront_default_certificate, TLSv1 must be specified.
3838

3939
| Name | Version |
4040
|------|---------|
41-
| terraform | >= 0.13.0 |
41+
| terraform | >= 1.3.0 |
42+
| aws | >= 3.0.0 |
4243

4344
## Providers
4445

4546
| Name | Version |
4647
|------|---------|
47-
| aws | n/a |
48+
| aws | >= 3.0.0 |
4849

4950
## Inputs
5051

5152
| Name | Description | Type | Default | Required |
5253
|------|-------------|------|---------|:--------:|
5354
| alarm\_cloudfront\_500\_errors\_threshold | Cloudfront 500 Errors rate threshold (use 0 to disable this alarm) | `number` | `5` | no |
5455
| alarm\_prefix | String prefix for cloudwatch alarms. (Optional) | `string` | `"alarm"` | no |
55-
| alarm\_sns\_topics\_us | Alarm topics to create and alert on metrics on US region | `list` | `[]` | no |
56-
| alb\_cloudfront\_key | Key generated by terraform-aws-ecs module to allow ALB connection from CloudFront | `any` | n/a | yes |
57-
| alb\_dns\_name | ALB DNS Name that CloudFront will point as origin | `any` | n/a | yes |
58-
| certificate\_arn | Certificate for this app to use in CloudFront (US), must cover `hostname`. | `any` | n/a | yes |
59-
| cloudfront\_forward\_headers | Headers to forward to origin from CloudFront | `list` | <pre>[<br> "*"<br>]</pre> | no |
56+
| alarm\_sns\_topics\_us | Alarm topics to create and alert on metrics on US region | `list(string)` | `[]` | no |
57+
| alb\_cloudfront\_key | Key generated by terraform-aws-ecs module to allow ALB connection from CloudFront | `string` | n/a | yes |
58+
| alb\_dns\_name | ALB DNS Name that CloudFront will point as origin | `string` | n/a | yes |
59+
| certificate\_arn | Certificate for this app to use in CloudFront (US), must cover `hostname`. | `string` | n/a | yes |
60+
| cloudfront\_forward\_headers | Headers to forward to origin from CloudFront | `list(string)` | <pre>[<br> "*"<br>]</pre> | no |
6061
| cloudfront\_logging\_bucket | Bucket to store logs from app | `string` | `null` | no |
6162
| cloudfront\_logging\_prefix | Logging prefix | `string` | `""` | no |
6263
| cloudfront\_origin\_keepalive\_timeout | The amount of time, in seconds, that CloudFront maintains an idle connection with a custom origin server before closing the connection. Valid values are from 1 to 60 seconds. | `number` | `5` | no |
6364
| cloudfront\_origin\_read\_timeout | The amount of time, in seconds, that CloudFront waits for a response from a custom origin. The value applies both to the time that CloudFront waits for an initial response and the time that CloudFront waits for each subsequent packet. Valid values are from 4 to 60 seconds. | `number` | `30` | no |
64-
| cloudfront\_web\_acl\_id | Optional web acl (WAF) to attach to CloudFront | `string` | `""` | no |
65-
| cluster\_name | Name of existing ECS Cluster to deploy this app to | `any` | n/a | yes |
6665
| dynamic\_custom\_error\_response | One or more custom error response elements (multiples allowed) | <pre>list(object({<br> error_code = optional(number)<br> response_code = optional(number)<br> response_page_path = optional(string)<br> }))</pre> | `[]` | no |
6766
| dynamic\_custom\_origin\_config | Configuration for the custom origin config to be used in dynamic block | `any` | `[]` | no |
6867
| dynamic\_ordered\_cache\_behavior | Ordered Cache Behaviors to be used in dynamic block | `any` | `[]` | no |
69-
| hosted\_zone | Existing Hosted Zone domain to add hostnames as DNS records | `any` | n/a | yes |
68+
| hosted\_zone | Existing Hosted Zone domain to add hostnames as DNS records | `string` | n/a | yes |
7069
| hostname\_create | Create hostnames in the hosted zone passed? | `bool` | `true` | no |
71-
| hostnames | Hostnames to create DNS record for this app that the cloudfront distribution will accept | `any` | n/a | yes |
70+
| hostnames | Hostnames to create DNS record for this app that the cloudfront distribution will accept | `list(string)` | n/a | yes |
7271
| iam\_certificate\_id | Specifies IAM certificate id for CloudFront distribution | `string` | `null` | no |
7372
| minimum\_protocol\_version | The minimum version of the SSL protocol that you want CloudFront to use for HTTPS connections. <br> One of SSLv3, TLSv1, TLSv1\_2016, TLSv1.1\_2016 or TLSv1.2\_2018. Default: TLSv1.2\_2018. <br> NOTE: If you are using a custom certificate (specified with acm\_certificate\_arn or iam\_certificate\_id), <br> and have specified sni-only in ssl\_support\_method, TLSv1 or later must be specified. <br> If you have specified vip in ssl\_support\_method, only SSLv3 or TLSv1 can be specified. <br> If you have specified cloudfront\_default\_certificate, TLSv1 must be specified. | `string` | `"TLSv1.2_2018"` | no |
74-
| name | Name of your ECS service | `any` | n/a | yes |
73+
| name | Name of your ECS service | `string` | n/a | yes |
74+
| record\_type | Type of the record to create on Route53 | `string` | `"CNAME"` | no |
7575
| restriction\_location | The ISO 3166-1-alpha-2 codes for which you want CloudFront either to distribute your content (whitelist) or not distribute your content (blacklist) | `list(any)` | `[]` | no |
7676
| restriction\_type | The restriction type of your CloudFront distribution geolocation restriction. Options include none, whitelist, blacklist | `string` | `"none"` | no |
7777
| waf\_cloudfront\_enable | Enable WAF for Cloudfront distribution | `bool` | `false` | no |
7878
| wafv2\_managed\_block\_rule\_groups | List of WAF V2 managed rule groups, set to block | `list(string)` | `[]` | no |
7979
| wafv2\_managed\_rule\_groups | List of WAF V2 managed rule groups, set to count | `list(string)` | <pre>[<br> "AWSManagedRulesCommonRuleSet"<br>]</pre> | no |
8080
| wafv2\_rate\_limit\_rule | The limit on requests per 5-minute period for a single originating IP address (leave 0 to disable) | `number` | `0` | no |
81-
| web\_acl\_id | Web ACL ARN for Cloudfront distribution | `string` | `null` | no |
8281

8382
## Outputs
8483

_outputs.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@ output "cloudfront_zone_id" {
1515

1616
output "aws_cloudfront_origin_access_identity" {
1717
description = "Define cloudfront origin access identity"
18-
value = aws_cloudfront_origin_access_identity.default.*
18+
value = aws_cloudfront_origin_access_identity.default[*]
1919
}

_variables.tf

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
variable "name" {
22
description = "Name of your ECS service"
3-
}
4-
5-
variable "cluster_name" {
6-
description = "Name of existing ECS Cluster to deploy this app to"
3+
type = string
74
}
85

96
variable "hostnames" {
107
description = "Hostnames to create DNS record for this app that the cloudfront distribution will accept"
8+
type = list(string)
119
}
1210

1311
variable "dynamic_custom_error_response" {
@@ -23,32 +21,33 @@ variable "dynamic_custom_error_response" {
2321
variable "hostname_create" {
2422
description = "Create hostnames in the hosted zone passed?"
2523
default = true
24+
type = bool
2625
}
2726

2827
variable "hosted_zone" {
2928
description = "Existing Hosted Zone domain to add hostnames as DNS records"
29+
type = string
3030
}
3131

3232
variable "alb_cloudfront_key" {
3333
description = "Key generated by terraform-aws-ecs module to allow ALB connection from CloudFront"
34+
type = string
3435
}
3536

3637
variable "alb_dns_name" {
3738
description = "ALB DNS Name that CloudFront will point as origin"
39+
type = string
3840
}
3941

4042
variable "certificate_arn" {
4143
description = "Certificate for this app to use in CloudFront (US), must cover `hostname`."
42-
}
43-
44-
variable "cloudfront_web_acl_id" {
45-
default = ""
46-
description = "Optional web acl (WAF) to attach to CloudFront"
44+
type = string
4745
}
4846

4947
variable "cloudfront_forward_headers" {
5048
default = ["*"]
5149
description = "Headers to forward to origin from CloudFront"
50+
type = list(string)
5251
}
5352

5453
variable "cloudfront_logging_bucket" {
@@ -66,21 +65,25 @@ variable "cloudfront_logging_prefix" {
6665
variable "cloudfront_origin_keepalive_timeout" {
6766
default = 5
6867
description = "The amount of time, in seconds, that CloudFront maintains an idle connection with a custom origin server before closing the connection. Valid values are from 1 to 60 seconds."
68+
type = number
6969
}
7070

7171
variable "cloudfront_origin_read_timeout" {
7272
default = 30
7373
description = "The amount of time, in seconds, that CloudFront waits for a response from a custom origin. The value applies both to the time that CloudFront waits for an initial response and the time that CloudFront waits for each subsequent packet. Valid values are from 4 to 60 seconds."
74+
type = number
7475
}
7576

7677
variable "alarm_cloudfront_500_errors_threshold" {
7778
default = 5
7879
description = "Cloudfront 500 Errors rate threshold (use 0 to disable this alarm)"
80+
type = number
7981
}
8082

8183
variable "alarm_sns_topics_us" {
8284
default = []
8385
description = "Alarm topics to create and alert on metrics on US region"
86+
type = list(string)
8487
}
8588

8689
variable "iam_certificate_id" {
@@ -157,8 +160,8 @@ variable "wafv2_rate_limit_rule" {
157160
description = "The limit on requests per 5-minute period for a single originating IP address (leave 0 to disable)"
158161
}
159162

160-
variable "web_acl_id" {
163+
variable "record_type" {
161164
type = string
162-
description = "Web ACL ARN for Cloudfront distribution"
163-
default = null
165+
description = "Type of the record to create on Route53"
166+
default = "CNAME"
164167
}

route53-record.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ resource "aws_route53_record" "hostname" {
77

88
zone_id = data.aws_route53_zone.selected.zone_id
99
name = var.hostnames[count.index]
10-
type = "CNAME"
10+
type = var.record_type
1111
ttl = "300"
12-
records = [element(aws_cloudfront_distribution.default.*.domain_name, 0)]
12+
records = [element(aws_cloudfront_distribution.default[*].domain_name, 0)]
1313
}

versions.tf

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
terraform {
2-
required_version = ">= 0.13.0"
3-
4-
}
2+
required_version = ">= 1.3.0"
3+
required_providers {
4+
aws = {
5+
source = "hashicorp/aws"
6+
version = ">= 3.0.0"
7+
}
8+
}
9+
}

waf.tf

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ resource "aws_wafv2_web_acl" "waf_cloudfront" {
44
description = "WAF managed rules for Cloudfront"
55
scope = "CLOUDFRONT"
66

7-
8-
97
default_action {
108
allow {}
119
}

0 commit comments

Comments
 (0)