resource "snowflake_storage_integration" "kafka_data_highway_integration" {
  name             = "${var.environment}-${var.application_family}-s3-integration"
  storage_provider = "S3"

  storage_allowed_locations = ["s3://${data.aws_s3_bucket.dev_asset_storage.bucket}/"]

  storage_aws_role_arn = "arn:aws:iam::${data.aws_caller_identity.current.account_id}:role/${var.environment}-${var.application_family}-snowflake-integration-role"
}

resource "snowflake_stage" "kafka_data_highway_stage" {
  name                = "${var.environment}-${var.application_family}-s3-stage"
  url                 = "s3://${data.aws_s3_bucket.dev_asset_storage.bucket}/"
  database            = var.stage_snowflake_database
  schema              = var.stage_snowflake_schema
  storage_integration = snowflake_storage_integration.kafka_data_highway_integration.name
}

module "kafka_data_highway_stage_access" {
  source = "git@github.com:theorchard/terraform-snowflake.git//modules/roles/stage_access?ref=7.7.4"

  database = snowflake_stage.kafka_data_highway_stage.database
  schema   = snowflake_stage.kafka_data_highway_stage.schema
  stage    = snowflake_stage.kafka_data_highway_stage.name
}

