|
| 1 | +#!/bin/bash |
| 2 | +set -e |
| 3 | + |
| 4 | +# Configuration |
| 5 | +# Replace these values with your actual project and location |
| 6 | +PROJECT_ID="${PROJECT_ID:-YOUR_PROJECT_ID}" |
| 7 | +LOCATION="${LOCATION:-us-central1}" |
| 8 | +ENTRY_GROUP_ID="${ENTRY_GROUP_ID:-aws-glue-entries}" |
| 9 | + |
| 10 | +echo "Using Project: $PROJECT_ID" |
| 11 | +echo "Using Location: $LOCATION" |
| 12 | +echo "Target Entry Group: $ENTRY_GROUP_ID" |
| 13 | + |
| 14 | +# 1. Create Entry Group |
| 15 | +echo "----------------------------------------------------------------" |
| 16 | +echo "Creating Entry Group: $ENTRY_GROUP_ID..." |
| 17 | +gcloud dataplex entry-groups create "$ENTRY_GROUP_ID" \ |
| 18 | + --project="$PROJECT_ID" \ |
| 19 | + --location="$LOCATION" \ |
| 20 | + --description="Entry group for AWS Glue metadata" || echo "Entry Group might already exist." |
| 21 | + |
| 22 | +# 2. Create Entry Types |
| 23 | +ENTRY_TYPES=("aws-glue-database" "aws-glue-table" "aws-glue-view") |
| 24 | + |
| 25 | +for TYPE in "${ENTRY_TYPES[@]}"; do |
| 26 | + echo "----------------------------------------------------------------" |
| 27 | + echo "Creating Entry Type: $TYPE..." |
| 28 | + gcloud dataplex entry-types create "$TYPE" \ |
| 29 | + --project="$PROJECT_ID" \ |
| 30 | + --location="$LOCATION" \ |
| 31 | + --description="Entry type for $TYPE" || echo "Entry Type $TYPE might already exist." |
| 32 | +done |
| 33 | + |
| 34 | +# 3. Create Aspect Types |
| 35 | +echo "----------------------------------------------------------------" |
| 36 | +echo "Creating Aspect Types..." |
| 37 | + |
| 38 | +# 3a. Marker Aspect Types (Database, Table, View) |
| 39 | +# We define a minimal schema for these markers since they are primarily used for identification. |
| 40 | +# Marker schema definition moved into loop below |
| 41 | + |
| 42 | +MARKER_ASPECTS=("aws-glue-database" "aws-glue-table" "aws-glue-view") |
| 43 | + |
| 44 | +for ASPECT in "${MARKER_ASPECTS[@]}"; do |
| 45 | + echo "Creating Aspect Type: $ASPECT..." |
| 46 | + cat > "${ASPECT}.yaml" <<EOF |
| 47 | +name: "$ASPECT" |
| 48 | +type: record |
| 49 | +recordFields: |
| 50 | + - name: description |
| 51 | + type: string |
| 52 | + index: 1 |
| 53 | + annotations: |
| 54 | + description: "Optional description for this marker." |
| 55 | + constraints: |
| 56 | + required: false |
| 57 | +EOF |
| 58 | + gcloud dataplex aspect-types create "$ASPECT" \ |
| 59 | + --project="$PROJECT_ID" \ |
| 60 | + --location="$LOCATION" \ |
| 61 | + --metadata-template-file-name="${ASPECT}.yaml" || echo "Aspect Type $ASPECT might already exist." |
| 62 | + rm "${ASPECT}.yaml" |
| 63 | +done |
| 64 | + |
| 65 | +# 3b. Lineage Aspect Type |
| 66 | +# Defines the schema for lineage links (source -> target) |
| 67 | +cat > lineage_aspect.yaml <<EOF |
| 68 | +name: "aws-lineage-aspect" |
| 69 | +type: record |
| 70 | +recordFields: |
| 71 | + - name: links |
| 72 | + type: array |
| 73 | + index: 1 |
| 74 | + annotations: |
| 75 | + description: "List of lineage links." |
| 76 | + arrayItems: |
| 77 | + name: "link" |
| 78 | + type: record |
| 79 | + recordFields: |
| 80 | + - name: source |
| 81 | + type: record |
| 82 | + index: 1 |
| 83 | + annotations: |
| 84 | + description: "Source entity in the lineage relationship." |
| 85 | + recordFields: |
| 86 | + - name: fully_qualified_name |
| 87 | + type: string |
| 88 | + index: 1 |
| 89 | + annotations: |
| 90 | + description: "FQN of the source entity." |
| 91 | + - name: target |
| 92 | + type: record |
| 93 | + index: 2 |
| 94 | + annotations: |
| 95 | + description: "Target entity in the lineage relationship." |
| 96 | + recordFields: |
| 97 | + - name: fully_qualified_name |
| 98 | + type: string |
| 99 | + index: 1 |
| 100 | + annotations: |
| 101 | + description: "FQN of the target entity." |
| 102 | +EOF |
| 103 | + |
| 104 | +echo "Creating Aspect Type: aws-lineage-aspect..." |
| 105 | +gcloud dataplex aspect-types create "aws-lineage-aspect" \ |
| 106 | + --project="$PROJECT_ID" \ |
| 107 | + --location="$LOCATION" \ |
| 108 | + --metadata-template-file-name=lineage_aspect.yaml || echo "Aspect Type aws-lineage-aspect might already exist." |
| 109 | + |
| 110 | +# Clean up temporary files |
| 111 | +rm lineage_aspect.yaml |
| 112 | + |
| 113 | +echo "----------------------------------------------------------------" |
| 114 | +echo "Setup complete. Please verify resources in the Google Cloud Console." |
0 commit comments