Skip to content

Commit

Permalink
taking region as input
Browse files Browse the repository at this point in the history
  • Loading branch information
shashitnak committed May 20, 2024
1 parent 5f06b37 commit 92dad31
Show file tree
Hide file tree
Showing 4 changed files with 176 additions and 4 deletions.
7 changes: 4 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ on: [push]
jobs:
hello_world_job:
runs-on: ubuntu-latest
name: A job to say hello
name: Deploy Tailcall
steps:
- name: Hello world action step
id: hello
- name: Deploy Tailcall
id: deploy-tailcall
uses: tailcallhq/gh-action@255eb49f7e93d9f3c8c2cfe1a45a5a9930fdea41
with:
aws-access-key-id: 'aws-access-key-id'
aws-secret-access-key: 'aws-secret-access-key'
aws-region: 'us-east-1'
config: 'config/config.graphql'
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ inputs:
aws-secret-access-key:
description: 'AWS_SECRET_ACCESS_KEY'
required: true
aws-region:
description: 'AWS_REGION'
required: true
config:
description: 'Tailcall config path'
required: true
Expand All @@ -17,4 +20,5 @@ runs:
env:
AWS_ACCESS_KEY_ID: ${{ inputs.aws-access-key-id }}
AWS_SECRET_ACCESS_KEY: ${{ inputs.aws-secret-access-key }}
AWS_REGION: ${{ inputs.aws-region }}
CONFIG: ${{ inputs.config }}
2 changes: 1 addition & 1 deletion entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ echo "PWD: $(pwd)"
git clone https://github.com/tailcallhq/tailcall-on-aws.git
cd tailcall-on-aws
terraform init
terraform apply
TF_VAR_AWS_REGION=$AWS_REGION terraform apply
echo "PWD: $(pwd)"
167 changes: 167 additions & 0 deletions tailcall.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "3.62.0"
}
github = {
source = "integrations/github"
version = "6.0.0-beta"
}
}
}

variable "AWS_REGION" {
type = string
}

provider "aws" { region = var.AWS_REGION }

data "aws_iam_policy_document" "assume_role" {
statement {
effect = "Allow"

principals {
type = "Service"
identifiers = ["lambda.amazonaws.com"]
}

actions = ["sts:AssumeRole"]
}
}

resource "aws_iam_role" "iam_for_tailcall" {
name = "iam_for_tailcall"
assume_role_policy = data.aws_iam_policy_document.assume_role.json
}

provider "github" {}

data "github_release" "tailcall" {
owner = "tailcallhq"
repository = "tailcall"
retrieve_by = "latest"
}

data "http" "bootstrap" {
url = data.github_release.tailcall.assets[index(data.github_release.tailcall.assets.*.name, "tailcall-aws-lambda-bootstrap")].browser_download_url
}

resource "local_sensitive_file" "bootstrap" {
content_base64 = data.http.bootstrap.response_body_base64
filename = "config/bootstrap"
}

resource "local_sensitive_file" "config" {
content_base64 = filebase64("config/config.graphql")
filename = "config/config.graphql"
}

data "archive_file" "tailcall" {

depends_on = [
local_sensitive_file.bootstrap,
local_sensitive_file.config
]
type = "zip"
source_dir = "config/"
output_path = "tailcall.zip"
}

resource "aws_lambda_function" "tailcall" {
depends_on = [
data.archive_file.tailcall
]

role = aws_iam_role.iam_for_tailcall.arn
function_name = "tailcall"
runtime = "provided.al2"
architectures = ["x86_64"]
handler = "bootstrap"
filename = data.archive_file.tailcall.output_path
source_code_hash = data.archive_file.tailcall.output_base64sha256
}

resource "aws_api_gateway_rest_api" "tailcall" {
name = "tailcall"
}

resource "aws_api_gateway_resource" "proxy" {
rest_api_id = "${aws_api_gateway_rest_api.tailcall.id}"
parent_id = "${aws_api_gateway_rest_api.tailcall.root_resource_id}"
path_part = "{proxy+}"
}

resource "aws_api_gateway_method" "proxy" {
rest_api_id = "${aws_api_gateway_rest_api.tailcall.id}"
resource_id = "${aws_api_gateway_resource.proxy.id}"
http_method = "ANY"
authorization = "NONE"
api_key_required = false
}

resource "aws_api_gateway_integration" "lambda" {
rest_api_id = "${aws_api_gateway_rest_api.tailcall.id}"
resource_id = "${aws_api_gateway_method.proxy.resource_id}"
http_method = "${aws_api_gateway_method.proxy.http_method}"

integration_http_method = "POST"
type = "AWS_PROXY"
uri = "${aws_lambda_function.tailcall.invoke_arn}"
}

resource "aws_api_gateway_method" "proxy_root" {
rest_api_id = "${aws_api_gateway_rest_api.tailcall.id}"
resource_id = "${aws_api_gateway_rest_api.tailcall.root_resource_id}"
http_method = "ANY"
authorization = "NONE"
api_key_required = false
}

resource "aws_api_gateway_integration" "lambda_root" {
rest_api_id = "${aws_api_gateway_rest_api.tailcall.id}"
resource_id = "${aws_api_gateway_method.proxy_root.resource_id}"
http_method = "${aws_api_gateway_method.proxy_root.http_method}"

integration_http_method = "POST"
type = "AWS_PROXY"
uri = "${aws_lambda_function.tailcall.invoke_arn}"
}

resource "aws_api_gateway_deployment" "tailcall" {
depends_on = [
aws_api_gateway_integration.lambda,
aws_api_gateway_integration.lambda_root,
]

rest_api_id = "${aws_api_gateway_rest_api.tailcall.id}"
}

resource "aws_api_gateway_stage" "live" {
deployment_id = aws_api_gateway_deployment.tailcall.id
rest_api_id = aws_api_gateway_rest_api.tailcall.id
stage_name = "live"
}

resource "aws_api_gateway_method_settings" "live" {
rest_api_id = aws_api_gateway_rest_api.tailcall.id
stage_name = aws_api_gateway_stage.live.stage_name
method_path = "*/*"

settings {}
}

resource "aws_lambda_permission" "apigw" {
statement_id = "AllowAPIGatewayInvoke"
action = "lambda:InvokeFunction"
function_name = "${aws_lambda_function.tailcall.function_name}"
principal = "apigateway.amazonaws.com"

# The /*/* portion grants access from any method on any resource
# within the API Gateway "REST API".
source_arn = "${aws_api_gateway_rest_api.tailcall.execution_arn}/*/*"
}

output "graphql_url" {
value = "${aws_api_gateway_stage.live.invoke_url}/graphql"
}

0 comments on commit 92dad31

Please sign in to comment.