Skip to content

Commit bb88b83

Browse files
adding builtin administrators field in AD resource (#10842) (#18333)
[upstream:d64895dd8b52ebb98b915297eecd80ef27617009] Signed-off-by: Modular Magician <[email protected]>
1 parent 16dd741 commit bb88b83

4 files changed

+171
-0
lines changed

google/services/netapp/resource_netapp_active_directory.go

+35
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,14 @@ A five-character random ID is generated automatically, for example, -6f9a, and a
9595
Required: true,
9696
Description: `Username for the Active Directory account with permissions to create the compute account within the specified organizational unit.`,
9797
},
98+
"administrators": {
99+
Type: schema.TypeList,
100+
Optional: true,
101+
Description: `Domain user accounts to be added to the local Administrators group of the SMB service. Comma-separated list of domain users or groups. The Domain Admin group is automatically added when the service joins your domain as a hidden group.`,
102+
Elem: &schema.Schema{
103+
Type: schema.TypeString,
104+
},
105+
},
98106
"aes_encryption": {
99107
Type: schema.TypeBool,
100108
Optional: true,
@@ -272,6 +280,12 @@ func resourceNetappactiveDirectoryCreate(d *schema.ResourceData, meta interface{
272280
} else if v, ok := d.GetOkExists("backup_operators"); !tpgresource.IsEmptyValue(reflect.ValueOf(backupOperatorsProp)) && (ok || !reflect.DeepEqual(v, backupOperatorsProp)) {
273281
obj["backupOperators"] = backupOperatorsProp
274282
}
283+
administratorsProp, err := expandNetappactiveDirectoryAdministrators(d.Get("administrators"), d, config)
284+
if err != nil {
285+
return err
286+
} else if v, ok := d.GetOkExists("administrators"); !tpgresource.IsEmptyValue(reflect.ValueOf(administratorsProp)) && (ok || !reflect.DeepEqual(v, administratorsProp)) {
287+
obj["administrators"] = administratorsProp
288+
}
275289
securityOperatorsProp, err := expandNetappactiveDirectorySecurityOperators(d.Get("security_operators"), d, config)
276290
if err != nil {
277291
return err
@@ -449,6 +463,9 @@ func resourceNetappactiveDirectoryRead(d *schema.ResourceData, meta interface{})
449463
if err := d.Set("backup_operators", flattenNetappactiveDirectoryBackupOperators(res["backupOperators"], d, config)); err != nil {
450464
return fmt.Errorf("Error reading activeDirectory: %s", err)
451465
}
466+
if err := d.Set("administrators", flattenNetappactiveDirectoryAdministrators(res["administrators"], d, config)); err != nil {
467+
return fmt.Errorf("Error reading activeDirectory: %s", err)
468+
}
452469
if err := d.Set("security_operators", flattenNetappactiveDirectorySecurityOperators(res["securityOperators"], d, config)); err != nil {
453470
return fmt.Errorf("Error reading activeDirectory: %s", err)
454471
}
@@ -556,6 +573,12 @@ func resourceNetappactiveDirectoryUpdate(d *schema.ResourceData, meta interface{
556573
} else if v, ok := d.GetOkExists("backup_operators"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, backupOperatorsProp)) {
557574
obj["backupOperators"] = backupOperatorsProp
558575
}
576+
administratorsProp, err := expandNetappactiveDirectoryAdministrators(d.Get("administrators"), d, config)
577+
if err != nil {
578+
return err
579+
} else if v, ok := d.GetOkExists("administrators"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, administratorsProp)) {
580+
obj["administrators"] = administratorsProp
581+
}
559582
securityOperatorsProp, err := expandNetappactiveDirectorySecurityOperators(d.Get("security_operators"), d, config)
560583
if err != nil {
561584
return err
@@ -650,6 +673,10 @@ func resourceNetappactiveDirectoryUpdate(d *schema.ResourceData, meta interface{
650673
updateMask = append(updateMask, "backupOperators")
651674
}
652675

676+
if d.HasChange("administrators") {
677+
updateMask = append(updateMask, "administrators")
678+
}
679+
653680
if d.HasChange("security_operators") {
654681
updateMask = append(updateMask, "securityOperators")
655682
}
@@ -840,6 +867,10 @@ func flattenNetappactiveDirectoryBackupOperators(v interface{}, d *schema.Resour
840867
return v
841868
}
842869

870+
func flattenNetappactiveDirectoryAdministrators(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
871+
return v
872+
}
873+
843874
func flattenNetappactiveDirectorySecurityOperators(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
844875
return v
845876
}
@@ -942,6 +973,10 @@ func expandNetappactiveDirectoryBackupOperators(v interface{}, d tpgresource.Ter
942973
return v, nil
943974
}
944975

976+
func expandNetappactiveDirectoryAdministrators(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
977+
return v, nil
978+
}
979+
945980
func expandNetappactiveDirectorySecurityOperators(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
946981
return v, nil
947982
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
// Copyright (c) HashiCorp, Inc.
2+
// SPDX-License-Identifier: MPL-2.0
3+
4+
// ----------------------------------------------------------------------------
5+
//
6+
// *** AUTO GENERATED CODE *** Type: MMv1 ***
7+
//
8+
// ----------------------------------------------------------------------------
9+
//
10+
// This file is automatically generated by Magic Modules and manual
11+
// changes will be clobbered when the file is regenerated.
12+
//
13+
// Please read more about how to change this file in
14+
// .github/CONTRIBUTING.md.
15+
//
16+
// ----------------------------------------------------------------------------
17+
18+
package netapp_test
19+
20+
import (
21+
"fmt"
22+
"strings"
23+
"testing"
24+
25+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
26+
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
27+
28+
"github.com/hashicorp/terraform-provider-google/google/acctest"
29+
"github.com/hashicorp/terraform-provider-google/google/tpgresource"
30+
transport_tpg "github.com/hashicorp/terraform-provider-google/google/transport"
31+
)
32+
33+
func TestAccNetappactiveDirectory_netappActiveDirectoryFullExample(t *testing.T) {
34+
t.Parallel()
35+
36+
context := map[string]interface{}{
37+
"random_suffix": acctest.RandString(t, 10),
38+
}
39+
40+
acctest.VcrTest(t, resource.TestCase{
41+
PreCheck: func() { acctest.AccTestPreCheck(t) },
42+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
43+
CheckDestroy: testAccCheckNetappactiveDirectoryDestroyProducer(t),
44+
Steps: []resource.TestStep{
45+
{
46+
Config: testAccNetappactiveDirectory_netappActiveDirectoryFullExample(context),
47+
},
48+
{
49+
ResourceName: "google_netapp_active_directory.test_active_directory_full",
50+
ImportState: true,
51+
ImportStateVerify: true,
52+
ImportStateVerifyIgnore: []string{"labels", "location", "name", "password", "terraform_labels"},
53+
},
54+
},
55+
})
56+
}
57+
58+
func testAccNetappactiveDirectory_netappActiveDirectoryFullExample(context map[string]interface{}) string {
59+
return acctest.Nprintf(`
60+
resource "google_netapp_active_directory" "test_active_directory_full" {
61+
name = "tf-test-test-active-directory-full%{random_suffix}"
62+
location = "us-central1"
63+
domain = "ad.internal"
64+
dns = "172.30.64.3"
65+
net_bios_prefix = "smbserver"
66+
username = "user"
67+
password = "pass"
68+
aes_encryption = false
69+
backup_operators = ["test1", "test2"]
70+
administrators = ["test1", "test2"]
71+
description = "ActiveDirectory is the public representation of the active directory config."
72+
encrypt_dc_connections = false
73+
kdc_hostname = "hostname"
74+
kdc_ip = "10.10.0.11"
75+
labels = {
76+
"foo": "bar"
77+
}
78+
ldap_signing = false
79+
nfs_users_with_ldap = false
80+
organizational_unit = "CN=Computers"
81+
security_operators = ["test1", "test2"]
82+
site = "test-site"
83+
}
84+
`, context)
85+
}
86+
87+
func testAccCheckNetappactiveDirectoryDestroyProducer(t *testing.T) func(s *terraform.State) error {
88+
return func(s *terraform.State) error {
89+
for name, rs := range s.RootModule().Resources {
90+
if rs.Type != "google_netapp_active_directory" {
91+
continue
92+
}
93+
if strings.HasPrefix(name, "data.") {
94+
continue
95+
}
96+
97+
config := acctest.GoogleProviderConfig(t)
98+
99+
url, err := tpgresource.ReplaceVarsForTest(config, rs, "{{NetappBasePath}}projects/{{project}}/locations/{{location}}/activeDirectories/{{name}}")
100+
if err != nil {
101+
return err
102+
}
103+
104+
billingProject := ""
105+
106+
if config.BillingProject != "" {
107+
billingProject = config.BillingProject
108+
}
109+
110+
_, err = transport_tpg.SendRequest(transport_tpg.SendRequestOptions{
111+
Config: config,
112+
Method: "GET",
113+
Project: billingProject,
114+
RawURL: url,
115+
UserAgent: config.UserAgent,
116+
})
117+
if err == nil {
118+
return fmt.Errorf("NetappactiveDirectory still exists at %s", url)
119+
}
120+
}
121+
122+
return nil
123+
}
124+
}

google/services/netapp/resource_netapp_active_directory_test.go

+2
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ resource "google_netapp_active_directory" "test_active_directory_full" {
5555
password = "pass"
5656
aes_encryption = false
5757
backup_operators = ["test1", "test2"]
58+
administrators = ["test1", "test2"]
5859
description = "ActiveDirectory is the public representation of the active directory config."
5960
encrypt_dc_connections = false
6061
kdc_hostname = "hostname"
@@ -83,6 +84,7 @@ resource "google_netapp_active_directory" "test_active_directory_full" {
8384
password = "pass"
8485
aes_encryption = false
8586
backup_operators = ["test1", "test2"]
87+
administrators = ["test1", "test2"]
8688
description = "ActiveDirectory is the public representation of the active directory config."
8789
encrypt_dc_connections = false
8890
kdc_hostname = "hostname"

website/docs/r/netapp_active_directory.html.markdown

+10
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ To get more information about activeDirectory, see:
3232
values will be stored in the raw state as plain text: `password`.
3333
[Read more about sensitive data in state](https://www.terraform.io/language/state/sensitive-data).
3434

35+
<div class = "oics-button" style="float: right; margin: 0 0 -15px">
36+
<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_image=gcr.io%2Fcloudshell-images%2Fcloudshell%3Alatest&cloudshell_print=.%2Fmotd&cloudshell_tutorial=.%2Ftutorial.md&cloudshell_working_dir=netapp_active_directory_full&open_in_editor=main.tf" target="_blank">
37+
<img alt="Open in Cloud Shell" src="//gstatic.com/cloudssh/images/open-btn.svg" style="max-height: 44px; margin: 32px auto; max-width: 100%;">
38+
</a>
39+
</div>
3540
## Example Usage - Netapp Active Directory Full
3641

3742

@@ -46,6 +51,7 @@ resource "google_netapp_active_directory" "test_active_directory_full" {
4651
password = "pass"
4752
aes_encryption = false
4853
backup_operators = ["test1", "test2"]
54+
administrators = ["test1", "test2"]
4955
description = "ActiveDirectory is the public representation of the active directory config."
5056
encrypt_dc_connections = false
5157
kdc_hostname = "hostname"
@@ -119,6 +125,10 @@ The following arguments are supported:
119125
(Optional)
120126
Domain user/group accounts to be added to the Backup Operators group of the SMB service. The Backup Operators group allows members to backup and restore files regardless of whether they have read or write access to the files. Comma-separated list.
121127

128+
* `administrators` -
129+
(Optional)
130+
Domain user accounts to be added to the local Administrators group of the SMB service. Comma-separated list of domain users or groups. The Domain Admin group is automatically added when the service joins your domain as a hidden group.
131+
122132
* `security_operators` -
123133
(Optional)
124134
Domain accounts that require elevated privileges such as `SeSecurityPrivilege` to manage security logs. Comma-separated list.

0 commit comments

Comments
 (0)