-
-
Notifications
You must be signed in to change notification settings - Fork 693
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Added deploy module to do complex deployments using AWS CodeDep…
…loy (#17)
- Loading branch information
1 parent
dafada2
commit 83f50be
Showing
10 changed files
with
843 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
builds/* | ||
deploy_script_*.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# Lambda Function Deployments using AWS CodeDeploy | ||
|
||
Configuration in this directory creates Lambda Function, Alias, and all resources required to create deployments using AWS CodeDeploy, and then it does a real deployment. | ||
|
||
## Usage | ||
|
||
To run this example you need to execute: | ||
|
||
```bash | ||
$ terraform init | ||
$ terraform plan | ||
$ terraform apply | ||
``` | ||
|
||
Note that this example may create resources which cost money. Run `terraform destroy` when you don't need these resources. | ||
|
||
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK --> | ||
## Requirements | ||
|
||
No requirements. | ||
|
||
## Providers | ||
|
||
| Name | Version | | ||
|------|---------| | ||
| aws | n/a | | ||
| random | n/a | | ||
|
||
## Inputs | ||
|
||
No input. | ||
|
||
## Outputs | ||
|
||
| Name | Description | | ||
|------|-------------| | ||
| appspec | n/a | | ||
| appspec\_content | n/a | | ||
| appspec\_sha256 | n/a | | ||
| codedeploy\_iam\_role\_name | Name of IAM role used by CodeDeploy | | ||
| deploy\_script | n/a | | ||
| script | n/a | | ||
| this\_codedeploy\_app\_name | Name of CodeDeploy application | | ||
| this\_codedeploy\_deployment\_group\_id | CodeDeploy deployment group name | | ||
|
||
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK --> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
provider "aws" { | ||
region = "eu-west-1" | ||
|
||
# Make it faster by skipping something | ||
skip_get_ec2_platforms = true | ||
skip_metadata_api_check = true | ||
skip_region_validation = true | ||
skip_credentials_validation = true | ||
skip_requesting_account_id = true | ||
} | ||
|
||
resource "random_pet" "this" { | ||
length = 2 | ||
} | ||
|
||
module "lambda_function" { | ||
source = "../../" | ||
|
||
function_name = "${random_pet.this.id}-lambda" | ||
handler = "index.lambda_handler" | ||
runtime = "python3.8" | ||
publish = true | ||
|
||
source_path = "${path.module}/../fixtures/python3.8-app1" | ||
hash_extra = "yo1" | ||
|
||
allowed_triggers = { | ||
APIGatewayAny = { | ||
service = "apigateway" | ||
arn = "arn:aws:execute-api:eu-west-1:135367859851:aqnku8akd0" | ||
} | ||
} | ||
} | ||
|
||
module "alias_refresh" { | ||
source = "../../modules/alias" | ||
|
||
refresh_alias = true | ||
|
||
name = "current-with-refresh" | ||
|
||
function_name = module.lambda_function.this_lambda_function_name | ||
|
||
# Set function_version when creating alias to be able to deploy using it, | ||
# because AWS CodeDeploy doesn't understand $LATEST as CurrentVersion. | ||
function_version = module.lambda_function.this_lambda_function_version | ||
} | ||
|
||
module "deploy" { | ||
source = "../../modules/deploy" | ||
|
||
alias_name = module.alias_refresh.this_lambda_alias_name | ||
function_name = module.lambda_function.this_lambda_function_name | ||
|
||
target_version = module.lambda_function.this_lambda_function_version | ||
description = "This is my awesome deploy!" | ||
|
||
create_app = true | ||
app_name = "my-awesome-app" | ||
|
||
create_deployment_group = true | ||
deployment_group_name = "something" | ||
|
||
create_deployment = true | ||
save_deploy_script = true | ||
wait_deployment_completion = true | ||
force_deploy = true | ||
|
||
attach_triggers_policy = true | ||
triggers = { | ||
start = { | ||
events = ["DeploymentStart"] | ||
name = "DeploymentStart" | ||
target_arn = aws_sns_topic.sns1.arn | ||
} | ||
success = { | ||
events = ["DeploymentSuccess"] | ||
name = "DeploymentSuccess" | ||
target_arn = aws_sns_topic.sns2.arn | ||
} | ||
} | ||
|
||
} | ||
|
||
resource "aws_sns_topic" "sns1" { | ||
name_prefix = random_pet.this.id | ||
} | ||
|
||
resource "aws_sns_topic" "sns2" { | ||
name_prefix = random_pet.this.id | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
output "this_codedeploy_app_name" { | ||
description = "Name of CodeDeploy application" | ||
value = module.deploy.this_codedeploy_app_name | ||
} | ||
|
||
output "this_codedeploy_deployment_group_id" { | ||
description = "CodeDeploy deployment group name" | ||
value = module.deploy.this_codedeploy_deployment_group_id | ||
} | ||
|
||
output "codedeploy_iam_role_name" { | ||
description = "Name of IAM role used by CodeDeploy" | ||
value = module.deploy.codedeploy_iam_role_name | ||
} | ||
|
||
output "appspec" { | ||
value = module.deploy.appspec | ||
} | ||
|
||
output "appspec_content" { | ||
value = module.deploy.appspec_content | ||
} | ||
|
||
output "appspec_sha256" { | ||
value = module.deploy.appspec_sha256 | ||
} | ||
|
||
output "script" { | ||
value = module.deploy.script | ||
} | ||
|
||
output "deploy_script" { | ||
value = module.deploy.deploy_script | ||
} |
Oops, something went wrong.