Skip to content

Commit d5614b9

Browse files
authored
Adding kms_key to google_lustre_instance (#15725)
1 parent 84fda72 commit d5614b9

File tree

2 files changed

+71
-8
lines changed

2 files changed

+71
-8
lines changed

mmv1/products/lustre/Instance.yaml

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -116,14 +116,7 @@ properties:
116116
type: String
117117
description: |-
118118
The state of the instance.
119-
Possible values:
120-
STATE_UNSPECIFIED
121-
ACTIVE
122-
CREATING
123-
DELETING
124-
UPGRADING
125-
REPAIRING
126-
STOPPED
119+
Please see https://cloud.google.com/managed-lustre/docs/reference/rest/v1/projects.locations.instances#state for values
127120
output: true
128121
- name: mountPoint
129122
type: String
@@ -155,3 +148,13 @@ properties:
155148
description: |-
156149
The placement policy name for the instance in the format of
157150
projects/{project}/locations/{location}/resourcePolicies/{resource_policy}
151+
- name: kmsKey
152+
type: String
153+
description: |-
154+
The KMS key id to use for encryption of the Lustre instance.
155+
immutable: true
156+
- name: stateReason
157+
type: String
158+
description: |-
159+
The reason why the instance is in a certain state.
160+
output: true

mmv1/third_party/terraform/services/lustre/resource_lustre_instance_test.go

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,66 @@ data "google_compute_network" "lustre-network" {
8080
`, context)
8181
}
8282

83+
func TestAccLustreInstance_withKmsKey(t *testing.T) {
84+
t.Parallel()
85+
86+
context := map[string]interface{}{
87+
"network_name": acctest.BootstrapSharedTestNetwork(t, "default-vpc"),
88+
"random_suffix": acctest.RandString(t, 10),
89+
"kms": acctest.BootstrapKMSKeyInLocation(t, "us-central1").CryptoKey.Name,
90+
}
91+
92+
acctest.VcrTest(t, resource.TestCase{
93+
PreCheck: func() { acctest.AccTestPreCheck(t) },
94+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
95+
Steps: []resource.TestStep{
96+
{
97+
Config: testAccLustreInstance_withKmsKey(context),
98+
},
99+
{
100+
ResourceName: "google_lustre_instance.instance",
101+
ImportState: true,
102+
ImportStateVerify: true,
103+
ImportStateVerifyIgnore: []string{"instance_id", "labels", "gke_support_enabled", "location", "terraform_labels"},
104+
},
105+
},
106+
})
107+
}
108+
109+
func testAccLustreInstance_withKmsKey(context map[string]interface{}) string {
110+
return acctest.Nprintf(`
111+
resource "google_lustre_instance" "instance" {
112+
instance_id = "tf-test-my-instance%{random_suffix}"
113+
location = "us-central1-a"
114+
filesystem = "testfs"
115+
network = data.google_compute_network.lustre-network.id
116+
gke_support_enabled = false
117+
capacity_gib = 18000
118+
per_unit_storage_throughput = 1000
119+
kms_key = "%{kms}"
120+
121+
timeouts {
122+
create = "120m"
123+
}
124+
125+
depends_on = [google_kms_crypto_key_iam_member.lustre_sa_encrypter_decrypter]
126+
}
127+
128+
resource "google_kms_crypto_key_iam_member" "lustre_sa_encrypter_decrypter" {
129+
crypto_key_id = "%{kms}"
130+
role = "roles/cloudkms.cryptoKeyEncrypterDecrypter"
131+
member = "serviceAccount:service-${data.google_project.project.number}@gcp-sa-lustre.iam.gserviceaccount.com"
132+
}
133+
134+
data "google_compute_network" "lustre-network" {
135+
name = "%{network_name}"
136+
}
137+
138+
data "google_project" "project" {
139+
}
140+
`, context)
141+
}
142+
83143
func testAccLustreInstance_update(context map[string]interface{}) string {
84144
return acctest.Nprintf(`
85145
resource "google_lustre_instance" "instance" {

0 commit comments

Comments
 (0)