Skip to content

Commit 6b7344d

Browse files
Add examples for AlloyDB Major Version Upgrade (hashicorp#13177) (hashicorp#21618)
[upstream:e98212e5d8fe8ac0e028a4be9b444a3dcbb6bcde] Signed-off-by: Modular Magician <[email protected]>
1 parent 47a6165 commit 6b7344d

File tree

3 files changed

+259
-0
lines changed

3 files changed

+259
-0
lines changed

.changelog/13177.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:none
2+
alloydb: add examples for AlloyDB Major Version Upgrade for `google_alloydb_cluster` resource.
3+
```

google/services/alloydb/resource_alloydb_cluster_generated_test.go

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,154 @@ resource "google_compute_network" "default" {
7373
`, context)
7474
}
7575

76+
func TestAccAlloydbCluster_alloydbClusterBeforeUpgradeExample(t *testing.T) {
77+
t.Parallel()
78+
79+
context := map[string]interface{}{
80+
"random_suffix": acctest.RandString(t, 10),
81+
}
82+
83+
acctest.VcrTest(t, resource.TestCase{
84+
PreCheck: func() { acctest.AccTestPreCheck(t) },
85+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
86+
CheckDestroy: testAccCheckAlloydbClusterDestroyProducer(t),
87+
Steps: []resource.TestStep{
88+
{
89+
Config: testAccAlloydbCluster_alloydbClusterBeforeUpgradeExample(context),
90+
},
91+
{
92+
ResourceName: "google_alloydb_cluster.default",
93+
ImportState: true,
94+
ImportStateVerify: true,
95+
ImportStateVerifyIgnore: []string{"annotations", "cluster_id", "initial_user", "labels", "location", "restore_backup_source", "restore_continuous_backup_source", "terraform_labels"},
96+
},
97+
},
98+
})
99+
}
100+
101+
func testAccAlloydbCluster_alloydbClusterBeforeUpgradeExample(context map[string]interface{}) string {
102+
return acctest.Nprintf(`
103+
resource "google_alloydb_instance" "default" {
104+
cluster = google_alloydb_cluster.default.name
105+
instance_id = "tf-test-alloydb-instance%{random_suffix}"
106+
instance_type = "PRIMARY"
107+
108+
machine_config {
109+
cpu_count = 2
110+
}
111+
112+
depends_on = [google_service_networking_connection.vpc_connection]
113+
}
114+
115+
resource "google_alloydb_cluster" "default" {
116+
cluster_id = "tf-test-alloydb-cluster%{random_suffix}"
117+
location = "us-central1"
118+
network_config {
119+
network = google_compute_network.default.id
120+
}
121+
database_version = "POSTGRES_14"
122+
123+
initial_user {
124+
password = "tf-test-alloydb-cluster%{random_suffix}"
125+
}
126+
}
127+
128+
data "google_project" "project" {}
129+
130+
resource "google_compute_network" "default" {
131+
name = "tf-test-alloydb-network%{random_suffix}"
132+
}
133+
134+
resource "google_compute_global_address" "private_ip_alloc" {
135+
name = "tf-test-alloydb-cluster%{random_suffix}"
136+
address_type = "INTERNAL"
137+
purpose = "VPC_PEERING"
138+
prefix_length = 16
139+
network = google_compute_network.default.id
140+
}
141+
142+
resource "google_service_networking_connection" "vpc_connection" {
143+
network = google_compute_network.default.id
144+
service = "servicenetworking.googleapis.com"
145+
reserved_peering_ranges = [google_compute_global_address.private_ip_alloc.name]
146+
}
147+
`, context)
148+
}
149+
150+
func TestAccAlloydbCluster_alloydbClusterAfterUpgradeExample(t *testing.T) {
151+
t.Parallel()
152+
153+
context := map[string]interface{}{
154+
"random_suffix": acctest.RandString(t, 10),
155+
}
156+
157+
acctest.VcrTest(t, resource.TestCase{
158+
PreCheck: func() { acctest.AccTestPreCheck(t) },
159+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
160+
CheckDestroy: testAccCheckAlloydbClusterDestroyProducer(t),
161+
Steps: []resource.TestStep{
162+
{
163+
Config: testAccAlloydbCluster_alloydbClusterAfterUpgradeExample(context),
164+
},
165+
{
166+
ResourceName: "google_alloydb_cluster.default",
167+
ImportState: true,
168+
ImportStateVerify: true,
169+
ImportStateVerifyIgnore: []string{"annotations", "cluster_id", "initial_user", "labels", "location", "restore_backup_source", "restore_continuous_backup_source", "terraform_labels"},
170+
},
171+
},
172+
})
173+
}
174+
175+
func testAccAlloydbCluster_alloydbClusterAfterUpgradeExample(context map[string]interface{}) string {
176+
return acctest.Nprintf(`
177+
resource "google_alloydb_instance" "default" {
178+
cluster = google_alloydb_cluster.default.name
179+
instance_id = "tf-test-alloydb-instance%{random_suffix}"
180+
instance_type = "PRIMARY"
181+
182+
machine_config {
183+
cpu_count = 2
184+
}
185+
186+
depends_on = [google_service_networking_connection.vpc_connection]
187+
}
188+
189+
resource "google_alloydb_cluster" "default" {
190+
cluster_id = "tf-test-alloydb-cluster%{random_suffix}"
191+
location = "us-central1"
192+
network_config {
193+
network = google_compute_network.default.id
194+
}
195+
database_version = "POSTGRES_15"
196+
197+
initial_user {
198+
password = "tf-test-alloydb-cluster%{random_suffix}"
199+
}
200+
}
201+
202+
data "google_project" "project" {}
203+
204+
resource "google_compute_network" "default" {
205+
name = "tf-test-alloydb-network%{random_suffix}"
206+
}
207+
208+
resource "google_compute_global_address" "private_ip_alloc" {
209+
name = "tf-test-alloydb-cluster%{random_suffix}"
210+
address_type = "INTERNAL"
211+
purpose = "VPC_PEERING"
212+
prefix_length = 16
213+
network = google_compute_network.default.id
214+
}
215+
216+
resource "google_service_networking_connection" "vpc_connection" {
217+
network = google_compute_network.default.id
218+
service = "servicenetworking.googleapis.com"
219+
reserved_peering_ranges = [google_compute_global_address.private_ip_alloc.name]
220+
}
221+
`, context)
222+
}
223+
76224
func TestAccAlloydbCluster_alloydbClusterFullExample(t *testing.T) {
77225
t.Parallel()
78226

website/docs/r/alloydb_cluster.html.markdown

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,114 @@ resource "google_compute_network" "default" {
6868
name = "alloydb-cluster"
6969
}
7070
```
71+
<div class = "oics-button" style="float: right; margin: 0 0 -15px">
72+
<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">
73+
<img alt="Open in Cloud Shell" src="//gstatic.com/cloudssh/images/open-btn.svg" style="max-height: 44px; margin: 32px auto; max-width: 100%;">
74+
</a>
75+
</div>
76+
## Example Usage - Alloydb Cluster Before Upgrade
77+
78+
79+
```hcl
80+
resource "google_alloydb_instance" "default" {
81+
cluster = google_alloydb_cluster.default.name
82+
instance_id = "alloydb-instance"
83+
instance_type = "PRIMARY"
84+
85+
machine_config {
86+
cpu_count = 2
87+
}
88+
89+
depends_on = [google_service_networking_connection.vpc_connection]
90+
}
91+
92+
resource "google_alloydb_cluster" "default" {
93+
cluster_id = "alloydb-cluster"
94+
location = "us-central1"
95+
network_config {
96+
network = google_compute_network.default.id
97+
}
98+
database_version = "POSTGRES_14"
99+
100+
initial_user {
101+
password = "alloydb-cluster"
102+
}
103+
}
104+
105+
data "google_project" "project" {}
106+
107+
resource "google_compute_network" "default" {
108+
name = "alloydb-network"
109+
}
110+
111+
resource "google_compute_global_address" "private_ip_alloc" {
112+
name = "alloydb-cluster"
113+
address_type = "INTERNAL"
114+
purpose = "VPC_PEERING"
115+
prefix_length = 16
116+
network = google_compute_network.default.id
117+
}
118+
119+
resource "google_service_networking_connection" "vpc_connection" {
120+
network = google_compute_network.default.id
121+
service = "servicenetworking.googleapis.com"
122+
reserved_peering_ranges = [google_compute_global_address.private_ip_alloc.name]
123+
}
124+
```
125+
<div class = "oics-button" style="float: right; margin: 0 0 -15px">
126+
<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">
127+
<img alt="Open in Cloud Shell" src="//gstatic.com/cloudssh/images/open-btn.svg" style="max-height: 44px; margin: 32px auto; max-width: 100%;">
128+
</a>
129+
</div>
130+
## Example Usage - Alloydb Cluster After Upgrade
131+
132+
133+
```hcl
134+
resource "google_alloydb_instance" "default" {
135+
cluster = google_alloydb_cluster.default.name
136+
instance_id = "alloydb-instance"
137+
instance_type = "PRIMARY"
138+
139+
machine_config {
140+
cpu_count = 2
141+
}
142+
143+
depends_on = [google_service_networking_connection.vpc_connection]
144+
}
145+
146+
resource "google_alloydb_cluster" "default" {
147+
cluster_id = "alloydb-cluster"
148+
location = "us-central1"
149+
network_config {
150+
network = google_compute_network.default.id
151+
}
152+
database_version = "POSTGRES_15"
153+
154+
initial_user {
155+
password = "alloydb-cluster"
156+
}
157+
}
158+
159+
data "google_project" "project" {}
160+
161+
resource "google_compute_network" "default" {
162+
name = "alloydb-network"
163+
}
164+
165+
resource "google_compute_global_address" "private_ip_alloc" {
166+
name = "alloydb-cluster"
167+
address_type = "INTERNAL"
168+
purpose = "VPC_PEERING"
169+
prefix_length = 16
170+
network = google_compute_network.default.id
171+
}
172+
173+
resource "google_service_networking_connection" "vpc_connection" {
174+
network = google_compute_network.default.id
175+
service = "servicenetworking.googleapis.com"
176+
reserved_peering_ranges = [google_compute_global_address.private_ip_alloc.name]
177+
}
178+
```
71179
<div class = "oics-button" style="float: right; margin: 0 0 -15px">
72180
<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">
73181
<img alt="Open in Cloud Shell" src="//gstatic.com/cloudssh/images/open-btn.svg" style="max-height: 44px; margin: 32px auto; max-width: 100%;">

0 commit comments

Comments
 (0)