|
| 1 | +package lustre_test |
| 2 | + |
| 3 | +import ( |
| 4 | + "testing" |
| 5 | + |
| 6 | + "github.com/hashicorp/terraform-plugin-testing/helper/resource" |
| 7 | + "github.com/hashicorp/terraform-plugin-testing/plancheck" |
| 8 | + |
| 9 | + "github.com/hashicorp/terraform-provider-google/google/acctest" |
| 10 | +) |
| 11 | + |
| 12 | +func TestAccLustreInstance_update(t *testing.T) { |
| 13 | + t.Parallel() |
| 14 | + |
| 15 | + context := map[string]interface{}{ |
| 16 | + "network_name": acctest.BootstrapSharedTestNetwork(t, "default-vpc"), |
| 17 | + "random_suffix": acctest.RandString(t, 10), |
| 18 | + } |
| 19 | + |
| 20 | + acctest.VcrTest(t, resource.TestCase{ |
| 21 | + PreCheck: func() { acctest.AccTestPreCheck(t) }, |
| 22 | + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t), |
| 23 | + Steps: []resource.TestStep{ |
| 24 | + { |
| 25 | + Config: testAccLustreInstance_full(context), |
| 26 | + }, |
| 27 | + { |
| 28 | + ResourceName: "google_lustre_instance.instance", |
| 29 | + ImportState: true, |
| 30 | + ImportStateVerify: true, |
| 31 | + ImportStateVerifyIgnore: []string{"instance_id", "labels", "gke_support_enabled", "location", "terraform_labels"}, |
| 32 | + }, |
| 33 | + { |
| 34 | + Config: testAccLustreInstance_update(context), |
| 35 | + ConfigPlanChecks: resource.ConfigPlanChecks{ |
| 36 | + PreApply: []plancheck.PlanCheck{ |
| 37 | + plancheck.ExpectResourceAction( |
| 38 | + "google_lustre_instance.instance", |
| 39 | + plancheck.ResourceActionUpdate, |
| 40 | + ), |
| 41 | + }, |
| 42 | + }, |
| 43 | + }, |
| 44 | + { |
| 45 | + ResourceName: "google_lustre_instance.instance", |
| 46 | + ImportState: true, |
| 47 | + ImportStateVerify: true, |
| 48 | + ImportStateVerifyIgnore: []string{"instance_id", "labels", "gke_support_enabled", "location", "terraform_labels"}, |
| 49 | + }, |
| 50 | + }, |
| 51 | + }) |
| 52 | +} |
| 53 | + |
| 54 | +func testAccLustreInstance_full(context map[string]interface{}) string { |
| 55 | + return acctest.Nprintf(` |
| 56 | +resource "google_lustre_instance" "instance" { |
| 57 | + instance_id = "tf-test-my-instance%{random_suffix}" |
| 58 | + location = "us-central1-a" |
| 59 | + filesystem = "testfs" |
| 60 | + network = data.google_compute_network.lustre-network.id |
| 61 | + gke_support_enabled = false |
| 62 | + capacity_gib = 18000 |
| 63 | + timeouts { |
| 64 | + create = "120m" |
| 65 | + } |
| 66 | +} |
| 67 | +
|
| 68 | +// This example assumes this network already exists. |
| 69 | +// The API creates a tenant network per network authorized for a |
| 70 | +// Lustre instance and that network is not deleted when the user-created |
| 71 | +// network (authorized_network) is deleted, so this prevents issues |
| 72 | +// with tenant network quota. |
| 73 | +// If this network hasn't been created and you are using this example in your |
| 74 | +// config, add an additional network resource or change |
| 75 | +// this from "data"to "resource" |
| 76 | +data "google_compute_network" "lustre-network" { |
| 77 | + name = "%{network_name}" |
| 78 | +} |
| 79 | +`, context) |
| 80 | +} |
| 81 | + |
| 82 | +func testAccLustreInstance_update(context map[string]interface{}) string { |
| 83 | + return acctest.Nprintf(` |
| 84 | +resource "google_lustre_instance" "instance" { |
| 85 | + instance_id = "tf-test-my-instance%{random_suffix}" |
| 86 | + location = "us-central1-a" |
| 87 | + filesystem = "testfs" |
| 88 | + capacity_gib = 18000 |
| 89 | + network = data.google_compute_network.lustre-network.id |
| 90 | + description = "test-description" |
| 91 | + labels = { |
| 92 | + test = "test-label" |
| 93 | + } |
| 94 | + timeouts { |
| 95 | + create = "120m" |
| 96 | + } |
| 97 | +} |
| 98 | +
|
| 99 | +// This example assumes this network already exists. |
| 100 | +// The API creates a tenant network per network authorized for a |
| 101 | +// Lustre instance and that network is not deleted when the user-created |
| 102 | +// network (authorized_network) is deleted, so this prevents issues |
| 103 | +// with tenant network quota. |
| 104 | +// If this network hasn't been created and you are using this example in your |
| 105 | +// config, add an additional network resource or change |
| 106 | +// this from "data"to "resource" |
| 107 | +data "google_compute_network" "lustre-network" { |
| 108 | + name = "%{network_name}" |
| 109 | +} |
| 110 | +`, context) |
| 111 | +} |
0 commit comments