Skip to content

Commit f832452

Browse files
authored
Merge pull request #23 from byu-oit/docker
feat: added docker support, closes #21
2 parents a20665d + f6177c1 commit f832452

File tree

18 files changed

+403
-277
lines changed

18 files changed

+403
-277
lines changed

.github/workflows/ci.yml

Lines changed: 28 additions & 10 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
}
@@ -37,16 +42,13 @@ jobs:
3742
format:
3843
name: Terraform Format
3944
runs-on: ubuntu-latest
40-
needs: env
41-
strategy:
42-
matrix: ${{ fromJson(needs.env.outputs.matrix) }}
4345
steps:
4446
- uses: actions/checkout@v2
4547

4648
- name: Terraform Setup
4749
uses: hashicorp/setup-terraform@v1
4850
with:
49-
terraform_version: ${{ matrix.env.tf_version }}
51+
terraform_version: 1.0.0
5052

5153
- name: Terraform Format
5254
working-directory: "./"
@@ -58,6 +60,7 @@ jobs:
5860
needs: env
5961
strategy:
6062
matrix: ${{ fromJson(needs.env.outputs.matrix) }}
63+
fail-fast: false
6164
steps:
6265
- uses: actions/checkout@v2
6366

@@ -79,5 +82,20 @@ jobs:
7982

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

README.md

Lines changed: 50 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -24,30 +24,43 @@ 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=v1.3.0"
30-
app_name = "my-lambda"
31-
env = "dev"
32-
codedeploy_service_role_arn = module.acs.power_builder_role.arn
33-
lambda_zip_file = "./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+
3637
hosted_zone = module.acs.route53_zone
3738
https_certificate_arn = module.acs.certificate.arn
3839
vpc_id = module.acs.vpc.id
3940
public_subnet_ids = module.acs.public_subnet_ids
4041
role_permissions_boundary_arn = module.acs.role_permissions_boundary.arn
42+
codedeploy_service_role_arn = module.acs.power_builder_role.arn
4143
codedeploy_test_listener_port = 4443
42-
use_codedeploy = true
43-
timeout = 3
44-
memory_size = 128
45-
46-
lambda_vpc_config = {
47-
subnet_ids = module.acs.private_subnet_ids
48-
security_group_ids = ["sg-3asdfadsfasdfas"]
44+
codedeploy_lifecycle_hooks = {
45+
BeforeAllowTraffic = aws_lambda_function.test_lambda.function_name
46+
AfterAllowTraffic = null
4947
}
48+
}
49+
```
5050

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"
57+
hosted_zone = module.acs.route53_zone
58+
https_certificate_arn = module.acs.certificate.arn
59+
vpc_id = module.acs.vpc.id
60+
public_subnet_ids = module.acs.public_subnet_ids
61+
role_permissions_boundary_arn = module.acs.role_permissions_boundary.arn
62+
codedeploy_service_role_arn = module.acs.power_builder_role.arn
63+
codedeploy_test_listener_port = 4443
5164
codedeploy_lifecycle_hooks = {
5265
BeforeAllowTraffic = aws_lambda_function.test_lambda.function_name
5366
AfterAllowTraffic = null
@@ -73,35 +86,35 @@ module "lambda_api" {
7386
* DNS A-Record
7487

7588
## Requirements
76-
* Terraform version 0.12.21 or greater
77-
* AWS provider version 2.56 or greater
89+
* Terraform version 0.13.2 or greater
90+
* AWS provider version 3.0 or greater
7891

7992
## Inputs
8093
| Name | Type | Description | Default |
8194
| --- | --- | --- | --- |
82-
| app_name | string | application name |
83-
| env | string | application environment (e.g. dev, stg, prd) |
95+
| app_name | string | Application name to name your Lambda API and other resources (Must be <= 24 alphanumeric characters) | |
96+
| 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 |
100+
| lambda_vpc_config | [object](#lambda_vpc_config) | Lambda VPC object. Used if lambda requires to run inside a VPC | null |
101+
| environment_variables | map(string) | A map that defines environment variables for the Lambda function. | |
102+
| domain_url | string | Custom domain URL for the API, defaults to <app_name>.<hosted_zone_domain> | null | |
103+
| 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. | |
104+
| https_certificate_arn | string | ARN of the HTTPS certificate of the hosted zone/domain. | |
84105
| codedeploy_service_role_arn | string | ARN of the IAM Role for the CodeDeploy to use to initiate new deployments. (usually the PowerBuilder Role) |
85-
| lambda_zip_file | string | File that contains your compiled or zipped source code. |
86-
| handler | string | Lambda event handler |
87-
| runtime | string | Lambda runtime |
88-
| lambda_vpc_config | [object](#lambda_vpc_config) | Lambda VPC object. Used if lambda requires to run inside a VPC | null
89-
| environment_variables | map(string) | A map that defines environment variables for the Lambda function. |
90-
| 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. |
91-
| https_certificate_arn | string | ARN of the HTTPS certificate of the hosted zone/domain. |
92106
| 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
93-
| 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`) |
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`) |
94108
| 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
95-
| vpc_id | string | VPC ID to deploy ALB and Lambda (If specified). |
96-
| public_subnet_ids | list(string) | List of subnet IDs for the ALB. |
97-
| tags | map(string) | A map of AWS Tags to attach to each resource created | {}
98-
| role_permissions_boundary_arn | string | IAM Role Permissions Boundary ARN |
99-
| log_retention_in_days | number | CloudWatch log group retention in days. Defaults to 7. | 7
100-
| lambda_policies | list(string) | List of IAM Policy ARNs to attach to the lambda role. | []'
101-
| use_codedeploy | bool | If true, CodeDeploy App and Deployment Group will be created and TF will not update alias to point to new versions of the Lambda (becuase CodeDeploy will do that). | false
102-
| timeout | number | How long the lambda will run (in seconds) before timing out | 3 (same as terraform default)
103-
| memory_size | number | Size of the memory of the lambda. CPU will scale along with it | 128 (same as terraform default)
104-
| xray_enabled | bool | Whether or not the X-Ray daemon should be created with the Lambda API. | false
109+
| vpc_id | string | VPC ID to deploy ALB and Lambda (If specified). | |
110+
| public_subnet_ids | list(string) | List of subnet IDs for the ALB. | |
111+
| tags | map(string) | A map of AWS Tags to attach to each resource created | {} |
112+
| role_permissions_boundary_arn | string | IAM Role Permissions Boundary ARN | |
113+
| log_retention_in_days | number | CloudWatch log group retention in days. Defaults to 7. | 7 |
114+
| lambda_policies | list(string) | List of IAM Policy ARNs to attach to the lambda role. | []' |
115+
| timeout | number | How long the lambda will run (in seconds) before timing out | 3 (same as terraform default) |
116+
| memory_size | number | Size of the memory of the lambda. CPU will scale along with it | 128 (same as terraform default) |
117+
| xray_enabled | bool | Whether or not the X-Ray daemon should be created with the Lambda API. | false |
105118

106119
#### lambda_vpc_config
107120

@@ -128,7 +141,7 @@ You can pass in either the object from the AWS terraform provider for an AWS Hos
128141

129142
#### CloudWatch logs
130143

131-
This module will create a CloudWatch log group named `/aws/lambda/<app_name>-<env>`.
144+
This module will create a CloudWatch log group named `/aws/lambda/<app_name>`.
132145

133146
For instance with the [above example](#usage) the logs could be found in the CloudWatch log group: `aws/lambda/my-lambda-dev`.
134147

changelog.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
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` variable to `zip_filename`
7+
- renamed `handler` variable to `zip_handler`
8+
- renamed `runtime` variable to `zip_runtime`
9+
- renamed `appspec_filename` variable to `codedeploy_appspec_filename`
10+
- removed `use_codedeploy` variable - just include the codedeploy variables to enable codedeploy
11+
- removed `env` variable - just include the env inside the `app_name` variable
12+
- added `domain_url` variable to enable a custom API URL

examples/ci-0_13/ci.tf

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
terraform {
2+
required_version = "0.13.2"
3+
}
4+
5+
provider "aws" {
6+
version = "~> 3.0"
7+
region = "us-west-2"
8+
}
9+
10+
module "acs" {
11+
source = "github.com/byu-oit/terraform-aws-acs-info?ref=v3.4.0"
12+
}
13+
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"
20+
hosted_zone = module.acs.route53_zone
21+
https_certificate_arn = module.acs.certificate.arn
22+
vpc_id = module.acs.vpc.id
23+
public_subnet_ids = module.acs.public_subnet_ids
24+
role_permissions_boundary_arn = module.acs.role_permissions_boundary.arn
25+
xray_enabled = true
26+
27+
lambda_vpc_config = {
28+
subnet_ids = module.acs.private_subnet_ids
29+
security_group_ids = []
30+
}
31+
}
32+
33+
module "lambda_docker_api" {
34+
source = "../../"
35+
app_name = "my-docker-lambda"
36+
image_uri = "crccheck/hello-world:latest"
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+
xray_enabled = true
43+
44+
lambda_vpc_config = {
45+
subnet_ids = module.acs.private_subnet_ids
46+
security_group_ids = []
47+
}
48+
}
File renamed without changes.

examples/ci-0_14/ci.tf

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
terraform {
2+
required_version = "0.14.8"
3+
}
4+
5+
provider "aws" {
6+
version = "~> 3.0"
7+
region = "us-west-2"
8+
}
9+
10+
module "acs" {
11+
source = "github.com/byu-oit/terraform-aws-acs-info?ref=v3.4.0"
12+
}
13+
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"
20+
hosted_zone = module.acs.route53_zone
21+
https_certificate_arn = module.acs.certificate.arn
22+
vpc_id = module.acs.vpc.id
23+
public_subnet_ids = module.acs.public_subnet_ids
24+
role_permissions_boundary_arn = module.acs.role_permissions_boundary.arn
25+
xray_enabled = true
26+
27+
lambda_vpc_config = {
28+
subnet_ids = module.acs.private_subnet_ids
29+
security_group_ids = []
30+
}
31+
}
32+
33+
module "lambda_docker_api" {
34+
source = "../../"
35+
app_name = "my-docker-lambda"
36+
image_uri = "crccheck/hello-world:latest"
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+
xray_enabled = true
43+
44+
lambda_vpc_config = {
45+
subnet_ids = module.acs.private_subnet_ids
46+
security_group_ids = []
47+
}
48+
}
File renamed without changes.

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-1/lambda.zip

Whitespace-only changes.

0 commit comments

Comments
 (0)