Skip to content

Commit fe4612e

Browse files
committed
fix: removed tf v0.12 support
removed object type variables added more ci tests added changelog.md
1 parent 7f89c4b commit fe4612e

File tree

15 files changed

+244
-217
lines changed

15 files changed

+244
-217
lines changed

.github/workflows/ci.yml

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ name: CI
33
on:
44
pull_request:
55
branches: [master]
6-
types: [opened, reopened, synchronize, edited]
76

87
jobs:
98
env:
@@ -17,13 +16,19 @@ jobs:
1716
"env":[
1817
{
1918
"tf_version":"0.13.2",
20-
"tf_working_dir":"./examples/ci-13",
19+
"tf_working_dir":"./examples/ci-0_13",
2120
"aws_key_name":"byu_oit_terraform_dev_key",
2221
"aws_secret_name":"byu_oit_terraform_dev_secret"
2322
},
2423
{
25-
"tf_version":"0.12.26",
26-
"tf_working_dir":"./examples/ci-12",
24+
"tf_version":"0.14.8",
25+
"tf_working_dir":"./examples/ci-0_14",
26+
"aws_key_name":"byu_oit_terraform_dev_key",
27+
"aws_secret_name":"byu_oit_terraform_dev_secret"
28+
},
29+
{
30+
"tf_version":"1.0.0",
31+
"tf_working_dir":"./examples/ci-1",
2732
"aws_key_name":"byu_oit_terraform_dev_key",
2833
"aws_secret_name":"byu_oit_terraform_dev_secret"
2934
}
@@ -79,5 +84,20 @@ jobs:
7984

8085
- name: Terraform Plan
8186
working-directory: ${{ matrix.env.tf_working_dir }}
82-
run: terraform plan -input=false
83-
# TODO: Post plan back to PR
87+
run: terraform plan.tfplan -input=false
88+
89+
- name: Comment Terraform Plan
90+
uses: byu-oit/github-action-tf-plan-comment@v1
91+
with:
92+
comment-title: Plan for Terraform v-${{ matrix.env.tf_version }}
93+
github-token: ${{ secrets.GITHUB_TOKEN }}
94+
working-directory: ${{ matrix.env.tf_working_dir }}
95+
terraform-plan-file: plan.tfplan
96+
97+
- name: Analyze Terraform Plan
98+
uses: byu-oit/github-action-tf-plan-analyzer@v2
99+
with:
100+
divvycloud-username: ${{ secrets.DIVVYCLOUD_USERNAME }}
101+
divvycloud-password: ${{ secrets.DIVVYCLOUD_PASSWORD }}
102+
working-directory: ${{ matrix.env.tf_working_dir }}
103+
terraform-plan-file: plan.tfplan

README.md

Lines changed: 41 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -24,28 +24,46 @@ Note: If you do not specify `use_codedeploy = true`, the above process will not
2424
Also Note: CodePipeline and CodeDeploy cannot be used together to deploy a Lambda. If you are using CodePipeline, you cannot specify `use_codedeploy = true`. CodeDeploy works fine with other pipelining tools (e.g. GitHub Actions).
2525

2626
## Usage
27+
For a Zip file lambda
2728
```hcl
2829
module "lambda_api" {
29-
source = "github.com/byu-oit/terraform-aws-lambda-api?ref=v2.0.0"
30-
app_name = "my-lambda-dev"
31-
env = "dev"
32-
zip_file = {
33-
filename = "./src/lambda.zip"
34-
handler = "index.handler"
35-
runtime = "nodejs12.x"
30+
source = "github.com/byu-oit/terraform-aws-lambda-api?ref=v2.0.0"
31+
app_name = "my-lambda-codedeploy-dev"
32+
env = "dev"
33+
zip_filename = "./src/lambda.zip"
34+
zip_handler = "index.handler"
35+
zip_runtime = "nodejs12.x"
36+
37+
hosted_zone = module.acs.route53_zone
38+
https_certificate_arn = module.acs.certificate.arn
39+
vpc_id = module.acs.vpc.id
40+
public_subnet_ids = module.acs.public_subnet_ids
41+
role_permissions_boundary_arn = module.acs.role_permissions_boundary.arn
42+
codedeploy_service_role_arn = module.acs.power_builder_role.arn
43+
codedeploy_test_listener_port = 4443
44+
codedeploy_lifecycle_hooks = {
45+
BeforeAllowTraffic = aws_lambda_function.test_lambda.function_name
46+
AfterAllowTraffic = null
3647
}
48+
}
49+
```
50+
51+
For a docker image lambda:
52+
```hcl
53+
module "lambda_api" {
54+
source = "github.com/byu-oit/terraform-aws-lambda-api?ref=v2.0.0"
55+
app_name = "my-docker-lambda"
56+
image_uri = "my-image-from-my-ecr:latest"
3757
hosted_zone = module.acs.route53_zone
3858
https_certificate_arn = module.acs.certificate.arn
3959
vpc_id = module.acs.vpc.id
4060
public_subnet_ids = module.acs.public_subnet_ids
4161
role_permissions_boundary_arn = module.acs.role_permissions_boundary.arn
42-
codedeploy_config = {
43-
service_role_arn = module.acs.power_builder_role.arn
44-
test_listener_port = 4443
45-
lifecycle_hooks = {
46-
BeforeAllowTraffic = aws_lambda_function.test_lambda.function_name
47-
AfterAllowTraffic = null
48-
}
62+
codedeploy_service_role_arn = module.acs.power_builder_role.arn
63+
codedeploy_test_listener_port = 4443
64+
codedeploy_lifecycle_hooks = {
65+
BeforeAllowTraffic = aws_lambda_function.test_lambda.function_name
66+
AfterAllowTraffic = null
4967
}
5068
}
5169
```
@@ -68,21 +86,26 @@ module "lambda_api" {
6886
* DNS A-Record
6987

7088
## Requirements
71-
* Terraform version 0.12.21 or greater
72-
* AWS provider version 2.56 or greater
89+
* Terraform version 0.13.2 or greater
90+
* AWS provider version 3.0 or greater
7391

7492
## Inputs
7593
| Name | Type | Description | Default |
7694
| --- | --- | --- | --- |
7795
| app_name | string | application name (include the env aka. 'my-api-dev') | |
78-
| zip_file | [object](#zip_file_config) | configuration for a zip file lambda (conflicts with `image_uri`) | null |
7996
| image_uri | string | ECR Image URI containing the function's deployment package (conflicts with `zip_file`)| null |
97+
| zip_filename | string | File that contains your compiled or zipped source code. |
98+
| zip_handler | string | Lambda event handler |
99+
| zip_runtime | string | Lambda runtime |
80100
| lambda_vpc_config | [object](#lambda_vpc_config) | Lambda VPC object. Used if lambda requires to run inside a VPC | null |
81101
| environment_variables | map(string) | A map that defines environment variables for the Lambda function. | |
82102
| domain_url | string | Custom domain URL for the API, defaults to <app_name>.<hosted_zone_domain> | null | |
83103
| hosted_zone | [object](#hosted_zone) | Hosted Zone object to redirect to ALB. (Can pass in the aws_hosted_zone object). A and AAAA records created in this hosted zone. | |
84104
| https_certificate_arn | string | ARN of the HTTPS certificate of the hosted zone/domain. | |
85-
| codedeploy_config | [object](#codedeploy_config) | Configuration for putting CodeDeploy on the lambda | null |
105+
| codedeploy_service_role_arn | string | ARN of the IAM Role for the CodeDeploy to use to initiate new deployments. (usually the PowerBuilder Role) |
106+
| codedeploy_lifecycle_hooks | [object](#codedeploy_lifecycle_hooks) | Define Lambda Functions for CodeDeploy lifecycle event hooks. Or set this variable to null to not have any lifecycle hooks invoked. Defaults to null | null
107+
| codedeploy_appspec_filename | string | Filename (including path) to use when outputing appspec json. | `appspec.json` in the current working directory (i.e. where you ran `terraform apply`) |
108+
| codedeploy_test_listener_port | number | The port for a codedeploy test listener. If provided CodeDeploy will use this port for test traffic on the new replacement set during the blue-green deployment process before shifting production traffic to the replacement set. Defaults to null | null
86109
| vpc_id | string | VPC ID to deploy ALB and Lambda (If specified). | |
87110
| public_subnet_ids | list(string) | List of subnet IDs for the ALB. | |
88111
| tags | map(string) | A map of AWS Tags to attach to each resource created | {} |
@@ -93,26 +116,13 @@ module "lambda_api" {
93116
| memory_size | number | Size of the memory of the lambda. CPU will scale along with it | 128 (same as terraform default) |
94117
| xray_enabled | bool | Whether or not the X-Ray daemon should be created with the Lambda API. | false |
95118

96-
#### zip_file_config
97-
This configuration is used for when you are including the zipped up code for the lambda instead of using the `image_uri`
98-
* `filename` - (string) File that contains your compiled or zipped source code
99-
* `handler` - (string) Lambda event handler
100-
* `runtime` - (string) Lambda runtime
101-
102119
#### lambda_vpc_config
103120

104121
This variable is used when the lambda needs to be run from within a VPC.
105122

106123
* **`subnet_ids`** - List of subnet IDs for the Lambda service.
107124
* **`security_group_ids`** - List of extra security group IDs to attach to the lambda.
108125

109-
#### codedeploy_config
110-
If this configuration is included then this module will add the CodeDeploy App and Group required to deploy new versions of the Lambda through CodeDeploy, also allowing for the use of the LifeCycle hooks.
111-
* `service_role_arn` - (string) ARN of the IAM Role for the CodeDeploy to use to initiate new deployments (usually the PowerBuilder Role)
112-
* `lifecycle_hooks` - ([object](#codedeploy_lifecycle_hooks)) | Define Lambda Functions for CodeDeploy lifecycle event hooks. Or set this variable to null to not have any lifecycle hooks invoked
113-
* `appspec_filename` - (string) Filename (including path) to use when outputing appspec json (defaults to `appspec.json` in the current working directory)
114-
* `test_listener_port` - (number) The port for a codedeploy test listener. If provided CodeDeploy will use this port for test traffic on the new replacement set during the blue-green deployment process before shifting production traffic to the replacement set
115-
116126
#### codedeploy_lifecycle_hooks
117127

118128
This variable is used when generating the [appspec.json](#appspec) file. This will define what Lambda Functions to invoke

changelog.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Changelog
2+
3+
## v2.0.0
4+
2/24/2022 - Major breaking changes from v1.x:
5+
- dropped support for terraform v0.12
6+
- renamed `lambda_zip_file` to `zip_filename`
7+
- renamed `handler` to `zip_handler`
8+
- renamed `runtime` to `zip_runtime`
9+
- renamed `appspec_filename` to `codedeploy_appspec_filename`
10+
- removed `use_codedeploy` - just include the codedeploy variables to enable codedeploy
11+
- added `domain_url` variable to enable a custom API URL

examples/ci-13/ci.tf renamed to examples/ci-0_13/ci.tf

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,11 @@ module "acs" {
1212
}
1313

1414
module "lambda_api" {
15-
source = "../../"
16-
app_name = "my-lambda"
17-
zip_file = {
18-
filename = "./lambda.zip"
19-
handler = "index.handler"
20-
runtime = "nodejs12.x"
21-
}
15+
source = "../../"
16+
app_name = "my-lambda"
17+
zip_filename = "./lambda.zip"
18+
zip_handler = "index.handler"
19+
zip_runtime = "nodejs12.x"
2220
hosted_zone = module.acs.route53_zone
2321
https_certificate_arn = module.acs.certificate.arn
2422
vpc_id = module.acs.vpc.id

examples/ci-12/ci.tf renamed to examples/ci-0_14/ci.tf

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,22 @@
11
terraform {
2-
required_version = "0.12.26"
2+
required_version = "0.14.8"
33
}
44

55
provider "aws" {
6-
version = "~> 2.56"
6+
version = "~> 3.0"
77
region = "us-west-2"
88
}
99

1010
module "acs" {
1111
source = "github.com/byu-oit/terraform-aws-acs-info?ref=v3.4.0"
1212
}
1313

14-
module "lambda_zip_api" {
15-
source = "../../"
16-
app_name = "my-lambda"
17-
zip_file = {
18-
filename = "./lambda.zip"
19-
handler = "index.handler"
20-
runtime = "nodejs12.x"
21-
}
14+
module "lambda_api" {
15+
source = "../../"
16+
app_name = "my-lambda"
17+
zip_filename = "./lambda.zip"
18+
zip_handler = "index.handler"
19+
zip_runtime = "nodejs12.x"
2220
hosted_zone = module.acs.route53_zone
2321
https_certificate_arn = module.acs.certificate.arn
2422
vpc_id = module.acs.vpc.id

examples/ci-1/ci.tf

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
terraform {
2+
required_version = "1.0.0"
3+
required_providers {
4+
aws = {
5+
source = "hashicorp/aws"
6+
version = "~> 3.73.0"
7+
}
8+
}
9+
}
10+
11+
provider "aws" {
12+
region = "us-west-2"
13+
}
14+
15+
module "acs" {
16+
source = "github.com/byu-oit/terraform-aws-acs-info?ref=v3.4.0"
17+
}
18+
19+
module "lambda_api" {
20+
source = "../../"
21+
app_name = "my-lambda"
22+
zip_filename = "./lambda.zip"
23+
zip_handler = "index.handler"
24+
zip_runtime = "nodejs12.x"
25+
hosted_zone = module.acs.route53_zone
26+
https_certificate_arn = module.acs.certificate.arn
27+
vpc_id = module.acs.vpc.id
28+
public_subnet_ids = module.acs.public_subnet_ids
29+
role_permissions_boundary_arn = module.acs.role_permissions_boundary.arn
30+
xray_enabled = true
31+
32+
lambda_vpc_config = {
33+
subnet_ids = module.acs.private_subnet_ids
34+
security_group_ids = []
35+
}
36+
}
37+
38+
module "lambda_docker_api" {
39+
source = "../../"
40+
app_name = "my-docker-lambda"
41+
image_uri = "crccheck/hello-world:latest"
42+
hosted_zone = module.acs.route53_zone
43+
https_certificate_arn = module.acs.certificate.arn
44+
vpc_id = module.acs.vpc.id
45+
public_subnet_ids = module.acs.public_subnet_ids
46+
role_permissions_boundary_arn = module.acs.role_permissions_boundary.arn
47+
xray_enabled = true
48+
49+
lambda_vpc_config = {
50+
subnet_ids = module.acs.private_subnet_ids
51+
security_group_ids = []
52+
}
53+
}

examples/ci-12/lambda.zip

Whitespace-only changes.

examples/ci-13/lambda.zip

Whitespace-only changes.

examples/docker-lambda/docker.tf

Lines changed: 5 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
terraform {
2-
required_version = "0.13.4"
3-
}
4-
51
provider "aws" {
62
version = "~> 3.0"
73
region = "us-west-2"
@@ -12,9 +8,10 @@ module "acs" {
128
}
139

1410
module "lambda_api" {
15-
source = "../../"
11+
# source = "../../"
12+
source = "github.com/byu-oit/terraform-aws-lambda-api?ref=v2.0.0"
1613
app_name = "my-docker-lambda"
17-
image = "my-image-from-my-ecr:latest"
14+
image_uri = "my-image-from-my-ecr:latest"
1815
hosted_zone = module.acs.route53_zone
1916
https_certificate_arn = module.acs.certificate.arn
2017
vpc_id = module.acs.vpc.id
@@ -28,38 +25,6 @@ module "lambda_api" {
2825
}
2926
}
3027

31-
output "lambda" {
32-
value = module.lambda_api.lambda
33-
}
34-
35-
output "lambda_security_group" {
36-
value = module.lambda_api.lambda_security_group
37-
}
38-
39-
output "lambda_live_alias" {
40-
value = module.lambda_api.lambda_live_alias
41-
}
42-
43-
output "codedeploy_deployment_group" {
44-
value = module.lambda_api.codedeploy_deployment_group
45-
}
46-
47-
output "codedeploy_appspec_json_file" {
48-
value = module.lambda_api.codedeploy_appspec_json_file
49-
}
50-
51-
output "alb" {
52-
value = module.lambda_api.alb
53-
}
54-
55-
output "alb_security_group" {
56-
value = module.lambda_api.alb_security_group
57-
}
58-
59-
output "dns_record" {
60-
value = module.lambda_api.dns_record
61-
}
62-
63-
output "cloudwatch_log_group" {
64-
value = module.lambda_api.cloudwatch_log_group
28+
output "url" {
29+
value = module.lambda_api.dns_record.fqdn
6530
}

examples/no-codedeploy/example.tf

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,12 @@ module "acs" {
88
}
99

1010
module "lambda_api" {
11-
source = "../../"
12-
# source = "github.com/byu-oit/terraform-aws-lambda-api?ref=v1.3.0"
13-
app_name = "my-lambda-dev"
14-
zip_file = {
15-
filename = "./src/lambda.zip"
16-
handler = "index.handler"
17-
runtime = "nodejs12.x"
18-
}
11+
# source = "../../"
12+
source = "github.com/byu-oit/terraform-aws-lambda-api?ref=v2.0.0"
13+
app_name = "my-lambda-dev"
14+
zip_filename = "./src/lambda.zip"
15+
zip_handler = "index.handler"
16+
zip_runtime = "nodejs12.x"
1917
hosted_zone = module.acs.route53_zone
2018
https_certificate_arn = module.acs.certificate.arn
2119
vpc_id = module.acs.vpc.id

0 commit comments

Comments
 (0)