Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update examples for Cloud Bigtable AppProfile #4172

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/5871.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
bigtable: Update the examples to show users can create all 3 different flavors of AppProfile
```
92 changes: 86 additions & 6 deletions google-beta/resource_bigtable_app_profile_generated_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
)

func TestAccBigtableAppProfile_bigtableAppProfileMulticlusterExample(t *testing.T) {
func TestAccBigtableAppProfile_bigtableAppProfileAnyclusterExample(t *testing.T) {
t.Parallel()

context := map[string]interface{}{
Expand All @@ -37,7 +37,7 @@ func TestAccBigtableAppProfile_bigtableAppProfileMulticlusterExample(t *testing.
CheckDestroy: testAccCheckBigtableAppProfileDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccBigtableAppProfile_bigtableAppProfileMulticlusterExample(context),
Config: testAccBigtableAppProfile_bigtableAppProfileAnyclusterExample(context),
},
{
ResourceName: "google_bigtable_app_profile.ap",
Expand All @@ -49,16 +49,28 @@ func TestAccBigtableAppProfile_bigtableAppProfileMulticlusterExample(t *testing.
})
}

func testAccBigtableAppProfile_bigtableAppProfileMulticlusterExample(context map[string]interface{}) string {
func testAccBigtableAppProfile_bigtableAppProfileAnyclusterExample(context map[string]interface{}) string {
return Nprintf(`
resource "google_bigtable_instance" "instance" {
name = "tf-test-bt-instance%{random_suffix}"
cluster {
cluster_id = "tf-test-bt-instance%{random_suffix}"
cluster_id = "cluster-1"
zone = "us-central1-a"
num_nodes = 3
storage_type = "HDD"
}
cluster {
cluster_id = "cluster-2"
zone = "us-central1-b"
num_nodes = 3
storage_type = "HDD"
}
cluster {
cluster_id = "cluster-3"
zone = "us-central1-c"
num_nodes = 3
storage_type = "HDD"
}

deletion_protection = "%{deletion_protection}"
}
Expand All @@ -67,7 +79,9 @@ resource "google_bigtable_app_profile" "ap" {
instance = google_bigtable_instance.instance.name
app_profile_id = "tf-test-bt-profile%{random_suffix}"

// Requests will be routed to any of the 3 clusters.
multi_cluster_routing_use_any = true

ignore_warnings = true
}
`, context)
Expand Down Expand Up @@ -104,7 +118,7 @@ func testAccBigtableAppProfile_bigtableAppProfileSingleclusterExample(context ma
resource "google_bigtable_instance" "instance" {
name = "tf-test-bt-instance%{random_suffix}"
cluster {
cluster_id = "tf-test-bt-instance%{random_suffix}"
cluster_id = "cluster-1"
zone = "us-central1-b"
num_nodes = 3
storage_type = "HDD"
Expand All @@ -117,8 +131,9 @@ resource "google_bigtable_app_profile" "ap" {
instance = google_bigtable_instance.instance.name
app_profile_id = "tf-test-bt-profile%{random_suffix}"

// Requests will be routed to the following cluster.
single_cluster_routing {
cluster_id = "tf-test-bt-instance%{random_suffix}"
cluster_id = "cluster-1"
allow_transactional_writes = true
}

Expand All @@ -127,6 +142,71 @@ resource "google_bigtable_app_profile" "ap" {
`, context)
}

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

context := map[string]interface{}{
"deletion_protection": false,
"random_suffix": randString(t, 10),
}

vcrTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckBigtableAppProfileDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccBigtableAppProfile_bigtableAppProfileMulticlusterExample(context),
},
{
ResourceName: "google_bigtable_app_profile.ap",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"app_profile_id", "instance", "ignore_warnings", "ignore_warnings"},
},
},
})
}

func testAccBigtableAppProfile_bigtableAppProfileMulticlusterExample(context map[string]interface{}) string {
return Nprintf(`
resource "google_bigtable_instance" "instance" {
name = "tf-test-bt-instance%{random_suffix}"
cluster {
cluster_id = "cluster-1"
zone = "us-central1-a"
num_nodes = 3
storage_type = "HDD"
}
cluster {
cluster_id = "cluster-2"
zone = "us-central1-b"
num_nodes = 3
storage_type = "HDD"
}
cluster {
cluster_id = "cluster-3"
zone = "us-central1-c"
num_nodes = 3
storage_type = "HDD"
}

deletion_protection = "%{deletion_protection}"
}

resource "google_bigtable_app_profile" "ap" {
instance = google_bigtable_instance.instance.name
app_profile_id = "tf-test-bt-profile%{random_suffix}"

// Requests will be routed to the following 2 clusters.
multi_cluster_routing_use_any = true
multi_cluster_routing_cluster_ids = ["cluster-1", "cluster-2"]

ignore_warnings = true
}
`, context)
}

func testAccCheckBigtableAppProfileDestroyProducer(t *testing.T) func(s *terraform.State) error {
return func(s *terraform.State) error {
for name, rs := range s.RootModule().Resources {
Expand Down
69 changes: 64 additions & 5 deletions website/docs/r/bigtable_app_profile.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,34 @@ To get more information about AppProfile, see:
* [API documentation](https://cloud.google.com/bigtable/docs/reference/admin/rest/v2/projects.instances.appProfiles)

<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_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">
<a href="https://console.cloud.google.com/cloudshell/open?cloudshell_git_repo=https%3A%2F%2Fgithub.com%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">
<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 - Bigtable App Profile Multicluster
## Example Usage - Bigtable App Profile Anycluster


```hcl
resource "google_bigtable_instance" "instance" {
name = "bt-instance"
cluster {
cluster_id = "bt-instance"
cluster_id = "cluster-1"
zone = "us-central1-a"
num_nodes = 3
storage_type = "HDD"
}
cluster {
cluster_id = "cluster-2"
zone = "us-central1-b"
num_nodes = 3
storage_type = "HDD"
}
cluster {
cluster_id = "cluster-3"
zone = "us-central1-c"
num_nodes = 3
storage_type = "HDD"
}

deletion_protection = "true"
}
Expand All @@ -54,7 +66,9 @@ resource "google_bigtable_app_profile" "ap" {
instance = google_bigtable_instance.instance.name
app_profile_id = "bt-profile"

// Requests will be routed to any of the 3 clusters.
multi_cluster_routing_use_any = true

ignore_warnings = true
}
```
Expand All @@ -70,7 +84,7 @@ resource "google_bigtable_app_profile" "ap" {
resource "google_bigtable_instance" "instance" {
name = "bt-instance"
cluster {
cluster_id = "bt-instance"
cluster_id = "cluster-1"
zone = "us-central1-b"
num_nodes = 3
storage_type = "HDD"
Expand All @@ -83,14 +97,59 @@ resource "google_bigtable_app_profile" "ap" {
instance = google_bigtable_instance.instance.name
app_profile_id = "bt-profile"

// Requests will be routed to the following cluster.
single_cluster_routing {
cluster_id = "bt-instance"
cluster_id = "cluster-1"
allow_transactional_writes = true
}

ignore_warnings = true
}
```
<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_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">
<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 - Bigtable App Profile Multicluster


```hcl
resource "google_bigtable_instance" "instance" {
name = "bt-instance"
cluster {
cluster_id = "cluster-1"
zone = "us-central1-a"
num_nodes = 3
storage_type = "HDD"
}
cluster {
cluster_id = "cluster-2"
zone = "us-central1-b"
num_nodes = 3
storage_type = "HDD"
}
cluster {
cluster_id = "cluster-3"
zone = "us-central1-c"
num_nodes = 3
storage_type = "HDD"
}

deletion_protection = "true"
}

resource "google_bigtable_app_profile" "ap" {
instance = google_bigtable_instance.instance.name
app_profile_id = "bt-profile"

// Requests will be routed to the following 2 clusters.
multi_cluster_routing_use_any = true
multi_cluster_routing_cluster_ids = ["cluster-1", "cluster-2"]

ignore_warnings = true
}
```

## Argument Reference

Expand Down