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..ae6c254 --- /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 = "example-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 = <