Skip to content

Commit b7e1b1a

Browse files
Update examples for Cloud Bigtable AppProfile. (#5871) (#11394)
Signed-off-by: Modular Magician <[email protected]>
1 parent e86f490 commit b7e1b1a

File tree

3 files changed

+153
-11
lines changed

3 files changed

+153
-11
lines changed

.changelog/5871.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
bigtable: Update the examples to show users can create all 3 different flavors of AppProfile
3+
```

google/resource_bigtable_app_profile_generated_test.go

+86-6
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import (
2323
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
2424
)
2525

26-
func TestAccBigtableAppProfile_bigtableAppProfileMulticlusterExample(t *testing.T) {
26+
func TestAccBigtableAppProfile_bigtableAppProfileAnyclusterExample(t *testing.T) {
2727
t.Parallel()
2828

2929
context := map[string]interface{}{
@@ -37,7 +37,7 @@ func TestAccBigtableAppProfile_bigtableAppProfileMulticlusterExample(t *testing.
3737
CheckDestroy: testAccCheckBigtableAppProfileDestroyProducer(t),
3838
Steps: []resource.TestStep{
3939
{
40-
Config: testAccBigtableAppProfile_bigtableAppProfileMulticlusterExample(context),
40+
Config: testAccBigtableAppProfile_bigtableAppProfileAnyclusterExample(context),
4141
},
4242
{
4343
ResourceName: "google_bigtable_app_profile.ap",
@@ -49,16 +49,28 @@ func TestAccBigtableAppProfile_bigtableAppProfileMulticlusterExample(t *testing.
4949
})
5050
}
5151

52-
func testAccBigtableAppProfile_bigtableAppProfileMulticlusterExample(context map[string]interface{}) string {
52+
func testAccBigtableAppProfile_bigtableAppProfileAnyclusterExample(context map[string]interface{}) string {
5353
return Nprintf(`
5454
resource "google_bigtable_instance" "instance" {
5555
name = "tf-test-bt-instance%{random_suffix}"
5656
cluster {
57-
cluster_id = "tf-test-bt-instance%{random_suffix}"
57+
cluster_id = "cluster-1"
58+
zone = "us-central1-a"
59+
num_nodes = 3
60+
storage_type = "HDD"
61+
}
62+
cluster {
63+
cluster_id = "cluster-2"
5864
zone = "us-central1-b"
5965
num_nodes = 3
6066
storage_type = "HDD"
6167
}
68+
cluster {
69+
cluster_id = "cluster-3"
70+
zone = "us-central1-c"
71+
num_nodes = 3
72+
storage_type = "HDD"
73+
}
6274
6375
deletion_protection = "%{deletion_protection}"
6476
}
@@ -67,7 +79,9 @@ resource "google_bigtable_app_profile" "ap" {
6779
instance = google_bigtable_instance.instance.name
6880
app_profile_id = "tf-test-bt-profile%{random_suffix}"
6981
82+
// Requests will be routed to any of the 3 clusters.
7083
multi_cluster_routing_use_any = true
84+
7185
ignore_warnings = true
7286
}
7387
`, context)
@@ -104,7 +118,7 @@ func testAccBigtableAppProfile_bigtableAppProfileSingleclusterExample(context ma
104118
resource "google_bigtable_instance" "instance" {
105119
name = "tf-test-bt-instance%{random_suffix}"
106120
cluster {
107-
cluster_id = "tf-test-bt-instance%{random_suffix}"
121+
cluster_id = "cluster-1"
108122
zone = "us-central1-b"
109123
num_nodes = 3
110124
storage_type = "HDD"
@@ -117,8 +131,9 @@ resource "google_bigtable_app_profile" "ap" {
117131
instance = google_bigtable_instance.instance.name
118132
app_profile_id = "tf-test-bt-profile%{random_suffix}"
119133
134+
// Requests will be routed to the following cluster.
120135
single_cluster_routing {
121-
cluster_id = "tf-test-bt-instance%{random_suffix}"
136+
cluster_id = "cluster-1"
122137
allow_transactional_writes = true
123138
}
124139
@@ -127,6 +142,71 @@ resource "google_bigtable_app_profile" "ap" {
127142
`, context)
128143
}
129144

145+
func TestAccBigtableAppProfile_bigtableAppProfileMulticlusterExample(t *testing.T) {
146+
t.Parallel()
147+
148+
context := map[string]interface{}{
149+
"deletion_protection": false,
150+
"random_suffix": randString(t, 10),
151+
}
152+
153+
vcrTest(t, resource.TestCase{
154+
PreCheck: func() { testAccPreCheck(t) },
155+
Providers: testAccProviders,
156+
CheckDestroy: testAccCheckBigtableAppProfileDestroyProducer(t),
157+
Steps: []resource.TestStep{
158+
{
159+
Config: testAccBigtableAppProfile_bigtableAppProfileMulticlusterExample(context),
160+
},
161+
{
162+
ResourceName: "google_bigtable_app_profile.ap",
163+
ImportState: true,
164+
ImportStateVerify: true,
165+
ImportStateVerifyIgnore: []string{"app_profile_id", "instance", "ignore_warnings", "ignore_warnings"},
166+
},
167+
},
168+
})
169+
}
170+
171+
func testAccBigtableAppProfile_bigtableAppProfileMulticlusterExample(context map[string]interface{}) string {
172+
return Nprintf(`
173+
resource "google_bigtable_instance" "instance" {
174+
name = "tf-test-bt-instance%{random_suffix}"
175+
cluster {
176+
cluster_id = "cluster-1"
177+
zone = "us-central1-a"
178+
num_nodes = 3
179+
storage_type = "HDD"
180+
}
181+
cluster {
182+
cluster_id = "cluster-2"
183+
zone = "us-central1-b"
184+
num_nodes = 3
185+
storage_type = "HDD"
186+
}
187+
cluster {
188+
cluster_id = "cluster-3"
189+
zone = "us-central1-c"
190+
num_nodes = 3
191+
storage_type = "HDD"
192+
}
193+
194+
deletion_protection = "%{deletion_protection}"
195+
}
196+
197+
resource "google_bigtable_app_profile" "ap" {
198+
instance = google_bigtable_instance.instance.name
199+
app_profile_id = "tf-test-bt-profile%{random_suffix}"
200+
201+
// Requests will be routed to the following 2 clusters.
202+
multi_cluster_routing_use_any = true
203+
multi_cluster_routing_cluster_ids = ["cluster-1", "cluster-2"]
204+
205+
ignore_warnings = true
206+
}
207+
`, context)
208+
}
209+
130210
func testAccCheckBigtableAppProfileDestroyProducer(t *testing.T) func(s *terraform.State) error {
131211
return func(s *terraform.State) error {
132212
for name, rs := range s.RootModule().Resources {

website/docs/r/bigtable_app_profile.html.markdown

+64-5
Original file line numberDiff line numberDiff line change
@@ -30,22 +30,34 @@ To get more information about AppProfile, see:
3030
* [API documentation](https://cloud.google.com/bigtable/docs/reference/admin/rest/v2/projects.instances.appProfiles)
3131

3232
<div class = "oics-button" style="float: right; margin: 0 0 -15px">
33-
<a href="https://console.cloud.google.com/cloudshell/open?cloudshell_git_repo=https%3A%2F%2Fgithub.jpy.wang%2Fterraform-google-modules%2Fdocs-examples.git&cloudshell_working_dir=bigtable_app_profile_multicluster&cloudshell_image=gcr.io%2Fgraphite-cloud-shell-images%2Fterraform%3Alatest&open_in_editor=main.tf&cloudshell_print=.%2Fmotd&cloudshell_tutorial=.%2Ftutorial.md" target="_blank">
33+
<a href="https://console.cloud.google.com/cloudshell/open?cloudshell_git_repo=https%3A%2F%2Fgithub.jpy.wang%2Fterraform-google-modules%2Fdocs-examples.git&cloudshell_working_dir=bigtable_app_profile_anycluster&cloudshell_image=gcr.io%2Fgraphite-cloud-shell-images%2Fterraform%3Alatest&open_in_editor=main.tf&cloudshell_print=.%2Fmotd&cloudshell_tutorial=.%2Ftutorial.md" target="_blank">
3434
<img alt="Open in Cloud Shell" src="//gstatic.com/cloudssh/images/open-btn.svg" style="max-height: 44px; margin: 32px auto; max-width: 100%;">
3535
</a>
3636
</div>
37-
## Example Usage - Bigtable App Profile Multicluster
37+
## Example Usage - Bigtable App Profile Anycluster
3838

3939

4040
```hcl
4141
resource "google_bigtable_instance" "instance" {
4242
name = "bt-instance"
4343
cluster {
44-
cluster_id = "bt-instance"
44+
cluster_id = "cluster-1"
45+
zone = "us-central1-a"
46+
num_nodes = 3
47+
storage_type = "HDD"
48+
}
49+
cluster {
50+
cluster_id = "cluster-2"
4551
zone = "us-central1-b"
4652
num_nodes = 3
4753
storage_type = "HDD"
4854
}
55+
cluster {
56+
cluster_id = "cluster-3"
57+
zone = "us-central1-c"
58+
num_nodes = 3
59+
storage_type = "HDD"
60+
}
4961
5062
deletion_protection = "true"
5163
}
@@ -54,7 +66,9 @@ resource "google_bigtable_app_profile" "ap" {
5466
instance = google_bigtable_instance.instance.name
5567
app_profile_id = "bt-profile"
5668
69+
// Requests will be routed to any of the 3 clusters.
5770
multi_cluster_routing_use_any = true
71+
5872
ignore_warnings = true
5973
}
6074
```
@@ -70,7 +84,7 @@ resource "google_bigtable_app_profile" "ap" {
7084
resource "google_bigtable_instance" "instance" {
7185
name = "bt-instance"
7286
cluster {
73-
cluster_id = "bt-instance"
87+
cluster_id = "cluster-1"
7488
zone = "us-central1-b"
7589
num_nodes = 3
7690
storage_type = "HDD"
@@ -83,14 +97,59 @@ resource "google_bigtable_app_profile" "ap" {
8397
instance = google_bigtable_instance.instance.name
8498
app_profile_id = "bt-profile"
8599
100+
// Requests will be routed to the following cluster.
86101
single_cluster_routing {
87-
cluster_id = "bt-instance"
102+
cluster_id = "cluster-1"
88103
allow_transactional_writes = true
89104
}
90105
91106
ignore_warnings = true
92107
}
93108
```
109+
<div class = "oics-button" style="float: right; margin: 0 0 -15px">
110+
<a href="https://console.cloud.google.com/cloudshell/open?cloudshell_git_repo=https%3A%2F%2Fgithub.jpy.wang%2Fterraform-google-modules%2Fdocs-examples.git&cloudshell_working_dir=bigtable_app_profile_multicluster&cloudshell_image=gcr.io%2Fgraphite-cloud-shell-images%2Fterraform%3Alatest&open_in_editor=main.tf&cloudshell_print=.%2Fmotd&cloudshell_tutorial=.%2Ftutorial.md" target="_blank">
111+
<img alt="Open in Cloud Shell" src="//gstatic.com/cloudssh/images/open-btn.svg" style="max-height: 44px; margin: 32px auto; max-width: 100%;">
112+
</a>
113+
</div>
114+
## Example Usage - Bigtable App Profile Multicluster
115+
116+
117+
```hcl
118+
resource "google_bigtable_instance" "instance" {
119+
name = "bt-instance"
120+
cluster {
121+
cluster_id = "cluster-1"
122+
zone = "us-central1-a"
123+
num_nodes = 3
124+
storage_type = "HDD"
125+
}
126+
cluster {
127+
cluster_id = "cluster-2"
128+
zone = "us-central1-b"
129+
num_nodes = 3
130+
storage_type = "HDD"
131+
}
132+
cluster {
133+
cluster_id = "cluster-3"
134+
zone = "us-central1-c"
135+
num_nodes = 3
136+
storage_type = "HDD"
137+
}
138+
139+
deletion_protection = "true"
140+
}
141+
142+
resource "google_bigtable_app_profile" "ap" {
143+
instance = google_bigtable_instance.instance.name
144+
app_profile_id = "bt-profile"
145+
146+
// Requests will be routed to the following 2 clusters.
147+
multi_cluster_routing_use_any = true
148+
multi_cluster_routing_cluster_ids = ["cluster-1", "cluster-2"]
149+
150+
ignore_warnings = true
151+
}
152+
```
94153

95154
## Argument Reference
96155

0 commit comments

Comments
 (0)