Skip to content

Commit

Permalink
Add examples for AlloyDB Major Version Upgrade (hashicorp#13177) (has…
Browse files Browse the repository at this point in the history
…hicorp#21618)

[upstream:e98212e5d8fe8ac0e028a4be9b444a3dcbb6bcde]

Signed-off-by: Modular Magician <[email protected]>
  • Loading branch information
modular-magician authored Feb 26, 2025
1 parent 47a6165 commit 6b7344d
Show file tree
Hide file tree
Showing 3 changed files with 259 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .changelog/13177.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:none
alloydb: add examples for AlloyDB Major Version Upgrade for `google_alloydb_cluster` resource.
```
148 changes: 148 additions & 0 deletions google/services/alloydb/resource_alloydb_cluster_generated_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,154 @@ resource "google_compute_network" "default" {
`, context)
}

func TestAccAlloydbCluster_alloydbClusterBeforeUpgradeExample(t *testing.T) {
t.Parallel()

context := map[string]interface{}{
"random_suffix": acctest.RandString(t, 10),
}

acctest.VcrTest(t, resource.TestCase{
PreCheck: func() { acctest.AccTestPreCheck(t) },
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
CheckDestroy: testAccCheckAlloydbClusterDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccAlloydbCluster_alloydbClusterBeforeUpgradeExample(context),
},
{
ResourceName: "google_alloydb_cluster.default",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"annotations", "cluster_id", "initial_user", "labels", "location", "restore_backup_source", "restore_continuous_backup_source", "terraform_labels"},
},
},
})
}

func testAccAlloydbCluster_alloydbClusterBeforeUpgradeExample(context map[string]interface{}) string {
return acctest.Nprintf(`
resource "google_alloydb_instance" "default" {
cluster = google_alloydb_cluster.default.name
instance_id = "tf-test-alloydb-instance%{random_suffix}"
instance_type = "PRIMARY"
machine_config {
cpu_count = 2
}
depends_on = [google_service_networking_connection.vpc_connection]
}
resource "google_alloydb_cluster" "default" {
cluster_id = "tf-test-alloydb-cluster%{random_suffix}"
location = "us-central1"
network_config {
network = google_compute_network.default.id
}
database_version = "POSTGRES_14"
initial_user {
password = "tf-test-alloydb-cluster%{random_suffix}"
}
}
data "google_project" "project" {}
resource "google_compute_network" "default" {
name = "tf-test-alloydb-network%{random_suffix}"
}
resource "google_compute_global_address" "private_ip_alloc" {
name = "tf-test-alloydb-cluster%{random_suffix}"
address_type = "INTERNAL"
purpose = "VPC_PEERING"
prefix_length = 16
network = google_compute_network.default.id
}
resource "google_service_networking_connection" "vpc_connection" {
network = google_compute_network.default.id
service = "servicenetworking.googleapis.com"
reserved_peering_ranges = [google_compute_global_address.private_ip_alloc.name]
}
`, context)
}

func TestAccAlloydbCluster_alloydbClusterAfterUpgradeExample(t *testing.T) {
t.Parallel()

context := map[string]interface{}{
"random_suffix": acctest.RandString(t, 10),
}

acctest.VcrTest(t, resource.TestCase{
PreCheck: func() { acctest.AccTestPreCheck(t) },
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
CheckDestroy: testAccCheckAlloydbClusterDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccAlloydbCluster_alloydbClusterAfterUpgradeExample(context),
},
{
ResourceName: "google_alloydb_cluster.default",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"annotations", "cluster_id", "initial_user", "labels", "location", "restore_backup_source", "restore_continuous_backup_source", "terraform_labels"},
},
},
})
}

func testAccAlloydbCluster_alloydbClusterAfterUpgradeExample(context map[string]interface{}) string {
return acctest.Nprintf(`
resource "google_alloydb_instance" "default" {
cluster = google_alloydb_cluster.default.name
instance_id = "tf-test-alloydb-instance%{random_suffix}"
instance_type = "PRIMARY"
machine_config {
cpu_count = 2
}
depends_on = [google_service_networking_connection.vpc_connection]
}
resource "google_alloydb_cluster" "default" {
cluster_id = "tf-test-alloydb-cluster%{random_suffix}"
location = "us-central1"
network_config {
network = google_compute_network.default.id
}
database_version = "POSTGRES_15"
initial_user {
password = "tf-test-alloydb-cluster%{random_suffix}"
}
}
data "google_project" "project" {}
resource "google_compute_network" "default" {
name = "tf-test-alloydb-network%{random_suffix}"
}
resource "google_compute_global_address" "private_ip_alloc" {
name = "tf-test-alloydb-cluster%{random_suffix}"
address_type = "INTERNAL"
purpose = "VPC_PEERING"
prefix_length = 16
network = google_compute_network.default.id
}
resource "google_service_networking_connection" "vpc_connection" {
network = google_compute_network.default.id
service = "servicenetworking.googleapis.com"
reserved_peering_ranges = [google_compute_global_address.private_ip_alloc.name]
}
`, context)
}

func TestAccAlloydbCluster_alloydbClusterFullExample(t *testing.T) {
t.Parallel()

Expand Down
108 changes: 108 additions & 0 deletions website/docs/r/alloydb_cluster.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,114 @@ resource "google_compute_network" "default" {
name = "alloydb-cluster"
}
```
<div class = "oics-button" style="float: right; margin: 0 0 -15px">
<a href="https://console.cloud.google.com/cloudshell/open?cloudshell_git_repo=https%3A%2F%2Fgithub.com%2Fterraform-google-modules%2Fdocs-examples.git&cloudshell_image=gcr.io%2Fcloudshell-images%2Fcloudshell%3Alatest&cloudshell_print=.%2Fmotd&cloudshell_tutorial=.%2Ftutorial.md&cloudshell_working_dir=alloydb_cluster_before_upgrade&open_in_editor=main.tf" target="_blank">
<img alt="Open in Cloud Shell" src="//gstatic.com/cloudssh/images/open-btn.svg" style="max-height: 44px; margin: 32px auto; max-width: 100%;">
</a>
</div>
## Example Usage - Alloydb Cluster Before Upgrade


```hcl
resource "google_alloydb_instance" "default" {
cluster = google_alloydb_cluster.default.name
instance_id = "alloydb-instance"
instance_type = "PRIMARY"
machine_config {
cpu_count = 2
}
depends_on = [google_service_networking_connection.vpc_connection]
}
resource "google_alloydb_cluster" "default" {
cluster_id = "alloydb-cluster"
location = "us-central1"
network_config {
network = google_compute_network.default.id
}
database_version = "POSTGRES_14"
initial_user {
password = "alloydb-cluster"
}
}
data "google_project" "project" {}
resource "google_compute_network" "default" {
name = "alloydb-network"
}
resource "google_compute_global_address" "private_ip_alloc" {
name = "alloydb-cluster"
address_type = "INTERNAL"
purpose = "VPC_PEERING"
prefix_length = 16
network = google_compute_network.default.id
}
resource "google_service_networking_connection" "vpc_connection" {
network = google_compute_network.default.id
service = "servicenetworking.googleapis.com"
reserved_peering_ranges = [google_compute_global_address.private_ip_alloc.name]
}
```
<div class = "oics-button" style="float: right; margin: 0 0 -15px">
<a href="https://console.cloud.google.com/cloudshell/open?cloudshell_git_repo=https%3A%2F%2Fgithub.com%2Fterraform-google-modules%2Fdocs-examples.git&cloudshell_image=gcr.io%2Fcloudshell-images%2Fcloudshell%3Alatest&cloudshell_print=.%2Fmotd&cloudshell_tutorial=.%2Ftutorial.md&cloudshell_working_dir=alloydb_cluster_after_upgrade&open_in_editor=main.tf" target="_blank">
<img alt="Open in Cloud Shell" src="//gstatic.com/cloudssh/images/open-btn.svg" style="max-height: 44px; margin: 32px auto; max-width: 100%;">
</a>
</div>
## Example Usage - Alloydb Cluster After Upgrade


```hcl
resource "google_alloydb_instance" "default" {
cluster = google_alloydb_cluster.default.name
instance_id = "alloydb-instance"
instance_type = "PRIMARY"
machine_config {
cpu_count = 2
}
depends_on = [google_service_networking_connection.vpc_connection]
}
resource "google_alloydb_cluster" "default" {
cluster_id = "alloydb-cluster"
location = "us-central1"
network_config {
network = google_compute_network.default.id
}
database_version = "POSTGRES_15"
initial_user {
password = "alloydb-cluster"
}
}
data "google_project" "project" {}
resource "google_compute_network" "default" {
name = "alloydb-network"
}
resource "google_compute_global_address" "private_ip_alloc" {
name = "alloydb-cluster"
address_type = "INTERNAL"
purpose = "VPC_PEERING"
prefix_length = 16
network = google_compute_network.default.id
}
resource "google_service_networking_connection" "vpc_connection" {
network = google_compute_network.default.id
service = "servicenetworking.googleapis.com"
reserved_peering_ranges = [google_compute_global_address.private_ip_alloc.name]
}
```
<div class = "oics-button" style="float: right; margin: 0 0 -15px">
<a href="https://console.cloud.google.com/cloudshell/open?cloudshell_git_repo=https%3A%2F%2Fgithub.com%2Fterraform-google-modules%2Fdocs-examples.git&cloudshell_image=gcr.io%2Fcloudshell-images%2Fcloudshell%3Alatest&cloudshell_print=.%2Fmotd&cloudshell_tutorial=.%2Ftutorial.md&cloudshell_working_dir=alloydb_cluster_full&open_in_editor=main.tf" target="_blank">
<img alt="Open in Cloud Shell" src="//gstatic.com/cloudssh/images/open-btn.svg" style="max-height: 44px; margin: 32px auto; max-width: 100%;">
Expand Down

0 comments on commit 6b7344d

Please sign in to comment.