-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from cristian-rincon/feature/initial-scaffolding
Feature/initial scaffolding
- Loading branch information
Showing
16 changed files
with
559 additions
and
1 deletion.
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,5 @@ | ||
### Changelog | ||
|
||
All notable changes to this project will be documented in this file. Dates are displayed in UTC. | ||
|
||
Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog). |
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 +1,65 @@ | ||
# latam-challenge | ||
# latam-challenge | ||
|
||
## Setup | ||
|
||
Apis to be enabled: | ||
|
||
- Billing API | ||
- Cloud Functions API | ||
- Pub/Sub API | ||
- Bigquery API | ||
- IAM API | ||
|
||
## 1. Deploy infrastructure | ||
|
||
### 1.1 Initialization | ||
|
||
> **Constraint:** tested using Terraform v1.8.1 | ||
```bash | ||
cd infra | ||
terraform init | ||
``` | ||
|
||
Create a new file called terraform.tfvars with the following information: | ||
|
||
```md | ||
project_id=<YOUR_GCP_PROJECT_ID> | ||
region=<YOUR_GCP_REGION> | ||
``` | ||
|
||
### 1.2 Plan | ||
|
||
```bash | ||
terraform plan -var-file=terraform.tfvars | ||
``` | ||
|
||
### 1.3 Apply | ||
|
||
```bash | ||
terraform apply -var-file=terraform.tfvars | ||
``` | ||
|
||
## 2. Test the deployed infrastructure | ||
|
||
### 2.1 Ingest data | ||
|
||
```bash | ||
curl -m 310 -X POST https://<fn_ingest_data_url> \ | ||
-H "Authorization: bearer $(gcloud auth print-identity-token)" -H "Content-Type: application/json" \ | ||
-d '{ | ||
"product_id": "45678", | ||
"product_name": "Laptop 2", | ||
"category": "Electronics", | ||
"unit_price": 999.99, | ||
"supplier": "TechSupplier Inc." | ||
}' | ||
``` | ||
|
||
### 2.2 Query data | ||
|
||
```bash | ||
curl -m 310 -X POST https://<fn_fetch_data_url> \ | ||
-H "Authorization: bearer $(gcloud auth print-identity-token)" -H "Content-Type: application/json" \ | ||
-d '{}' | ||
``` |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,55 @@ | ||
## Requirements | ||
|
||
| Name | Version | | ||
|------|---------| | ||
| <a name="requirement_google"></a> [google](#requirement\_google) | 6.2.0 | | ||
|
||
## Providers | ||
|
||
| Name | Version | | ||
|------|---------| | ||
| <a name="provider_archive"></a> [archive](#provider\_archive) | 2.6.0 | | ||
| <a name="provider_google"></a> [google](#provider\_google) | 6.2.0 | | ||
|
||
## Modules | ||
|
||
No modules. | ||
|
||
## Resources | ||
|
||
| Name | Type | | ||
|------|------| | ||
| [google_bigquery_dataset.ecommerce_analytics](https://registry.terraform.io/providers/hashicorp/google/6.2.0/docs/resources/bigquery_dataset) | resource | | ||
| [google_bigquery_table.product_sales_table](https://registry.terraform.io/providers/hashicorp/google/6.2.0/docs/resources/bigquery_table) | resource | | ||
| [google_cloudfunctions2_function.fn_fetch_data](https://registry.terraform.io/providers/hashicorp/google/6.2.0/docs/resources/cloudfunctions2_function) | resource | | ||
| [google_cloudfunctions2_function.fn_ingest_data](https://registry.terraform.io/providers/hashicorp/google/6.2.0/docs/resources/cloudfunctions2_function) | resource | | ||
| [google_project_iam_member.data_engineering_bigquery_data_editor](https://registry.terraform.io/providers/hashicorp/google/6.2.0/docs/resources/project_iam_member) | resource | | ||
| [google_project_iam_member.data_engineering_bigquery_user](https://registry.terraform.io/providers/hashicorp/google/6.2.0/docs/resources/project_iam_member) | resource | | ||
| [google_project_iam_member.data_engineering_cloudfunctions](https://registry.terraform.io/providers/hashicorp/google/6.2.0/docs/resources/project_iam_member) | resource | | ||
| [google_project_iam_member.data_engineering_pubsub](https://registry.terraform.io/providers/hashicorp/google/6.2.0/docs/resources/project_iam_member) | resource | | ||
| [google_pubsub_subscription.product_sales_subscription](https://registry.terraform.io/providers/hashicorp/google/6.2.0/docs/resources/pubsub_subscription) | resource | | ||
| [google_pubsub_topic.product_sales_topic](https://registry.terraform.io/providers/hashicorp/google/6.2.0/docs/resources/pubsub_topic) | resource | | ||
| [google_service_account.data_engineering](https://registry.terraform.io/providers/hashicorp/google/6.2.0/docs/resources/service_account) | resource | | ||
| [google_storage_bucket.staging_bucket](https://registry.terraform.io/providers/hashicorp/google/6.2.0/docs/resources/storage_bucket) | resource | | ||
| [google_storage_bucket_object.fetch_data_source_object](https://registry.terraform.io/providers/hashicorp/google/6.2.0/docs/resources/storage_bucket_object) | resource | | ||
| [google_storage_bucket_object.ingest_data_source_object](https://registry.terraform.io/providers/hashicorp/google/6.2.0/docs/resources/storage_bucket_object) | resource | | ||
| [archive_file.fetch_data_source_code_archive](https://registry.terraform.io/providers/hashicorp/archive/latest/docs/data-sources/file) | data source | | ||
| [archive_file.ingestion_source_code_archive](https://registry.terraform.io/providers/hashicorp/archive/latest/docs/data-sources/file) | data source | | ||
|
||
## Inputs | ||
|
||
| Name | Description | Type | Default | Required | | ||
|------|-------------|------|---------|:--------:| | ||
| <a name="input_environment"></a> [environment](#input\_environment) | The environment | `string` | n/a | yes | | ||
| <a name="input_project_id"></a> [project\_id](#input\_project\_id) | The project ID | `string` | n/a | yes | | ||
| <a name="input_region"></a> [region](#input\_region) | The region | `string` | n/a | yes | | ||
|
||
## Outputs | ||
|
||
| Name | Description | | ||
|------|-------------| | ||
| <a name="output_ecommerce_analytics_dataset_id"></a> [ecommerce\_analytics\_dataset\_id](#output\_ecommerce\_analytics\_dataset\_id) | n/a | | ||
| <a name="output_fn_ingest_data_url"></a> [fn\_ingest\_data\_url](#output\_fn\_ingest\_data\_url) | n/a | | ||
| <a name="output_product_sales_subscription_name"></a> [product\_sales\_subscription\_name](#output\_product\_sales\_subscription\_name) | n/a | | ||
| <a name="output_product_sales_table_id"></a> [product\_sales\_table\_id](#output\_product\_sales\_table\_id) | n/a | | ||
| <a name="output_product_sales_topic_name"></a> [product\_sales\_topic\_name](#output\_product\_sales\_topic\_name) | n/a | |
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,57 @@ | ||
// Bigquery dataset "ecommerce_analytics" | ||
resource "google_bigquery_dataset" "ecommerce_analytics" { | ||
dataset_id = "ecommerce_analytics" | ||
project = var.project_id | ||
location = var.region | ||
default_table_expiration_ms = "2592000000" # 30 days in milliseconds | ||
labels = { | ||
env = var.environment | ||
} | ||
} | ||
|
||
# Bigquery table "ecommerce_analytics.sales" | ||
resource "google_bigquery_table" "product_sales_table" { | ||
dataset_id = google_bigquery_dataset.ecommerce_analytics.dataset_id | ||
table_id = "product_sales" | ||
deletion_protection = true | ||
time_partitioning { | ||
type = "DAY" | ||
} | ||
|
||
// Bigquery table schema | ||
// product_id: STRING | ||
// product_name: STRING | ||
// category: STRING | ||
// unit_price: FLOAT | ||
// supplier: STRING | ||
|
||
schema = <<EOF | ||
[ | ||
{ | ||
"name": "product_id", | ||
"type": "STRING", | ||
"mode": "REQUIRED" | ||
}, | ||
{ | ||
"name": "product_name", | ||
"type": "STRING", | ||
"mode": "REQUIRED" | ||
}, | ||
{ | ||
"name": "category", | ||
"type": "STRING", | ||
"mode": "REQUIRED" | ||
}, | ||
{ | ||
"name": "unit_price", | ||
"type": "FLOAT", | ||
"mode": "REQUIRED" | ||
}, | ||
{ | ||
"name": "supplier", | ||
"type": "STRING", | ||
"mode": "REQUIRED" | ||
} | ||
] | ||
EOF | ||
} |
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 @@ | ||
// Service account for the resources | ||
resource "google_service_account" "data_engineering" { | ||
account_id = "data-engineering" | ||
display_name = "Data Engineering Service Account" | ||
project = var.project_id | ||
} | ||
|
||
// Grant the service account the necessary roles to use pub/sub, cloud functions and bigquery | ||
resource "google_project_iam_member" "data_engineering_pubsub" { | ||
project = var.project_id | ||
role = "roles/pubsub.editor" | ||
member = "serviceAccount:${google_service_account.data_engineering.email}" | ||
} | ||
|
||
resource "google_project_iam_member" "data_engineering_bigquery_user" { | ||
project = var.project_id | ||
role = "roles/bigquery.user" | ||
member = "serviceAccount:${google_service_account.data_engineering.email}" | ||
} | ||
resource "google_project_iam_member" "data_engineering_bigquery_data_editor" { | ||
project = var.project_id | ||
role = "roles/bigquery.dataEditor" | ||
member = "serviceAccount:${google_service_account.data_engineering.email}" | ||
} | ||
|
||
resource "google_project_iam_member" "data_engineering_cloudfunctions" { | ||
project = var.project_id | ||
role = "roles/cloudfunctions.developer" | ||
member = "serviceAccount:${google_service_account.data_engineering.email}" | ||
} | ||
|
Oops, something went wrong.