Skip to content

Commit

Permalink
Adds VPC config (#11)
Browse files Browse the repository at this point in the history
* adds vpc config

* removes default value

* vpc test

* adds default values

* test

* changes default value

* test

* adds statement to IAM policy

* cleans up

---------

Co-authored-by: jubran nassar <[email protected]>
  • Loading branch information
jubranNassar and jubranNassar authored Mar 22, 2024
1 parent 5840d19 commit c2ceb3b
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 6 deletions.
11 changes: 8 additions & 3 deletions iac/lambda.tf
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ resource "aws_lambda_function" "autoscaler" {
filename = !local.use_s3_package ? data.archive_file.binary.output_path : null
source_code_hash = !local.use_s3_package ? data.archive_file.binary.output_base64sha256 : null

s3_bucket = local.use_s3_package ? var.autoscaler_s3_package.bucket : null
s3_key = local.use_s3_package ? var.autoscaler_s3_package.key : null
s3_bucket = local.use_s3_package ? var.autoscaler_s3_package.bucket : null
s3_key = local.use_s3_package ? var.autoscaler_s3_package.key : null
s3_object_version = local.use_s3_package ? var.autoscaler_s3_package.object_version : null

function_name = local.function_name
Expand All @@ -42,6 +42,11 @@ resource "aws_lambda_function" "autoscaler" {
architectures = [var.autoscaler_architecture == "amd64" ? "x86_64" : var.autoscaler_architecture]
timeout = var.autoscaling_timeout

vpc_config {
subnet_ids = var.subnet_ids
security_group_ids = var.security_group_ids
}

environment {
variables = {
AUTOSCALING_GROUP_ARN = var.autoscaling_group_arn
Expand Down Expand Up @@ -82,4 +87,4 @@ resource "aws_lambda_permission" "allow_cloudwatch_to_call_lambda" {
resource "aws_cloudwatch_log_group" "log_group" {
name = "/aws/lambda/${local.function_name}"
retention_in_days = 7
}
}
13 changes: 13 additions & 0 deletions iac/policy.tf
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,19 @@ data "aws_iam_policy_document" "autoscaler" {
resources = ["*"]
}

# Allow the Lambda to take actions on NetworkInterfaces
statement {
effect = "Allow"
actions = [
"ec2:DescribeNetworkInterfaces",
"ec2:CreateNetworkInterface",
"ec2:DeleteNetworkInterface",
"ec2:DescribeInstances",
"ec2:AttachNetworkInterface"
]
resources = ["*"]
}

# Allow the Lambda to read the secret from SSM Parameter Store.
statement {
effect = "Allow"
Expand Down
18 changes: 15 additions & 3 deletions iac/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ variable "spacelift_api_key_secret" {
variable "spacelift_api_key_endpoint" {
type = string
description = "Full URL of the Spacelift API endpoint to use, eg. https://demo.app.spacelift.io"
default = null
}

variable "worker_pool_id" {
Expand Down Expand Up @@ -81,9 +80,22 @@ variable "region" {

variable "autoscaler_s3_package" {
type = object({
bucket = string
key = string
bucket = string
key = string
object_version = optional(string)
})
description = "Configuration to retrieve autoscaler lambda package from s3 bucket"
default = null
}

variable "subnet_ids" {
type = list(string)
description = "optional subnet IDs to provide to the autoscaler VPC configuration"
default = [""]
}

variable "security_group_ids" {
type = list(string)
description = "optional security group IDs to provide to the autoscaler VPC configuration"
default = [""]
}

0 comments on commit c2ceb3b

Please sign in to comment.