From 05adc85ad4f4eed8f8a67c432592d1ccc1f19819 Mon Sep 17 00:00:00 2001 From: Justin Rich Date: Wed, 13 Mar 2024 12:05:47 -0700 Subject: [PATCH 1/2] add new example --- Examples/database_onboarding/README.md | 8 + Examples/database_onboarding/main.tf | 197 ++++++++++++++++++++++ Examples/database_onboarding/variables.tf | 23 +++ Examples/database_onboarding/versions.tf | 15 ++ 4 files changed, 243 insertions(+) create mode 100644 Examples/database_onboarding/README.md create mode 100644 Examples/database_onboarding/main.tf create mode 100644 Examples/database_onboarding/variables.tf create mode 100644 Examples/database_onboarding/versions.tf diff --git a/Examples/database_onboarding/README.md b/Examples/database_onboarding/README.md new file mode 100644 index 0000000..c43b3ac --- /dev/null +++ b/Examples/database_onboarding/README.md @@ -0,0 +1,8 @@ +# Database Onboarding + +This terraform takes a few simple parameters and then does the following + +1. Create Postgres RDS DB +1. Inject sample data and install masking +1. Configure the data repo and access rules +1. Configure mapping and masking policy \ No newline at end of file diff --git a/Examples/database_onboarding/main.tf b/Examples/database_onboarding/main.tf new file mode 100644 index 0000000..20971e5 --- /dev/null +++ b/Examples/database_onboarding/main.tf @@ -0,0 +1,197 @@ +provider "cyral" { + client_id = var.cyral_client_id + client_secret = var.cyral_client_secret + control_plane = var.cyral_control_plane +} + +locals { + db_name = "test_data" + sidecar_name = var.sidecar_name + idp_name = "Okta-Sales" + repo_name = "jr-tf-repo" + + pg_listener_port = 5435 + pg_listener_id = cyral_sidecar_listener.pg.id + db_login_name = "postgres" + + sidecar_host = var.sidecar_host + + database_credentials = { + username = "postgres" + password = random_password.db_password.result + } +} + +# Get existing Sidecar +data "cyral_sidecar_id" "this" { + sidecar_name = local.sidecar_name +} + +# Get existing Okta integration +data "cyral_integration_idp" "okta" { + display_name = local.idp_name +} + +# Generate password for database +resource "random_password" "db_password" { + length = 16 + special = true + override_special = "_%!" +} + + +# Build PG RDS Instance +resource "aws_db_instance" "postgres" { + identifier = local.repo_name + instance_class = "db.t3.micro" + engine = "postgres" + allocated_storage = 20 + storage_type = "gp2" + username = local.database_credentials.username + password = random_password.db_password.result + db_name = local.db_name + backup_retention_period = 0 + skip_final_snapshot = true +} + +# Install masking and inject data +resource "null_resource" "init_db" { + depends_on = [aws_db_instance.postgres, cyral_repository_binding.pg, cyral_repository_conf_auth.pg, cyral_repository_conf_analysis.this] + + provisioner "local-exec" { + command = < Date: Wed, 13 Mar 2024 13:35:51 -0700 Subject: [PATCH 2/2] use more generic name --- Examples/database_onboarding/main.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Examples/database_onboarding/main.tf b/Examples/database_onboarding/main.tf index 20971e5..ae6c254 100644 --- a/Examples/database_onboarding/main.tf +++ b/Examples/database_onboarding/main.tf @@ -8,7 +8,7 @@ locals { db_name = "test_data" sidecar_name = var.sidecar_name idp_name = "Okta-Sales" - repo_name = "jr-tf-repo" + repo_name = "example-tf-repo" pg_listener_port = 5435 pg_listener_id = cyral_sidecar_listener.pg.id