Skip to content

Commit

Permalink
Sync bitbucket and GitHub
Browse files Browse the repository at this point in the history
  • Loading branch information
carchi8py committed Oct 13, 2022
1 parent a193124 commit d84ee43
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 51 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## 22.10.0
* resource/active_directory: ([#76](https://github.com/NetApp/terraform-provider-netapp-gcp/issues/76))

## 22.8.1
BUG FIXES:
* resource/storage_pool: Fix creation error with shared vpc. ([#69](https://github.com/NetApp/terraform-provider-netapp-gcp/issues/69))
Expand Down
2 changes: 2 additions & 0 deletions gcp/active_directory.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ type operateActiveDirectoryRequest struct {
AesEncryption bool `structs:"aesEncryption"`
Label string `structs:"label"`
AdName string `structs:"adName"`
ManagedAD bool `structs:"managedAD"`
}

// operateActiveDirectoryResult returns the api response for creating/updating an active directory
Expand Down Expand Up @@ -60,6 +61,7 @@ type listActiveDirectoryResult struct {
AesEncryption bool `json:"aesEncryption"`
Label string `json:"label"`
AdName string `json:"adName"`
ManagedAD bool `structs:"managedAD"`
}

type listActiveDirectoryAPIResult struct {
Expand Down
88 changes: 44 additions & 44 deletions gcp/data_source_gcp_active_directory.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package gcp

import (
"fmt"

"github.com/hashicorp/terraform/helper/schema"
)

Expand All @@ -27,7 +25,7 @@ func dataSourceGCPActiveDirectory() *schema.Resource {
Type: schema.TypeString,
Optional: true,
},
"netbios": {
"net_bios": {
Type: schema.TypeString,
Optional: true,
},
Expand All @@ -47,50 +45,52 @@ func dataSourceGCPActiveDirectory() *schema.Resource {
Type: schema.TypeString,
Computed: true,
},
"aes_encryption": {
Type: schema.TypeBool,
Optional: true,
},
"backup_operators": {
Type: schema.TypeSet,
Elem: &schema.Schema{
Type: schema.TypeString,
},
Optional: true,
},
"security_operators": {
Type: schema.TypeSet,
Elem: &schema.Schema{
Type: schema.TypeString,
},
Optional: true,
},
"allow_local_nfs_users_with_ldap": {
Type: schema.TypeBool,
Optional: true,
},
"kdc_ip": {
Type: schema.TypeString,
Optional: true,
},
"ldap_signing": {
Type: schema.TypeBool,
Optional: true,
},
"connection_type": {
Type: schema.TypeString,
Optional: true,
},
"ad_server": {
Type: schema.TypeString,
Optional: true,
},
"managed_ad": {
Type: schema.TypeBool,
Optional: true,
},
},
}
}

func dataSourceGCPActiveDirectoryRead(d *schema.ResourceData, meta interface{}) error {
client := meta.(*Client)
activeDirectory := listActiveDirectoryRequest{}
activeDirectory.Region = d.Get("region").(string)
var res listActiveDirectoryResult
res, err := client.listActiveDirectoryForRegion(activeDirectory)
if err != nil {
return err
}
d.SetId(res.UUID)

if err := d.Set("uuid", res.UUID); err != nil {
return fmt.Errorf("Error reading active directory UUID: %s", err)
}
if err := d.Set("domain", res.Domain); err != nil {
return fmt.Errorf("Error reading active directory domain: %s", err)
}

if err := d.Set("netbios", res.NetBIOS); err != nil {
return fmt.Errorf("Error reading active directory netbios: %s", err)
}

if err := d.Set("organizational_unit", res.OrganizationalUnit); err != nil {
return fmt.Errorf("Error reading active directory organizational_unit: %s", err)
}

if err := d.Set("site", res.Site); err != nil {
return fmt.Errorf("Error reading active directory site: %s", err)
}

if err := d.Set("username", res.Username); err != nil {
return fmt.Errorf("Error reading active directory username: %s", err)
}

if err := d.Set("dns_server", res.DNS); err != nil {
return fmt.Errorf("Error reading active directory dns_server: %s", err)
}

if err := d.Set("region", res.Region); err != nil {
return fmt.Errorf("Error reading active directory region: %s", err)
}
return nil
return resourceGCPActiveDirectoryRead(d, meta)
}
24 changes: 19 additions & 5 deletions gcp/resource_netapp_gcp_active_directory.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,11 @@ func resourceGCPActiveDirectory() *schema.Resource {
Type: schema.TypeString,
Optional: true,
},
"managed_ad": {
Type: schema.TypeBool,
Optional: true,
Default: false,
},
},
}
}
Expand Down Expand Up @@ -162,6 +167,8 @@ func resourceGCPActiveDirectoryCreate(d *schema.ResourceData, meta interface{})
activeDirectory.AdName = v.(string)
}

activeDirectory.ManagedAD = d.Get("managed_ad").(bool)

res, err := client.createActiveDirectory(&activeDirectory)
if err != nil {
log.Print("Error creating active directory")
Expand All @@ -176,18 +183,20 @@ func resourceGCPActiveDirectoryCreate(d *schema.ResourceData, meta interface{})

func resourceGCPActiveDirectoryRead(d *schema.ResourceData, meta interface{}) error {
client := meta.(*Client)
id := d.Id()
activeDirectory := listActiveDirectoryRequest{}
activeDirectory.Region = d.Get("region").(string)
var res listActiveDirectoryResult
res, err := client.listActiveDirectoryForRegion(activeDirectory)
if err != nil {
return err
}
if res.UUID != id {
return fmt.Errorf("Expected active directory with id: %v, Response contained active directory with id: %v",
d.Get("uuid").(string), res.UUID)
}
// Disabling, since it would fail for call from dataSourceGCPVolumeRead
// Unclear if this sanity check is required
// if res.UUID != d.id {
// return fmt.Errorf("Expected active directory with id: %v, Response contained active directory with id: %v",
// d.Get("uuid").(string), res.UUID)
// }
d.SetId(res.UUID)
d.Set("uuid", res.UUID)

if err := d.Set("domain", res.Domain); err != nil {
Expand Down Expand Up @@ -250,6 +259,9 @@ func resourceGCPActiveDirectoryRead(d *schema.ResourceData, meta interface{}) er
return fmt.Errorf("Error reading active directory ad_server: %s", err)
}

if err := d.Set("managed_ad", res.ManagedAD); err != nil {
return fmt.Errorf("Error reading active directory managed_ad: %s", err)
}
return nil
}

Expand Down Expand Up @@ -340,6 +352,8 @@ func resourceGCPActiveDirectoryUpdate(d *schema.ResourceData, meta interface{})
activeDirectory.AdName = v.(string)
}

activeDirectory.ManagedAD = d.Get("managed_ad").(bool)

err := client.updateActiveDirectory(activeDirectory)
if err != nil {
return err
Expand Down
5 changes: 3 additions & 2 deletions website/docs/r/active_directory.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ Creates a new Active Directory connection for a given region. Only one connectio
resource "netapp-gcp_active_directory" "gcp-active-directory" {
provider = netapp-gcp
region = "us-west2"
username = "test_user"
password = "netapp"
username = "test_user"
password = "netapp"
domain = "example.com"
dns_server = "10.0.0.0"
net_bios = "cvsserver"
Expand All @@ -52,6 +52,7 @@ AD connection specific settings:
* `net_bios` - (Required) NetBIOS prefix name of the server that will be created. A random 5-digit suffix is appended automatically (e.g. -A579).
* `aes_encryption` - (Optional) Enables AES-128 and AES-256 encryption for Kerberos-based communication with Active Directory. Default is false.
* `ldap_signing` - (Optional) Enables LDAP siging. Default is false.
* `managed_ad` - (Optional) Flags this configuration as Google ManagedAD configuration. Please see https://cloud.google.com/architecture/partners/netapp-cloud-volumes/managing-active-directory-connections?hl=en_US#connect_to_managed_microsoft_ad

User credentials for Domain join:
* `username` - (Required) Username of an account permitted to create computer objects in your Active Directory.
Expand Down

0 comments on commit d84ee43

Please sign in to comment.