Google Cloud AlloyDB Operators

The AlloyDB for PostgreSQL is a fully managed, PostgreSQL-compatible database service that’s designed for your most demanding workloads, including hybrid transactional and analytical processing. AlloyDB pairs a Google-built database engine with a cloud-based, multi-node architecture to deliver enterprise-grade performance, reliability, and availability.

Airflow provides operators to manage AlloyDB clusters.

Prerequisite Tasks

To use these operators, you must do a few things:

Create cluster

To create an AlloyDB cluster (primary end secondary) you can use AlloyDBCreateClusterOperator.

google/tests/system/google/cloud/alloy_db/example_alloy_db.py[source]

create_cluster = AlloyDBCreateClusterOperator(
    task_id="create_cluster",
    cluster_id=CLUSTER_ID,
    cluster_configuration=CLUSTER,
    is_secondary=False,
    location=GCP_LOCATION,
    project_id=GCP_PROJECT_ID,
)

Update cluster

To update an AlloyDB cluster you can use AlloyDBUpdateClusterOperator.

google/tests/system/google/cloud/alloy_db/example_alloy_db.py[source]

update_cluster = AlloyDBUpdateClusterOperator(
    task_id="update_cluster",
    cluster_id=CLUSTER_ID,
    cluster_configuration=CLUSTER_UPDATE,
    update_mask=CLUSTER_UPDATE_MASK,
    location=GCP_LOCATION,
    project_id=GCP_PROJECT_ID,
)

Delete cluster

To delete an AlloyDB cluster you can use AlloyDBDeleteClusterOperator.

google/tests/system/google/cloud/alloy_db/example_alloy_db.py[source]

delete_cluster = AlloyDBDeleteClusterOperator(
    task_id="delete_cluster",
    project_id=GCP_PROJECT_ID,
    location=GCP_LOCATION,
    cluster_id=CLUSTER_ID,
)

Create instance

To create an AlloyDB instance (primary end secondary) you can use AlloyDBCreateInstanceOperator.

google/tests/system/google/cloud/alloy_db/example_alloy_db.py[source]

create_instance = AlloyDBCreateInstanceOperator(
    task_id="create_instance",
    cluster_id=CLUSTER_ID,
    instance_id=INSTANCE_ID,
    instance_configuration=INSTANCE,
    is_secondary=False,
    project_id=GCP_PROJECT_ID,
    location=GCP_LOCATION,
)

Update instance

To update an AlloyDB instance you can use AlloyDBUpdateInstanceOperator.

google/tests/system/google/cloud/alloy_db/example_alloy_db.py[source]

update_instance = AlloyDBUpdateInstanceOperator(
    task_id="update_instance",
    cluster_id=CLUSTER_ID,
    instance_id=INSTANCE_ID,
    instance_configuration=INSTANCE_UPDATE,
    update_mask=INSTANCE_UPDATE_MASK,
    location=GCP_LOCATION,
    project_id=GCP_PROJECT_ID,
)

Delete instance

To delete an AlloyDB instance you can use AlloyDBDeleteInstanceOperator.

google/tests/system/google/cloud/alloy_db/example_alloy_db.py[source]

delete_instance = AlloyDBDeleteInstanceOperator(
    task_id="delete_instance",
    cluster_id=CLUSTER_ID,
    instance_id=INSTANCE_ID,
    project_id=GCP_PROJECT_ID,
    location=GCP_LOCATION,
)

Create user

To create an AlloyDB user you can use AlloyDBCreateUserOperator. Note that the primary instance must be created in the cluster

google/tests/system/google/cloud/alloy_db/example_alloy_db.py[source]

creat_user = AlloyDBCreateUserOperator(
    task_id="create_user",
    user_id=USER_ID,
    user_configuration=USER,
    cluster_id=CLUSTER_ID,
    project_id=GCP_PROJECT_ID,
    location=GCP_LOCATION,
)

Update user

To update an AlloyDB user you can use AlloyDBUpdateUserOperator.

google/tests/system/google/cloud/alloy_db/example_alloy_db.py[source]

update_user = AlloyDBUpdateUserOperator(
    task_id="update_user",
    user_id=USER_ID,
    user_configuration=USER_UPDATE,
    cluster_id=CLUSTER_ID,
    update_mask=USER_UPDATE_MASK,
    location=GCP_LOCATION,
    project_id=GCP_PROJECT_ID,
)

Delete user

To delete an AlloyDB user you can use AlloyDBDeleteUserOperator.

google/tests/system/google/cloud/alloy_db/example_alloy_db.py[source]

delete_user = AlloyDBDeleteUserOperator(
    task_id="delete_user",
    cluster_id=CLUSTER_ID,
    user_id=USER_ID,
    project_id=GCP_PROJECT_ID,
    location=GCP_LOCATION,
)

Create backup

To create an AlloyDB backup you can use AlloyDBCreateBackupOperator.

google/tests/system/google/cloud/alloy_db/example_alloy_db.py[source]

create_backup = AlloyDBCreateBackupOperator(
    task_id="create_backup",
    backup_id=BACKUP_ID,
    backup_configuration=BACKUP,
    location=GCP_LOCATION_BACKUP,
    project_id=GCP_PROJECT_ID,
)

Update backup

To update an AlloyDB backup you can use AlloyDBUpdateBackupOperator.

google/tests/system/google/cloud/alloy_db/example_alloy_db.py[source]

update_backup = AlloyDBUpdateBackupOperator(
    task_id="update_backup",
    backup_id=BACKUP_ID,
    backup_configuration=BACKUP_UPDATE,
    update_mask=BACKUP_UPDATE_MASK,
    location=GCP_LOCATION_BACKUP,
    project_id=GCP_PROJECT_ID,
)

Delete backup

To delete an AlloyDB backup you can use AlloyDBDeleteBackupOperator.

google/tests/system/google/cloud/alloy_db/example_alloy_db.py[source]

delete_backup = AlloyDBDeleteBackupOperator(
    task_id="delete_backup",
    backup_id=BACKUP_ID,
    location=GCP_LOCATION_BACKUP,
    project_id=GCP_PROJECT_ID,
)

Was this entry helpful?