-
Notifications
You must be signed in to change notification settings - Fork 9
Terraform, Lambda, and Frontend Changes #104
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
Open
gt1074
wants to merge
51
commits into
main
Choose a base branch
from
Terraform2
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
51 commits
Select commit
Hold shift + click to select a range
4f34a7a
Only necessary changes
gt1074 3f5ed96
Implementing localstack Pro / terraform-local (tflocal)
gt1074 0e4cddb
Revert "Implementing localstack Pro / terraform-local (tflocal)"
gt1074 a2fea97
Create test file / Universal Region Usage / Bug fixes
gt1074 9fde3df
wibl-python: cloud: AWS: Update conversion start lambda permissions a…
selimnairb 5c996d1
Merge pull request #84 from CCOMJHC/conversion-start-lambda-permissio…
gt1074 37b4044
Creating new terraform module parallel to configure-manager-ecs.sh
gt1074 527cc7c
Merge remote-tracking branch 'origin/Terraform2' into Terraform2
gt1074 8dbd839
Changing lambda configuration due to aws policy change
gt1074 e3e6d30
Bug fixes
gt1074 6259df1
Fixing .proto config files / Lambda permission change / Changing ecs …
gt1074 6d26614
Adding force delete to ecr repos
gt1074 473bc37
Initial implementation of Manager/Frontend ECS / bug fixing
gt1074 72c1ebc
Adding terraform specific proto documents / Removing local stack from…
gt1074 f523b85
Starting rds implementation
gt1074 5d457cf
Embed RDS inside manager ecs module / configure security group and db…
gt1074 3507725
Frontend RDS instance / Expanded container definitions / Cloudwatch g…
gt1074 2cd656f
Implementing Django s3 static storage / Static file adjustments / Fro…
gt1074 834148a
Moving Static Files
gt1074 3a99f5b
Starting TLS frontend implementation
gt1074 20590ac
Cloudfront additions, vpc permission changes, static bucket access ch…
gt1074 c846761
Fixing gitignore for static files / adding back missing files
gt1074 fb989bb
Changing Bulma to correct file extension / addressing cors issues wit…
gt1074 ca2f925
Large scale changes to cloud front / adding elastic cache to replace …
gt1074 6b385f3
Deletion marking, no lost metadata / Adjusting S3 permissions for lam…
gt1074 cd07b5e
Fixing state implementation
gt1074 91a86b3
Started development with AWS Location Services to replace the Open St…
gt1074 d38cd47
Fix map to include style and glyph information
gt1074 3cda58e
Adding SSM auth string management / Submission lambda bug fixes / Man…
gt1074 ef0412b
Adding SSM auth string management / Submission lambda bug fixes / Man…
gt1074 9dbd3a0
Socket consumer changes / Index event manager bug fixes
gt1074 6f099b2
Merge branch 'main' into Terraform2
gt1074 a6d928a
Move Terraform folder into AWS folder / Add build instruction / add d…
gt1074 94dafbb
Documentation changes / removing commented code / adding extra nat ga…
gt1074 4293785
Adding "geojson" extension support for wibl manager downloading
gt1074 e42e4c3
Changing lambda configurations to no longer have verbose output / rem…
gt1074 81ad96f
Adding s3 state storage for the wibl-python terraform configuration
gt1074 fe83a0a
Adding secret generation script, changing readme to include the script.
gt1074 a1c9768
Updating documentation
gt1074 1ef1541
Fixing statistics endpoint bug / Adding plotly as static instead of c…
gt1074 b439187
Bug Fixes
gt1074 42cf86a
tfvars now points to the generate_secret script for creating values.
gt1074 ee141a4
Adding the terraform bootstrap process from the upload server
gt1074 386fa03
Updating README to account for manual variable replacement in the s3 …
gt1074 7141815
Upadting README to account for the necessary update of the configurat…
gt1074 4b07c17
Fixing the bounding box bug.
gt1074 15f6cee
Merge branch '105-bounding-box-bugfixes' into Terraform2
gt1074 ceb65c9
Updating the gitignore to include terraform.tfvars and default_auth.txt
gt1074 3b385e9
Updating documentation / Removing auth files from git (tfvars, defaul…
gt1074 48966a1
Updating gitignore
gt1074 8f71a9c
Changed bucket configurations / raising minimum terraform, aws, and d…
gt1074 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 hidden or 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 hidden or 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
File renamed without changes.
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,133 @@ | ||
| # Terraform AWS Build Instructions | ||
|
|
||
| ## Setup | ||
| The following software items must be installed and configured before continuing | ||
|
|
||
| - Docker | ||
| - AWS CLI | ||
| - Terraform | ||
|
|
||
| ### 1. Changing default configurations | ||
| Inside the [tf-configure-step-1.bash](./tf-configure-step-1.bash) file there is a variable called `PROVIDER_PREFIX`. | ||
| Replace the value inside the quotation marks with a unique name to apply to all resources. Due to the nature of the cloud, | ||
| all AWS components must have name unique to its region, type. So, the value given will be used to create unique names | ||
| for all necessary resources. | ||
|
|
||
| Example: `PROVIDER_PREFIX='UNHJHC'` | ||
|
|
||
| Once you have updated the value, run the [tf-configure-step-1.bash](./tf-configure-step-1.bash) file. This script will | ||
| generate a file called `terraform.tfvars` inside the [Terraform](../Terraform) folder. This file has three sections, | ||
| variables that need to be changed, variables that are optional to change, and variables that can be left alone. | ||
|
|
||
| #### Variables That Need To Be Changed: | ||
| - region: Must be a valid AWS region code. Consider this list for available regions. [AWS_Region_List](https://docs.aws.amazon.com/global-infrastructure/latest/regions/aws-regions.html) | ||
| - DCDB_provider_id: Replace with your given DCDB provider id. | ||
| - superuser_username/password: Choose the main username and password used to access the frontend dashboard. | ||
| - frontend_secret_key: Following the directions is the `terraform.tfvars` file to generate a Django secret. The script | ||
| to do so is located [here](./generate_secret.sh). | ||
| - origin_secret: This password phrase adds an extra level of security between the CloudFront module and the | ||
| frontend's load balancer. Run the generate_secret script again to create a new value. | ||
| - DCDB_mode: By default the test mode is active. To switch to using the production URL, set this variable to 1. | ||
|
|
||
| #### Variables That Can Optionally Changed: | ||
| - frontend/manager_db_size: This variable sets the size, in gigabytes, of the respective databases. The frontend database | ||
| only contains bookkeeping information for user logins and common caching while the manager database contains all the | ||
| file metadata that is currently in the system. If you come across storage space issues, 99% of the time it will be the | ||
| manager database. | ||
| - frontend/manager_username/password: The database usernames and passwords are only used to internally access the database | ||
| contents inside each separate AWS RDS instance. These values can be set for added security. | ||
|
|
||
| #### Other Mandatory Replacement Area: | ||
| - In [main.tf](./main.tf) in the section near the top labeled `backend "s3"`, the variables inside must be | ||
| **manually updated**. They will not follow what is located inside the tfvars file. The variables that need to be updated | ||
| are `terraform-state-bucket`, `region`, and `terraform-state-key`. They must match their tfvars counter-parts, so copy | ||
| and pasting their values over is the easier course of action. | ||
|
|
||
| Example | ||
| ``` | ||
| terraform { | ||
| required_providers { | ||
| aws = { | ||
| source = "hashicorp/aws" | ||
| version = "~> 5.0" | ||
| } | ||
| docker = { | ||
| source = "kreuzwerker/docker" | ||
| version = "~> 3.0" | ||
| } | ||
| } | ||
|
|
||
| backend "s3" { | ||
| bucket = "REPLACE" | ||
| region = "REPLACE" | ||
| key = "REPLACE" | ||
| } | ||
|
|
||
| required_version = ">= 1.5.0" | ||
| } | ||
| ``` | ||
|
|
||
| - The step 1 script will generate an empty text file name `default_auth.txt`. Inside of this file you must put your DCDB | ||
| provider secret. If the secret is not copied into this file, the final steps of the data pipeline will fail. | ||
|
|
||
| ### 2. Bootstrapping Terraform | ||
| Terraform is able to modify and delete computing resources that were created using Terraform. To do this, Terraform must | ||
| store state information about what resources have been created. This state information can be stored locally on a single | ||
| compute. However, if the locally stored state information is lost, then you lose the ability to automatically update or | ||
| delete the computing resources originally created by Terraform. To avoid this problem, Terraform state can be stored | ||
| remotely in S3. In addition to providing a disaster recovery solution, storing state in S3 allows multiple | ||
| people/computers to manage a WIBL system created with Terraform, and to do so asynchronously, without having to | ||
| worry about each person's updates overwriting each other. | ||
|
|
||
| You can use the script [tf-configure-step-2.bash](tf-configure-step-2.bash) to create an S3 bucket in which to store | ||
| Terraform state. The name and key for the bucket should have been automatically set in the previous step, but remember | ||
| to update the [main.tf](./main.tf) so it matches the value in the `terraform.tfvars` file. | ||
|
|
||
| Running tf-configure-step-2.bash will look something like this: | ||
|
|
||
| ``` | ||
| CONTENT_ROOT: /Users/USER_NAME/.../WIBL/wibl-python | ||
| Using AWS_TF_ROOT: /Users/USER_NAME/.../WIBL/wibl-python/scripts/cloud/AWS/Terraform | ||
| Using AWS_PROFILE: default | ||
| Using TF_VARS: /Users/USER_NAME/.../WIBL/wibl-python/scripts/cloud/AWS/Terraform/terraform.tfvars | ||
| Using AWS_REGION: us-east-2 | ||
| Using TF_STATE_BUCKET: unhjhc-wibl-tf-state | ||
| Using TF_STATE_KEY: terraform/state/wibl-processing-server-deploy.tfstate | ||
| Using AWS_CLI: aws --profile default --region us-east-2 | ||
| Using AWS_ACCOUNT_NUMBER: XXXXXXXXXXXX | ||
| Creating terraform state bucket unhjhc-wibl-tf-state in AWS region us-east-2... | ||
| { | ||
| "Location": "https://unhjhc-wibl-tf-state.s3.amazonaws.com/" | ||
| } | ||
| Enabling bucket versioning in terraform state bucket unhjhc-wibl-tf-state... | ||
| Done. | ||
| ``` | ||
|
|
||
| ### 3. Building The Lambda Package | ||
| This step only works if `docker` is currently running on your system. Inside the outer [AWS](../../AWS) folder is a | ||
| script called [build-lambda.sh](../build-lambda.sh), run this script. Even if the script is successful, there may still | ||
| be a lingering `build` or `package` folder, pay these no mind and continue to the next step. | ||
|
|
||
| ### 4. Building The System With Terraform | ||
| This step also requires `docker` to work, so ensure it is running. First, run the `plan.sh` script inside the Terraform | ||
| folder. This is where any you will be alerted of any misconfigured or missing variables. If script says "Plan: 125 to | ||
| add, 0 to change, 0 to destroy." without returning any errors, run the next script `build.sh`. If you do experience any | ||
| errors when running the `build.sh` script, you need to then run the `destroy.sh` script before you can attempt another | ||
| build. | ||
|
|
||
| If you experience this error, **Error: Backend configuration changed**, then run the [tf-reconfigure.sh](./tf-reconfigure.sh) | ||
| script and try to build again. | ||
|
|
||
| #### IMPORTANT: The system can take upwards of 15 to 25 minutes to fully build or destroy. | ||
|
|
||
| ### How To Tear Down The System | ||
| #### WARNING: This script destroys ALL resources, meaning all data put into the system will be unrecoverable. | ||
| To destroy the resources in the cloud, including all AWS and docker resources, run the `destroy.sh` script. | ||
| The following resources tend to take longer to destroy than their counter-parts. | ||
| - module.configure-manager-ecs.aws_internet_gateway.ig_public | ||
| - module.configure-manager-ecs.aws_cloudfront_distribution.frontend | ||
|
|
||
| This is mostly due to a bug with AWS's resource state management system. AWS believes select lambda functions are still | ||
| running, which can often leave multiple components hanging on each other waiting for the other to be destroyed. If it | ||
| seems like this might be the case, using ^c to cancel the script and rerunning it may solve the issue. | ||
|
|
This file contains hidden or 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,59 @@ | ||
| data "aws_caller_identity" "current" {} | ||
| data "aws_region" "current" {} | ||
| # TODO: Why is it saying that "bucket_namespace" is not expected here? | ||
| resource "aws_s3_bucket" "incoming_bucket" { | ||
| bucket = format("%s-%s-%s-an", var.incoming_bucket, data.aws_caller_identity.current.account_id, data.aws_region.current.region) | ||
| force_destroy = true | ||
| bucket_namespace = "account-regional" | ||
| } | ||
|
|
||
| resource "aws_s3_bucket" "staging_bucket" { | ||
| bucket = format("%s-%s-%s-an", var.staging_bucket, data.aws_caller_identity.current.account_id, data.aws_region.current.region) | ||
| force_destroy = true | ||
| bucket_namespace = "account-regional" | ||
| } | ||
|
|
||
| resource "aws_s3_bucket" "viz_bucket" { | ||
| bucket = format("%s-%s-%s-an", var.viz_bucket, data.aws_caller_identity.current.account_id, data.aws_region.current.region) | ||
| force_destroy = true | ||
| bucket_namespace = "account-regional" | ||
| } | ||
|
|
||
| resource "aws_s3_bucket" "static_bucket" { | ||
| bucket = format("%s-%s-%s-an", var.static_bucket, data.aws_caller_identity.current.account_id, data.aws_region.current.region) | ||
| force_destroy = true | ||
| bucket_namespace = "account-regional" | ||
| } | ||
|
|
||
| data "aws_iam_policy_document" "static_bucket_policy" { | ||
| statement { | ||
| actions = ["s3:GetObject"] | ||
|
|
||
| resources = [ | ||
| "${aws_s3_bucket.static_bucket.arn}/static/*" | ||
| ] | ||
|
|
||
| principals { | ||
| type = "AWS" | ||
| identifiers = [var.oai_iam_arn] | ||
| } | ||
| } | ||
| } | ||
|
|
||
| resource "aws_s3_bucket_policy" "static" { | ||
| bucket = aws_s3_bucket.static_bucket.id | ||
| policy = data.aws_iam_policy_document.static_bucket_policy.json | ||
| } | ||
|
|
||
| resource "aws_s3_bucket_cors_configuration" "static_files" { | ||
| bucket = aws_s3_bucket.static_bucket.id | ||
|
|
||
| cors_rule { | ||
| allowed_methods = ["GET", "HEAD"] | ||
| allowed_origins = [var.alb_url] | ||
| allowed_headers = ["*"] | ||
| max_age_seconds = 3000 | ||
| } | ||
| depends_on = [aws_s3_bucket.static_bucket] | ||
| } | ||
|
|
34 changes: 34 additions & 0 deletions
34
wibl-python/scripts/cloud/AWS/Terraform/buckets/outputs.tf
This file contains hidden or 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,34 @@ | ||
| output "incoming_bucket_arn" { | ||
| value = aws_s3_bucket.incoming_bucket.arn | ||
| } | ||
|
|
||
| output "incoming_bucket_id" { | ||
| value = aws_s3_bucket.incoming_bucket.id | ||
| } | ||
| output "staging_bucket_arn" { | ||
| value = aws_s3_bucket.staging_bucket.arn | ||
| } | ||
|
|
||
| output "viz_bucket_arn" { | ||
| value = aws_s3_bucket.viz_bucket.arn | ||
| } | ||
|
|
||
| output "static_bucket_regional_dns_name" { | ||
| value = aws_s3_bucket.static_bucket.bucket_regional_domain_name | ||
| } | ||
|
|
||
| output "incoming_bucket_full_name" { | ||
| value = aws_s3_bucket.incoming_bucket.bucket | ||
| } | ||
|
|
||
| output "staging_bucket_full_name" { | ||
| value = aws_s3_bucket.staging_bucket.bucket | ||
| } | ||
|
|
||
| output "static_bucket_full_name" { | ||
| value = aws_s3_bucket.static_bucket.bucket | ||
| } | ||
|
|
||
| output "viz_bucket_full_name" { | ||
| value = aws_s3_bucket.viz_bucket.bucket | ||
| } |
28 changes: 28 additions & 0 deletions
28
wibl-python/scripts/cloud/AWS/Terraform/buckets/variables.tf
This file contains hidden or 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,28 @@ | ||
| variable "incoming_bucket" { | ||
| description = "Name of the incoming s3 bucket" | ||
| type = string | ||
| } | ||
|
|
||
| variable "staging_bucket" { | ||
| description = "Name of the staging s3 bucket" | ||
| type = string | ||
| } | ||
|
|
||
| variable "viz_bucket" { | ||
| description = "Name of the viz s3 bucket" | ||
| type = string | ||
| } | ||
|
|
||
| variable "static_bucket" { | ||
| description = "Name of the static bucket" | ||
| type = string | ||
| } | ||
|
|
||
| variable "alb_url" { | ||
| description = "Frontend cloudfront distribution url" | ||
| type = string | ||
| } | ||
|
|
||
| variable "oai_iam_arn" { | ||
| type = string | ||
| } |
This file contains hidden or 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,7 @@ | ||
| #!/bin/bash | ||
|
|
||
| WIBL_BUILD_LOCATION=$(git rev-parse --show-toplevel)/wibl-python/awsbuild | ||
| ACCOUNT_NUMBER=$(aws sts get-caller-identity --query Account --output text) | ||
| SRC_PATH=$(git rev-parse --show-toplevel)/wibl-python | ||
| TF_LOG=DEBUG | ||
| terraform init -backend-config=backend.hcl && terraform apply -auto-approve -var="src_path=${SRC_PATH}" -var="wibl_build_path=${WIBL_BUILD_LOCATION}" -var="account_number=${ACCOUNT_NUMBER}" |
This file contains hidden or 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,6 @@ | ||
| #!/bin/bash | ||
|
|
||
| WIBL_BUILD_LOCATION=$(git rev-parse --show-toplevel)/wibl-python/awsbuild | ||
| ACCOUNT_NUMBER=$(aws sts get-caller-identity --query Account --output text) | ||
| SRC_PATH=$(git rev-parse --show-toplevel)/wibl-python | ||
| terraform destroy -auto-approve -var="wibl_build_path=${WIBL_BUILD_LOCATION}" -var="src_path=${SRC_PATH}" -var="account_number=${ACCOUNT_NUMBER}" |
This file contains hidden or 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 @@ | ||
| dd if=/dev/random bs=4096 count=1 status=none | sha512sum --quiet |
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.
Uh oh!
There was an error while loading. Please reload this page.