Skip to content
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

add triggers for re-generate sql files and re-install poetry #48

Merged
merged 15 commits into from
Oct 6, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 37 additions & 14 deletions infrastructure/terraform/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,17 @@ locals {
config_file_name = "config"
poetry_run_alias = "${var.poetry_cmd} run"
mds_dataset_suffix = var.create_prod_environment ? "prod" : var.create_dev_environment ? "dev" : "staging"

project_toml_file_path = "${local.source_root_dir}/pyproject.toml"
project_toml_content_hash = filesha512(local.project_toml_file_path)

generated_sql_queries_directory_path = "${local.source_root_dir}/sql/query"
generated_sql_queries_fileset = [for f in fileset(local.generated_sql_queries_directory_path, "*.sql") : "${local.generated_sql_queries_directory_path}/${f}"]
generated_sql_queries_content_hash = sha512(join("", [for f in local.generated_sql_queries_fileset : fileexists(f) ? filesha512(f) : sha512("file-not-found")]))

generated_sql_procedures_directory_path = "${local.source_root_dir}/sql/procedure"
generated_sql_procedures_fileset = [for f in fileset(local.generated_sql_procedures_directory_path, "*.sql") : "${local.generated_sql_procedures_directory_path}/${f}"]
generated_sql_procedures_content_hash = sha512(join("", [for f in local.generated_sql_procedures_fileset : fileexists(f) ? filesha512(f) : sha512("file-not-found")]))
}

resource "local_file" "feature_store_configuration" {
Expand All @@ -75,39 +86,51 @@ resource "local_file" "feature_store_configuration" {
}

resource "null_resource" "poetry_install" {
triggers = {
create_command = "${var.poetry_cmd} install"
source_contents_hash = local.project_toml_content_hash
}

provisioner "local-exec" {
command = "${var.poetry_cmd} install"
when = create
command = self.triggers.create_command
working_dir = local.source_root_dir
}
}

resource "null_resource" "generate_sql_queries" {

triggers = {
create_command = <<-EOT
${local.poetry_run_alias} inv apply-env-variables-queries --env-name=${local.config_file_name}
${local.poetry_run_alias} inv apply-env-variables-procedures --env-name=${local.config_file_name}
EOT

destroy_command = <<-EOT
rm -f sql/query/*.sql
rm -f sql/procedure/*.sql
EOT

working_dir = local.source_root_dir

poetry_installed = null_resource.poetry_install.id

source_contents_hash = local_file.feature_store_configuration.content_sha512
destination_queries_hash = local.generated_sql_queries_content_hash
destination_procedures_hash = local.generated_sql_procedures_content_hash
}

provisioner "local-exec" {
command = <<-EOT
${local.poetry_run_alias} inv apply-env-variables-queries --env-name=${local.config_file_name}
${local.poetry_run_alias} inv apply-env-variables-procedures --env-name=${local.config_file_name}
EOT
when = create
command = self.triggers.create_command
working_dir = self.triggers.working_dir
}

provisioner "local-exec" {
when = destroy
command = <<-EOT
rm sql/query/*.sql
rm sql/procedure/*.sql
EOT
command = self.triggers.destroy_command
working_dir = self.triggers.working_dir
}

depends_on = [
local_file.feature_store_configuration,
null_resource.poetry_install
]
}

module "feature_store" {
Expand Down
Loading