From c91c1c85a75ab3de3f77ae0ac48ce92bf4211c83 Mon Sep 17 00:00:00 2001 From: HarshCasper Date: Sun, 25 May 2025 13:03:07 +0530 Subject: [PATCH 1/3] add terraform iac integration --- .gitignore | 5 +++ terraform/main.tf | 99 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 104 insertions(+) create mode 100644 terraform/main.tf diff --git a/.gitignore b/.gitignore index 489fc0d..0c209fe 100644 --- a/.gitignore +++ b/.gitignore @@ -20,3 +20,8 @@ __pycache__ # Native App app/output/ + +# Terraform +.terraform/ +.terraform.lock.hcl +terraform.tfstate diff --git a/terraform/main.tf b/terraform/main.tf new file mode 100644 index 0000000..59fd0c9 --- /dev/null +++ b/terraform/main.tf @@ -0,0 +1,99 @@ +terraform { + required_providers { + snowflake = { + source = "snowflakedb/snowflake" + version = ">= 1.0.0" + } + } +} + +provider "snowflake" { + organization_name = "test" + account_name = "test" + user = "test" + password = "test" + role = "test" + host = "snowflake.localhost.localstack.cloud" + port = "4566" +} + +# Create the factory pipeline database +resource "snowflake_database" "factory_pipeline_demo" { + name = "FACTORY_PIPELINE_DEMO" + comment = "Factory pipeline demo database" + data_retention_time_in_days = 3 +} + +# Create the public schema +resource "snowflake_schema" "public" { + database = snowflake_database.factory_pipeline_demo.name + name = "PUBLIC" + comment = "Public schema for factory pipeline demo" + with_managed_access = false +} + +# Create the raw sensor data table +resource "snowflake_table" "raw_sensor_data" { + database = snowflake_database.factory_pipeline_demo.name + schema = snowflake_schema.public.name + name = "RAW_SENSOR_DATA" + comment = "Raw sensor data from factory machines" + column { + name = "machine_id" + type = "VARCHAR(50)" + } + column { + name = "timestamp" + type = "TIMESTAMP_NTZ" + } + column { + name = "temperature" + type = "FLOAT" + } + column { + name = "vibration" + type = "FLOAT" + } + column { + name = "pressure" + type = "FLOAT" + } + column { + name = "status_code" + type = "VARCHAR(10)" + } +} + +# Create CSV file format +resource "snowflake_file_format" "csv_format" { + database = snowflake_database.factory_pipeline_demo.name + schema = snowflake_schema.public.name + name = "csv_format" + format_type = "CSV" + field_delimiter = "," + skip_header = 1 + null_if = ["NULL", "null"] + empty_field_as_null = true + comment = "CSV file format for sensor data ingestion" +} + +# Create S3 stage for sensor data +resource "snowflake_stage" "sensor_data_stage" { + database = snowflake_database.factory_pipeline_demo.name + schema = snowflake_schema.public.name + name = "sensor_data_stage" + url = "s3://factory-sensor-data-local/raw_data/" + credentials = "AWS_KEY_ID='test' AWS_SECRET_KEY='test'" + file_format = "DATABASE=${snowflake_database.factory_pipeline_demo.name}.SCHEMA=${snowflake_schema.public.name}.${snowflake_file_format.csv_format.name}" + comment = "S3 stage for factory sensor data files" +} + +# Create Snowpipe for automated ingestion +resource "snowflake_pipe" "sensor_data_pipe" { + database = snowflake_database.factory_pipeline_demo.name + schema = snowflake_schema.public.name + name = "sensor_data_pipe" + copy_statement = "COPY INTO ${snowflake_database.factory_pipeline_demo.name}.${snowflake_schema.public.name}.${snowflake_table.raw_sensor_data.name} FROM @${snowflake_stage.sensor_data_stage.name} PATTERN='.*[.]csv' ON_ERROR = 'CONTINUE'" + auto_ingest = true + comment = "Automated pipe for ingesting sensor data from S3" +} From b3cbad1b773fddefd2b4c3da4a0e34616f804c27 Mon Sep 17 00:00:00 2001 From: Harsh Mishra Date: Mon, 7 Jul 2025 16:21:50 +0530 Subject: [PATCH 2/3] Update ci.yml --- .github/workflows/ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d3023ca..104b325 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -59,6 +59,7 @@ jobs: - name: Install dependencies run: | make install + dbt debug --profiles-dir . --profile localstack - name: Create Snowflake resources run: | From 3a580e7c8e2d3f9cd36fb17b4ed7685e3c01c176 Mon Sep 17 00:00:00 2001 From: Harsh Mishra Date: Mon, 7 Jul 2025 16:27:50 +0530 Subject: [PATCH 3/3] Update ci.yml --- .github/workflows/ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 473132a..7fb5f45 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -59,6 +59,7 @@ jobs: - name: Install dependencies run: | make install + source env/bin/activate dbt debug --profiles-dir . --profile localstack - name: Create Snowflake resources