generated from AgnostiqHQ/covalent-executor-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added terraform files to lambda plugin (#89)
* Added terraform files to lambda plugin * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * minor code changes * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * skipping misplaced test * removing misplaced test --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: sankalp <[email protected]>
- Loading branch information
1 parent
c41fa3c
commit 1ed40e5
Showing
9 changed files
with
205 additions
and
21 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
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 |
---|---|---|
@@ -1,2 +1,5 @@ | ||
include VERSION | ||
include requirements.txt | ||
include covalent_awslambda_plugin/assets/infra/* | ||
exclude covalent_awslambda_plugin/assets/infra/*.swp | ||
include covalent_awslambda_plugin/assets/infra/*.tf |
17 changes: 17 additions & 0 deletions
17
covalent_awslambda_plugin/assets/infra/functional_tests.tfvars
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,17 @@ | ||
# Copyright 2021 Agnostiq Inc. | ||
# | ||
# This file is part of Covalent. | ||
# | ||
# Licensed under the Apache License 2.0 (the "License"). A copy of the | ||
# License may be obtained with this software package or at | ||
# | ||
# https://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Use of this file is prohibited except in compliance with the License. | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
name = "lambda-ci-ft-test" |
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,74 @@ | ||
# Copyright 2021 Agnostiq Inc. | ||
# | ||
# This file is part of Covalent. | ||
# | ||
# Licensed under the Apache License 2.0 (the "License"). A copy of the | ||
# License may be obtained with this software package or at | ||
# | ||
# https://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Use of this file is prohibited except in compliance with the License. | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
provider "aws" { | ||
region = var.aws_region | ||
} | ||
|
||
data "aws_caller_identity" "current" {} | ||
|
||
resource "aws_s3_bucket" "s3_bucket" { | ||
bucket = "${var.name}-covalent-artifact-bucket" | ||
force_destroy = true | ||
} | ||
|
||
resource "aws_iam_role" "lambda_iam_role" { | ||
name = "${var.name}-lambda-iam-role" | ||
assume_role_policy = jsonencode({ | ||
Version = "2012-10-17" | ||
Statement = [ | ||
{ | ||
Action = "sts:AssumeRole" | ||
Effect = "Allow" | ||
Sid = "" | ||
Principal = { | ||
Service = "lambda.amazonaws.com" | ||
} | ||
}, | ||
] | ||
}) | ||
managed_policy_arns = [ "arn:aws:iam::aws:policy/AWSLambdaExecute" ] | ||
|
||
tags = { | ||
"Terraform" = "true" | ||
} | ||
} | ||
|
||
resource "aws_ecr_repository" "ecr_repository" { | ||
name = "${var.name}-lambda-executor-base-ecr-repo" | ||
image_tag_mutability = "MUTABLE" | ||
|
||
force_delete = true | ||
image_scanning_configuration { | ||
scan_on_push = false | ||
} | ||
|
||
provisioner "local-exec" { | ||
command = "docker pull public.ecr.aws/covalent/covalent-lambda-executor:${var.executor_base_image_tag_name} && aws ecr get-login-password --region ${var.aws_region} | docker login --username AWS --password-stdin ${data.aws_caller_identity.current.account_id}.dkr.ecr.${var.aws_region}.amazonaws.com && docker tag public.ecr.aws/covalent/covalent-lambda-executor:${var.executor_base_image_tag_name} ${aws_ecr_repository.ecr_repository.repository_url}:${var.executor_base_image_tag_name} && docker push ${aws_ecr_repository.ecr_repository.repository_url}:${var.executor_base_image_tag_name}" | ||
} | ||
} | ||
|
||
resource aws_lambda_function lambda { | ||
function_name = "${var.name}-lambda-fn" | ||
role = aws_iam_role.lambda_iam_role.arn | ||
package_type = "Image" | ||
timeout = var.timeout | ||
memory_size = var.memory_size | ||
image_uri = "${aws_ecr_repository.ecr_repository.repository_url}:${var.executor_base_image_tag_name}" | ||
ephemeral_storage { | ||
size = var.ephemeral_storage # Min 512 MB and the Max 10240 MB | ||
} | ||
} |
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,25 @@ | ||
# Copyright 2021 Agnostiq Inc. | ||
# | ||
# This file is part of Covalent. | ||
# | ||
# Licensed under the Apache License 2.0 (the "License"). A copy of the | ||
# License may be obtained with this software package or at | ||
# | ||
# https://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Use of this file is prohibited except in compliance with the License. | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
output "s3_bucket_name" { | ||
value = aws_s3_bucket.s3_bucket.id | ||
description = "Allocated AWS S3 bucket name for storing lambda files" | ||
} | ||
|
||
output "function_name" { | ||
value = aws_lambda_function.lambda.function_name | ||
description = "AWS Lambda function name" | ||
} |
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,45 @@ | ||
# Copyright 2021 Agnostiq Inc. | ||
# | ||
# This file is part of Covalent. | ||
# | ||
# Licensed under the Apache License 2.0 (the "License"). A copy of the | ||
# License may be obtained with this software package or at | ||
# | ||
# https://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Use of this file is prohibited except in compliance with the License. | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
variable "name" { | ||
default = "covalent-lambda" | ||
description = "Prefix to use for all provisioned resources" | ||
} | ||
|
||
variable "executor_base_image_tag_name" { | ||
default = "latest" | ||
description = "Image tag for image in provisioned ecr repo to be used for lambda invocations" | ||
} | ||
|
||
variable "aws_region" { | ||
default = "us-east-1" | ||
description = "The aws region" | ||
} | ||
|
||
variable "timeout" { | ||
default = 900 | ||
description = "The amount of time your Lambda Function has to run in seconds" | ||
} | ||
|
||
variable "memory_size" { | ||
default = 1024 | ||
description = "The amount of memory in MB your Lambda Function can use at runtime" | ||
} | ||
|
||
variable "ephemeral_storage" { | ||
default = 1024 | ||
description = "Size of the ephemeral storage in MB" | ||
} |
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,24 @@ | ||
# Copyright 2021 Agnostiq Inc. | ||
# | ||
# This file is part of Covalent. | ||
# | ||
# Licensed under the Apache License 2.0 (the "License"). A copy of the | ||
# License may be obtained with this software package or at | ||
# | ||
# https://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Use of this file is prohibited except in compliance with the License. | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
terraform { | ||
required_providers { | ||
aws = { | ||
source = "hashicorp/aws" | ||
version = "5.17.0" | ||
} | ||
} | ||
} |
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