-
-
Notifications
You must be signed in to change notification settings - Fork 278
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Infra: tm-exporter lambda function using terragrunt. #6189
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
c101bcf
infra: added terraform snippets for tm-extrator deployment
mahesh-naxa 8fa7cd8
docs: updated readme for tm-extrctor lambda setup.
mahesh-naxa fe956c4
infra: added terragrunt.hcl for stag setup
mahesh-naxa fd1fcea
infra: added lambda conf and env.hcl for prod
mahesh-naxa d0373d0
infra: terragrunt now sources from git repository.
mahesh-naxa 830adbe
Merge remote-tracking branch 'origin/develop' into infra-lambda-tm-ex…
kshitijrajsharma 3e6d263
infra: terraform now sources modules from hotosm repo v1.0.0
mahesh-naxa 2c6428b
readme: updated terraform lambda deployment docs
mahesh-naxa 7a9378b
infra: modified terragrunt config to use aws_profile as defined
mahesh-naxa ed24bef
infra: moved raw_data_api & config_json to common inputs
mahesh-naxa fd94007
readme: Updated readme with input documentation
mahesh-naxa 55b7303
infra: bumped tm-extrator tag to v1.0.2
mahesh-naxa 711f1fc
Merge branch 'develop' into infra-lambda-tm-exporter
dakotabenjamin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,61 @@ | ||
<!-- GETTING STARTED --> | ||
## TM-Extractor with Terragrunt | ||
|
||
This directory contains infrastructure config for deploying [tm-extractor](https://github.com/hotosm/TM-Extractor) on AWS Lambda. | ||
|
||
Check [tm-extractor](https://github.com/hotosm/TM-Extractor) for resources created and exporter script. | ||
|
||
To get it running on your environment follow the following. | ||
|
||
### Prerequisites | ||
|
||
This are list of things you will need. | ||
* AWS IAM User with permission for creating resources such as lambda function, cloudwatch group, cloudwatch event etc. | ||
See all resource [here](https://github.com/hotosm/TM-Extractor/blob/ec37c1318325c534b4ac47f057263050e6e92f03/main.tf). | ||
* [Terraform](https://developer.hashicorp.com/terraform/tutorials/aws-get-started/install-cli) or (OpenTofu)[https://opentofu.org/docs/intro/install/] | ||
* [Terragrunt](https://terragrunt.gruntwork.io/docs/getting-started/install/#install-terragrunt) | ||
> **_NOTE:_** Please check compatibility note. https://terragrunt.gruntwork.io/docs/getting-started/supported-versions/ | ||
Tested on: Terraform v1.5.5 & terragrunt version v0.54.9. | ||
|
||
### Environments | ||
|
||
Before running deployment, make sure you have the following environment variables exported. | ||
- `TF_VAR_rawdata_api_auth_token`, Auth token for raw data api, Request [here](https://github.com/hotosm/raw-data-api/). | ||
- `TF_VAR_raw_data_api`, API endpoint. Defaults to https://api-prod.raw-data.hotosm.org/v1 | ||
- `TF_VAR_active_projects_api_base_url`, Your [tasking-manager](https://github.com/hotosm/tasking-manager) instance. | ||
Defaults to https://tasking-manager-staging-api.hotosm.org/api/v2 | ||
|
||
## Inputs and Local Variables | ||
`env.hcl` within each deployment environment overrides the input vars. | ||
``` | ||
locals { | ||
environment = "stag" | ||
# Appends to all the resource names eg: tm-extrator-hotosm-lambda-stag | ||
|
||
account_name = "hotosm" | ||
# Also appends to the resource names for better naming | ||
|
||
aws_profile = "default" | ||
# Acts as AWS_PROFILE environment var, If you have multiple profile defined in ~/.aws/credentials, you can set these so each envionment deployment uses its own set of profiles. | ||
|
||
aws_region = "ap-south-1" | ||
# The AWS region the resources should be created on. | ||
|
||
application = "tasking-manager" | ||
team = "HOTOSM" | ||
creator = "HOTOSM" | ||
owner = "HOTOSM" | ||
# Above are used for generating tags for AWS resources. | ||
} | ||
``` | ||
|
||
## Plan and Apply | ||
- `cd` into `scripts/aws/lambda/TM-Extractor/<your-environment-here>/tm-extractor`. | ||
- `terragrunt init`, initializes providers and resources. | ||
- `terragrunt plan`, run a plan to check for infrastructure changes. | ||
- `terragrunt apply`, applies the configuration. | ||
|
||
|
||
_For more information, please refer to the [TM-Extractor](https://github.com/hotosm/TM-Extractor)_ repository. | ||
|
||
<p align="right">(<a href="#readme-top">back to top</a>)</p> |
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,48 @@ | ||
# --------------------------------------------------------------------------------------------------------------------- | ||
# COMMON TERRAGRUNT CONFIGURATION | ||
# This is the common component configuration for mysql. The common variables for each environment to | ||
# deploy mysql are defined here. This configuration will be merged into the environment configuration | ||
# via an include block. | ||
# --------------------------------------------------------------------------------------------------------------------- | ||
|
||
# Terragrunt will copy the Terraform configurations specified by the source parameter, along with any files in the | ||
# working directory, into a temporary folder, and execute your Terraform commands in that folder. If any environment | ||
# needs to deploy a different module version, it should redefine this block with a different ref to override the | ||
# deployed version. | ||
terraform { | ||
# Sourcing from https://github.com/hotosm/TM-Extractor/ | ||
source = "${local.base_source_url}?ref=v1.0.1" | ||
} | ||
|
||
# --------------------------------------------------------------------------------------------------------------------- | ||
# Locals are named constants that are reusable within the configuration. | ||
# --------------------------------------------------------------------------------------------------------------------- | ||
locals { | ||
# Automatically load environment-level variables | ||
environment_vars = read_terragrunt_config(find_in_parent_folders("env.hcl")) | ||
|
||
# Extract out common variables for reuse | ||
env = local.environment_vars.locals.environment | ||
|
||
# Expose the base source URL so different versions of the module can be deployed in different environments. This will | ||
# be used to construct the terraform block in the child terragrunt configurations. | ||
base_source_url = "git::https://github.com/hotosm/TM-Extractor/" | ||
} | ||
|
||
# --------------------------------------------------------------------------------------------------------------------- | ||
# MODULE PARAMETERS | ||
# These are the variables we have to pass in to use the module. This defines the parameters that are common across all | ||
# environments. | ||
# --------------------------------------------------------------------------------------------------------------------- | ||
# Defaults, overridden by env.hcl | ||
|
||
inputs = { | ||
iam_lambda_role_name = "tm-extractor-role" | ||
cw_retention_in_days = "14" | ||
lambda_environment = "dev" | ||
lambda_memory_size = "128" | ||
lambda_timeout = "14" | ||
lambda_cron_expression = "cron(0 0 * * ? *)" | ||
raw_data_api = "https://api-prod.raw-data.hotosm.org/v1" | ||
config_json = "config.json" | ||
} |
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,14 @@ | ||
# Set common variables for the environment. This is automatically pulled in in the root terragrunt.hcl configuration to | ||
# feed forward to the child modules. | ||
# Check ../README.md ## Inputs and Local Variables for details. | ||
|
||
locals { | ||
environment = "dev" | ||
account_name = "naxadevelopers" | ||
aws_profile = "default" | ||
aws_region = "ap-south-1" | ||
application = "tasking-manager" | ||
team = "HOTOSM" | ||
creator = "HOTOSM" | ||
owner = "HOTOSM" | ||
} |
32 changes: 32 additions & 0 deletions
32
scripts/aws/lambda/TM-Extractor/dev/tm-extractor/terragrunt.hcl
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,32 @@ | ||
# --------------------------------------------------------------------------------------------------------------------- | ||
# TERRAGRUNT CONFIGURATION | ||
# This is the configuration for Terragrunt, a thin wrapper for Terraform that helps keep your code DRY and | ||
# maintainable: https://github.com/gruntwork-io/terragrunt | ||
# --------------------------------------------------------------------------------------------------------------------- | ||
|
||
# --------------------------------------------------------------------------------------------------------------------- | ||
# Include configurations that are common used across multiple environments. | ||
# --------------------------------------------------------------------------------------------------------------------- | ||
|
||
# Include the root `terragrunt.hcl` configuration. The root configuration contains settings that are common across all | ||
# components and environments, such as how to configure remote state. | ||
include "root" { | ||
path = find_in_parent_folders() | ||
} | ||
|
||
# Include the envcommon configuration for the component. The envcommon configuration contains settings that are common | ||
# for the component across all environments. | ||
include "envcommon" { | ||
path = "${dirname(find_in_parent_folders())}/_envcommon/lambda.hcl" | ||
} | ||
|
||
# --------------------------------------------------------------------------------------------------------------------- | ||
# Override parameters for this environment | ||
# --------------------------------------------------------------------------------------------------------------------- | ||
|
||
# For production, we want to specify bigger instance classes and storage, so we specify override parameters here. These | ||
# inputs get merged with the common inputs from the root and the envcommon lambda.hcl | ||
inputs = { | ||
zip_output_dir = "files" | ||
active_projects_api_base_url = "https://tm.naxa.com.np/api/v2" | ||
} |
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,14 @@ | ||
# Set common variables for the environment. This is automatically pulled in in the root terragrunt.hcl configuration to | ||
# feed forward to the child modules. | ||
# Check ../README.md ## Inputs and Local Variables for details. | ||
|
||
locals { | ||
environment = "prod" | ||
account_name = "hotosm" | ||
aws_profile = "default" | ||
aws_region = "ap-south-1" | ||
application = "tasking-manager" | ||
team = "HOTOSM" | ||
creator = "HOTOSM" | ||
owner = "HOTOSM" | ||
} |
31 changes: 31 additions & 0 deletions
31
scripts/aws/lambda/TM-Extractor/prod/tm-extractor/terragrunt.hcl
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,31 @@ | ||
# --------------------------------------------------------------------------------------------------------------------- | ||
# TERRAGRUNT CONFIGURATION | ||
# This is the configuration for Terragrunt, a thin wrapper for Terraform that helps keep your code DRY and | ||
# maintainable: https://github.com/gruntwork-io/terragrunt | ||
# --------------------------------------------------------------------------------------------------------------------- | ||
|
||
# --------------------------------------------------------------------------------------------------------------------- | ||
# Include configurations that are common used across multiple environments. | ||
# --------------------------------------------------------------------------------------------------------------------- | ||
|
||
# Include the root `terragrunt.hcl` configuration. The root configuration contains settings that are common across all | ||
# components and environments, such as how to configure remote state. | ||
include "root" { | ||
path = find_in_parent_folders() | ||
} | ||
|
||
# Include the envcommon configuration for the component. The envcommon configuration contains settings that are common | ||
# for the component across all environments. | ||
include "envcommon" { | ||
path = "${dirname(find_in_parent_folders())}/_envcommon/lambda.hcl" | ||
} | ||
|
||
# --------------------------------------------------------------------------------------------------------------------- | ||
# Override parameters for this environment | ||
# --------------------------------------------------------------------------------------------------------------------- | ||
|
||
# For production, we want to specify bigger instance classes and storage, so we specify override parameters here. These | ||
# inputs get merged with the common inputs from the root and the envcommon lambda.hcl | ||
inputs = { | ||
active_projects_api_base_url = "https://tasking-manager-tm4-production-api.hotosm.org/api/v2" | ||
} |
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,14 @@ | ||
# Set common variables for the environment. This is automatically pulled in in the root terragrunt.hcl configuration to | ||
# feed forward to the child modules. | ||
# Check ../README.md ## Inputs and Local Variables for details. | ||
|
||
locals { | ||
environment = "stag" | ||
account_name = "hotosm" | ||
aws_profile = "default" | ||
aws_region = "ap-south-1" | ||
application = "tasking-manager" | ||
team = "HOTOSM" | ||
creator = "HOTOSM" | ||
owner = "HOTOSM" | ||
} |
32 changes: 32 additions & 0 deletions
32
scripts/aws/lambda/TM-Extractor/stag/tm-extractor/terragrunt.hcl
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,32 @@ | ||
# --------------------------------------------------------------------------------------------------------------------- | ||
# TERRAGRUNT CONFIGURATION | ||
# This is the configuration for Terragrunt, a thin wrapper for Terraform that helps keep your code DRY and | ||
# maintainable: https://github.com/gruntwork-io/terragrunt | ||
# --------------------------------------------------------------------------------------------------------------------- | ||
|
||
# --------------------------------------------------------------------------------------------------------------------- | ||
# Include configurations that are common used across multiple environments. | ||
# --------------------------------------------------------------------------------------------------------------------- | ||
|
||
# Include the root `terragrunt.hcl` configuration. The root configuration contains settings that are common across all | ||
# components and environments, such as how to configure remote state. | ||
include "root" { | ||
path = find_in_parent_folders() | ||
} | ||
|
||
# Include the envcommon configuration for the component. The envcommon configuration contains settings that are common | ||
# for the component across all environments. | ||
include "envcommon" { | ||
path = "${dirname(find_in_parent_folders())}/_envcommon/lambda.hcl" | ||
} | ||
|
||
# --------------------------------------------------------------------------------------------------------------------- | ||
# Override parameters for this environment | ||
# --------------------------------------------------------------------------------------------------------------------- | ||
|
||
# For production, we want to specify bigger instance classes and storage, so we specify override parameters here. These | ||
# inputs get merged with the common inputs from the root and the envcommon lambda.hcl | ||
inputs = { | ||
zip_output_dir = "files" | ||
active_projects_api_base_url = "https://tasking-manager-staging-api.hotosm.org/api/v2" | ||
} |
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,89 @@ | ||
# --------------------------------------------------------------------------------------------------------------------- | ||
# TERRAGRUNT CONFIGURATION | ||
# Terragrunt is a thin wrapper for Terraform that provides extra tools for working with multiple Terraform modules, | ||
# remote state, and locking: https://github.com/gruntwork-io/terragrunt | ||
# --------------------------------------------------------------------------------------------------------------------- | ||
|
||
locals { | ||
# Automatically load environment-level variables | ||
environment_vars = read_terragrunt_config(find_in_parent_folders("env.hcl")) | ||
|
||
# Extract the variables we need for easy access | ||
account_name = local.environment_vars.locals.account_name | ||
aws_profile = local.environment_vars.locals.aws_profile | ||
aws_region = local.environment_vars.locals.aws_region | ||
environment = local.environment_vars.locals.environment | ||
application = local.environment_vars.locals.application | ||
team = local.environment_vars.locals.team | ||
creator = local.environment_vars.locals.creator | ||
owner = local.environment_vars.locals.owner | ||
} | ||
|
||
# Generate an AWS provider block | ||
generate "provider" { | ||
path = "provider.tf" | ||
if_exists = "overwrite_terragrunt" | ||
contents = <<EOF | ||
provider "aws" { | ||
region = "${local.aws_region}" | ||
profile = "${local.aws_profile}" | ||
default_tags { | ||
tags = { | ||
Environment = "${local.environment}" | ||
Application = "${local.application}" | ||
Team = "${local.team}" | ||
Creator = "${local.creator}" | ||
Owner = "${local.owner}" | ||
} | ||
} | ||
} | ||
EOF | ||
} | ||
|
||
#Export AWS_PROFILE env var. | ||
terraform { | ||
extra_arguments "aws_profile" { | ||
commands = [ | ||
"init", | ||
"apply", | ||
"refresh", | ||
"import", | ||
"plan", | ||
"destroy" | ||
] | ||
|
||
env_vars = { | ||
AWS_PROFILE = "${local.aws_profile}" | ||
} | ||
} | ||
} | ||
|
||
# Configure Terragrunt to automatically store tfstate files in an S3 bucket | ||
remote_state { | ||
backend = "s3" | ||
config = { | ||
encrypt = true | ||
bucket = "${get_env("TG_BUCKET_PREFIX", "")}tm-extractor-${local.account_name}-${local.aws_region}" | ||
key = "${path_relative_to_include()}/terraform.tfstate" | ||
region = local.aws_region | ||
dynamodb_table = "tm-extractor-locks" | ||
profile = "${local.aws_profile}" | ||
} | ||
generate = { | ||
path = "backend.tf" | ||
if_exists = "overwrite_terragrunt" | ||
} | ||
} | ||
|
||
|
||
# --------------------------------------------------------------------------------------------------------------------- | ||
# GLOBAL PARAMETERS | ||
# These variables apply to all configurations in this subfolder. These are automatically merged into the child | ||
# `terragrunt.hcl` config via the include block. | ||
# --------------------------------------------------------------------------------------------------------------------- | ||
|
||
# Configure root level variables that all resources can inherit. This is especially helpful with multi-account configs | ||
# where terraform_remote_state data sources are placed directly into the modules. | ||
inputs = merge( | ||
local.environment_vars.locals, | ||
) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should these be set with example defaults as a
env.hcl.example
with README instructions to replace and rename?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be up to us to have it already created. I have updated
README.md
withinscripts/aws/lambda/TM-Extrator/
with this information.@dakotabenjamin However i had no clue on what stag/prod input vars will be for
account_name
,account_region
. Can you have that updated for stag/prod.