Skip to content

Commit 82b7d1d

Browse files
Enable updating directory service config for Filestore instance (#14203) (#11137)
[upstream:b446df388f5204f9f74d52ef6659b8b8064ae3c2] Signed-off-by: Modular Magician <magic-modules@google.com>
1 parent c9d08c0 commit 82b7d1d

File tree

4 files changed

+76
-17
lines changed

4 files changed

+76
-17
lines changed

.changelog/14203.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
filestore: add support for updating `directory_services` fields in place in `google_filestore_instance`
3+
```

google-beta/services/filestore/resource_filestore_instance.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,6 @@ Possible values include: STANDARD, PREMIUM, BASIC_HDD, BASIC_SSD, HIGH_SCALE_SSD
312312
"directory_services": {
313313
Type: schema.TypeList,
314314
Optional: true,
315-
ForceNew: true,
316315
Description: `Directory Services configuration.
317316
Should only be set if protocol is "NFS_V4_1".`,
318317
MaxItems: 1,
@@ -321,21 +320,18 @@ Should only be set if protocol is "NFS_V4_1".`,
321320
"ldap": {
322321
Type: schema.TypeList,
323322
Optional: true,
324-
ForceNew: true,
325323
Description: `Configuration for LDAP servers.`,
326324
MaxItems: 1,
327325
Elem: &schema.Resource{
328326
Schema: map[string]*schema.Schema{
329327
"domain": {
330328
Type: schema.TypeString,
331329
Required: true,
332-
ForceNew: true,
333330
Description: `The LDAP domain name in the format of 'my-domain.com'.`,
334331
},
335332
"servers": {
336333
Type: schema.TypeList,
337334
Required: true,
338-
ForceNew: true,
339335
Description: `The servers names are used for specifying the LDAP servers names.
340336
The LDAP servers names can come with two formats:
341337
1. DNS name, for example: 'ldap.example1.com', 'ldap.example2.com'.
@@ -349,15 +345,13 @@ IP addresses.`,
349345
"groups_ou": {
350346
Type: schema.TypeString,
351347
Optional: true,
352-
ForceNew: true,
353348
Description: `The groups Organizational Unit (OU) is optional. This parameter is a hint
354349
to allow faster lookup in the LDAP namespace. In case that this parameter
355350
is not provided, Filestore instance will query the whole LDAP namespace.`,
356351
},
357352
"users_ou": {
358353
Type: schema.TypeString,
359354
Optional: true,
360-
ForceNew: true,
361355
Description: `The users Organizational Unit (OU) is optional. This parameter is a hint
362356
to allow faster lookup in the LDAP namespace. In case that this parameter
363357
is not provided, Filestore instance will query the whole LDAP namespace.`,
@@ -896,6 +890,12 @@ func resourceFilestoreInstanceUpdate(d *schema.ResourceData, meta interface{}) e
896890
} else if v, ok := d.GetOkExists("performance_config"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, performanceConfigProp)) {
897891
obj["performanceConfig"] = performanceConfigProp
898892
}
893+
directoryServicesProp, err := expandFilestoreInstanceDirectoryServices(d.Get("directory_services"), d, config)
894+
if err != nil {
895+
return err
896+
} else if v, ok := d.GetOkExists("directory_services"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, directoryServicesProp)) {
897+
obj["directoryServices"] = directoryServicesProp
898+
}
899899
effectiveLabelsProp, err := expandFilestoreInstanceEffectiveLabels(d.Get("effective_labels"), d, config)
900900
if err != nil {
901901
return err
@@ -932,6 +932,10 @@ func resourceFilestoreInstanceUpdate(d *schema.ResourceData, meta interface{}) e
932932
updateMask = append(updateMask, "performanceConfig")
933933
}
934934

935+
if d.HasChange("directory_services") {
936+
updateMask = append(updateMask, "directoryServices")
937+
}
938+
935939
if d.HasChange("effective_labels") {
936940
updateMask = append(updateMask, "labels")
937941
}

google-beta/services/filestore/resource_filestore_instance_test.go

Lines changed: 62 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
//
99
// This code is generated by Magic Modules using the following:
1010
//
11-
// Source file: https://github.com/GoogleCloudPlatform/magic-modules/tree/main/mmv1/third_party/terraform/services/filestore/resource_filestore_instance_test.go.tmpl
11+
// Source file: https://github.com/GoogleCloudPlatform/magic-modules/tree/main/mmv1/third_party/terraform/services/filestore/resource_filestore_instance_test.go
1212
//
1313
// DO NOT EDIT this file directly. Any changes made to this file will be
1414
// overwritten during the next generation cycle.
@@ -566,14 +566,41 @@ func TestAccFilestoreInstance_directoryServices(t *testing.T) {
566566

567567
acctest.VcrTest(t, resource.TestCase{
568568
PreCheck: func() { acctest.AccTestPreCheck(t) },
569-
ProtoV5ProviderFactories: acctest.ProtoV5ProviderBetaFactories(t),
569+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
570570
CheckDestroy: testAccCheckFilestoreInstanceDestroyProducer(t),
571571
Steps: []resource.TestStep{
572572
{
573-
Config: testAccFilestoreInstance_ldap(name, location, tier),
573+
Config: testAccFilestoreInstance_ldap(name, location, tier, "example.com"),
574+
Check: resource.ComposeTestCheckFunc(
575+
resource.TestCheckResourceAttr("google_filestore_instance.instance", "directory_services.0.ldap.0.domain", "example.com"),
576+
resource.TestCheckResourceAttr("google_filestore_instance.instance", "directory_services.0.ldap.0.servers.0", "ldap.example.com"),
577+
resource.TestCheckResourceAttr("google_filestore_instance.instance", "directory_services.0.ldap.0.users_ou", "users"),
578+
resource.TestCheckResourceAttr("google_filestore_instance.instance", "directory_services.0.ldap.0.groups_ou", "groups"),
579+
),
580+
},
581+
{
582+
ResourceName: "google_filestore_instance.instance",
583+
ImportState: true,
584+
ImportStateVerify: true,
585+
ImportStateVerifyIgnore: []string{"zone"},
586+
},
587+
{
588+
Config: testAccFilestoreInstance_nfs_v4(name, location, tier),
589+
Check: resource.ComposeTestCheckFunc(
590+
resource.TestCheckNoResourceAttr("google_filestore_instance.instance", "directory_services.0.ldap.0.domain"),
591+
),
592+
},
593+
{
594+
ResourceName: "google_filestore_instance.instance",
595+
ImportState: true,
596+
ImportStateVerify: true,
597+
ImportStateVerifyIgnore: []string{"zone"},
598+
},
599+
{
600+
Config: testAccFilestoreInstance_ldap(name, location, tier, "example.com"),
574601
Check: resource.ComposeTestCheckFunc(
575-
resource.TestCheckResourceAttr("google_filestore_instance.instance", "directory_services.0.ldap.0.domain", "my-domain.com"),
576-
resource.TestCheckResourceAttr("google_filestore_instance.instance", "directory_services.0.ldap.0.servers.0", "ldap.example1.com"),
602+
resource.TestCheckResourceAttr("google_filestore_instance.instance", "directory_services.0.ldap.0.domain", "example.com"),
603+
resource.TestCheckResourceAttr("google_filestore_instance.instance", "directory_services.0.ldap.0.servers.0", "ldap.example.com"),
577604
resource.TestCheckResourceAttr("google_filestore_instance.instance", "directory_services.0.ldap.0.users_ou", "users"),
578605
resource.TestCheckResourceAttr("google_filestore_instance.instance", "directory_services.0.ldap.0.groups_ou", "groups"),
579606
),
@@ -584,14 +611,39 @@ func TestAccFilestoreInstance_directoryServices(t *testing.T) {
584611
ImportStateVerify: true,
585612
ImportStateVerifyIgnore: []string{"zone"},
586613
},
614+
{
615+
Config: testAccFilestoreInstance_ldap(name, location, tier, "other.com"),
616+
ExpectError: regexp.MustCompile("cannot update existing directory services configuration"),
617+
},
587618
},
588619
})
589620
}
590621

591-
func testAccFilestoreInstance_ldap(name, location, tier string) string {
622+
func testAccFilestoreInstance_nfs_v4(name, location, tier string) string {
623+
return fmt.Sprintf(`
624+
resource "google_filestore_instance" "instance" {
625+
name = "%s"
626+
location = "%s"
627+
tier = "%s"
628+
description = "An instance created during testing."
629+
protocol = "NFS_V4_1"
630+
631+
file_shares {
632+
capacity_gb = 1024
633+
name = "share"
634+
}
635+
636+
networks {
637+
network = "default"
638+
modes = ["MODE_IPV4"]
639+
}
640+
}
641+
`, name, location, tier)
642+
}
643+
644+
func testAccFilestoreInstance_ldap(name, location, tier, domain string) string {
592645
return fmt.Sprintf(`
593646
resource "google_filestore_instance" "instance" {
594-
provider = google-beta
595647
name = "%s"
596648
location = "%s"
597649
tier = "%s"
@@ -610,14 +662,14 @@ resource "google_filestore_instance" "instance" {
610662
611663
directory_services {
612664
ldap {
613-
domain = "my-domain.com"
614-
servers = ["ldap.example1.com"]
665+
domain = "%s"
666+
servers = ["ldap.example.com"]
615667
users_ou = "users"
616668
groups_ou = "groups"
617669
}
618670
}
619671
}
620-
`, name, location, tier)
672+
`, name, location, tier, domain)
621673
}
622674

623675
func TestAccFilestoreInstance_psc(t *testing.T) {

website/docs/r/filestore_instance.html.markdown

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ The following arguments are supported:
241241
Structure is [documented below](#nested_initial_replication).
242242

243243
* `directory_services` -
244-
(Optional, [Beta](https://terraform.io/docs/providers/google/guides/provider_versions.html))
244+
(Optional)
245245
Directory Services configuration.
246246
Should only be set if protocol is "NFS_V4_1".
247247
Structure is [documented below](#nested_directory_services).

0 commit comments

Comments
 (0)