Skip to content

Commit 41801e0

Browse files
authored
v0.2.0 (#21)
New changes: * tfe provider version * updated oac name, event name to provide uniqueness * fulfillment url evaluation in case of no changes * support for python3.12/3/13 lambda runtime in validations * kms alias name with a prefix.
1 parent d314f4b commit 41801e0

File tree

10 files changed

+21
-19
lines changed

10 files changed

+21
-19
lines changed

.config/.tflint.hcl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
plugin "aws" {
55
enabled = true
6-
version = "0.22.1"
6+
version = "0.54.0"
77
source = "github.com/terraform-linters/tflint-ruleset-aws"
88
}
99

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
v0.1.0
1+
v0.2.0

cloudfront.tf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ module "runtask_cloudfront" {
1919

2020
create_origin_access_control = true
2121
origin_access_control = {
22-
lambda_oac = {
23-
description = "CloudFront OAC to Lambda"
22+
lambda_oac_plan_analyzer = {
23+
description = "CloudFront OAC to Lambda AWS-IA plan analyzer"
2424
origin_type = "lambda"
2525
signing_behavior = "always"
2626
signing_protocol = "sigv4"
@@ -36,7 +36,7 @@ module "runtask_cloudfront" {
3636
origin_protocol_policy = "https-only"
3737
origin_ssl_protocols = ["TLSv1.2"]
3838
}
39-
origin_access_control = "lambda_oac"
39+
origin_access_control = "lambda_oac_plan_analyzer"
4040
custom_header = var.deploy_waf ? [local.cloudfront_custom_header] : null
4141
}
4242
}

examples/basic/providers.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ terraform {
88

99
tfe = {
1010
source = "hashicorp/tfe"
11-
version = "~> 0.38.0"
11+
version = ">= 0.38.0"
1212
}
1313
}
1414
}

kms.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ resource "aws_kms_key" "runtask_key" {
1111

1212
# Assign an alias to the key
1313
resource "aws_kms_alias" "runtask_key" {
14-
name = "alias/runTask"
14+
name = "alias/${local.solution_prefix}-runTask"
1515
target_key_id = aws_kms_key.runtask_key.key_id
1616
}
1717

@@ -28,6 +28,6 @@ resource "aws_kms_key" "runtask_waf" {
2828
resource "aws_kms_alias" "runtask_waf" {
2929
count = local.waf_deployment
3030
provider = aws.cloudfront_waf
31-
name = "alias/runtask-WAF"
31+
name = "alias/${local.solution_prefix}-runtask-WAF"
3232
target_key_id = aws_kms_key.runtask_waf[count.index].key_id
3333
}

lambda.tf

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ resource "aws_lambda_function" "runtask_eventbridge" {
2626
HCP_TF_CF_SECRET_ARN = var.deploy_waf ? aws_secretsmanager_secret.runtask_cloudfront[0].arn : null
2727
HCP_TF_CF_SIGNATURE = var.deploy_waf ? local.cloudfront_sig_name : null
2828
EVENT_BUS_NAME = var.event_bus_name
29+
EVENT_RULE_DETAIL_TYPE = local.solution_prefix # ensure uniqueness of event sent to each runtask state machine
2930
}
3031
}
3132
tracing_config {
@@ -42,7 +43,6 @@ resource "aws_lambda_function" "runtask_eventbridge" {
4243
resource "aws_lambda_function_url" "runtask_eventbridge" {
4344
function_name = aws_lambda_function.runtask_eventbridge.function_name
4445
authorization_type = "AWS_IAM"
45-
#checkov:skip=CKV_AWS_258:auth set to none, validation hmac inside the lambda code
4646
}
4747

4848
resource "aws_lambda_permission" "runtask_eventbridge" {
@@ -78,9 +78,10 @@ resource "aws_lambda_function" "runtask_request" {
7878
}
7979
environment {
8080
variables = {
81-
HCP_TF_ORG = var.hcp_tf_org
82-
RUNTASK_STAGES = join(",", var.runtask_stages)
83-
WORKSPACE_PREFIX = length(var.workspace_prefix) > 0 ? var.workspace_prefix : null
81+
HCP_TF_ORG = var.hcp_tf_org
82+
RUNTASK_STAGES = join(",", var.runtask_stages)
83+
WORKSPACE_PREFIX = length(var.workspace_prefix) > 0 ? var.workspace_prefix : null
84+
EVENT_RULE_DETAIL_TYPE = local.solution_prefix # ensure uniqueness of event sent to each runtask state machine
8485
}
8586
}
8687
tags = local.combined_tags

lambda/runtask_callback/handler.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def lambda_handler(event, _):
3535
logger.debug(json.dumps(event))
3636
try:
3737
# trim empty url from the payload
38-
if event["payload"]["result"]["fulfillment"]["url"] == False:
38+
if "fulfillment" in event["payload"]["result"] and event["payload"]["result"]["fulfillment"]["url"] == False:
3939
event["payload"]["result"]["fulfillment"].pop("url")
4040

4141
if (

lambda/runtask_eventbridge/handler.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1616
"""
1717

18-
"""HashiCorp HCP Terraform run task event handler implementation"""
18+
"""HCP Terraform run task event handler implementation"""
1919

2020
import os
2121
import hmac
@@ -46,6 +46,7 @@
4646
logger.info("Log level set to %s" % logger.getEffectiveLevel())
4747

4848
event_bus_name = os.environ.get("EVENT_BUS_NAME", "default")
49+
event_rule_detail_type = os.environ.get("EVENT_RULE_DETAIL_TYPE", "tfplan-analyzer")
4950
event_bridge_client = boto3.client("events")
5051

5152
## Add user-agent to event-bridge event
@@ -80,7 +81,6 @@ def lambda_handler(event, _):
8081
)
8182
return {"statusCode": 500, "body": "Internal Server Error"}
8283

83-
detail_type = "hcp-tf-runtask"
8484
try:
8585
if hcp_tf_use_waf == "True" and not contains_valid_cloudfront_signature(
8686
event=event
@@ -92,7 +92,7 @@ def lambda_handler(event, _):
9292
print_error("401 Unauthorized - Invalid Payload Signature", headers)
9393
return {"statusCode": 401, "body": "Invalid Payload Signature"}
9494

95-
response = forward_event(json_payload, detail_type)
95+
response = forward_event(json_payload, event_rule_detail_type)
9696

9797
if response["FailedEntryCount"] > 0:
9898
print_error(

lambda/runtask_request/handler.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
HCP_TF_ORG = os.environ.get("HCP_TF_ORG", False)
2323
WORKSPACE_PREFIX = os.environ.get("WORKSPACE_PREFIX", False)
2424
RUNTASK_STAGES = os.environ.get("RUNTASK_STAGES", False)
25+
EVENT_RULE_DETAIL_TYPE = os.environ.get("EVENT_RULE_DETAIL_TYPE", "tfplan-analyzer") # assume there could be multiple deployment of this module, this will ensure each rule are unique
2526

2627
logger = logging.getLogger()
2728
log_level = os.environ.get("log_level", logging.INFO)
@@ -34,7 +35,7 @@ def lambda_handler(event, _):
3435
logger.debug(json.dumps(event))
3536
try:
3637
VERIFY = True
37-
if event["payload"]["detail-type"] == "hcp-tf-runtask":
38+
if event["payload"]["detail-type"] == EVENT_RULE_DETAIL_TYPE:
3839
if (
3940
HCP_TF_ORG
4041
and event["payload"]["detail"]["organization_name"] != HCP_TF_ORG

variables.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,8 @@ variable "lambda_python_runtime" {
107107
type = string
108108
default = "python3.11"
109109
validation {
110-
condition = contains(["python3.11", "python3.10", "python3.9"], var.lambda_python_runtime)
111-
error_message = "Valid values for var: lambda_python_runtime are python3.11, python3.10, python3.9"
110+
condition = contains(["python3.13","python3.12","python3.11", "python3.10", "python3.9"], var.lambda_python_runtime)
111+
error_message = "Valid values for var: lambda_python_runtime are python3.13, python3.12, python3.11, python3.10, python3.9"
112112
}
113113
}
114114

0 commit comments

Comments
 (0)