Skip to content

Commit

Permalink
Add resource nexus_security_ldap_order
Browse files Browse the repository at this point in the history
  • Loading branch information
Nosmoht committed Aug 3, 2020
1 parent a0e838b commit 5ea7d3b
Show file tree
Hide file tree
Showing 4 changed files with 125 additions and 9 deletions.
24 changes: 24 additions & 0 deletions README.md
Expand Up @@ -19,6 +19,7 @@
- [nexus_repository](#resource-nexus_repository)
- [nexus_role](#resource-nexus_role)
- [nexus_security_ldap](#resource-nexus_security_ldap)
- [nexus_security_ldap_orger](#resource-nexus-security-ldap-order)
- [nexus_security_realms](#resource-nexus_security_realms)
- [nexus_script](#resource-nexus_script)
- [nexus_user](#resource-nexus_user)
Expand Down Expand Up @@ -549,6 +550,29 @@ resource "nexus_security_ldap" "acceptance" {
}
```

#### Resource nexus_security_ldap_order

Set order of LDAP server

```hcl
resource "nexus_security_ldap" "server1" {
...
name = "server1"
}
resource "nexus_security_ldap" "server2" {
...
name = "server2"
}
resource "nexus_security_ldap_order" {
order = [
nexus_security_ldap.server1.name,
nexus_security_ldap.server2.name,
]
}
```

#### Resource nexus_security_realms

Activate security realms
Expand Down
19 changes: 10 additions & 9 deletions nexus/provider.go
Expand Up @@ -18,15 +18,16 @@ func Provider() terraform.ResourceProvider {
"nexus_user": dataSourceUser(),
},
ResourcesMap: map[string]*schema.Resource{
"nexus_blobstore": resourceBlobstore(),
"nexus_content_selector": resourceContentSelector(),
"nexus_privilege": resourcePrivilege(),
"nexus_repository": resourceRepository(),
"nexus_role": resourceRole(),
"nexus_script": resourceScript(),
"nexus_security_ldap": resourceSecurityLDAP(),
"nexus_security_realms": resourceSecurityRealms(),
"nexus_user": resourceUser(),
"nexus_blobstore": resourceBlobstore(),
"nexus_content_selector": resourceContentSelector(),
"nexus_privilege": resourcePrivilege(),
"nexus_repository": resourceRepository(),
"nexus_role": resourceRole(),
"nexus_script": resourceScript(),
"nexus_security_ldap": resourceSecurityLDAP(),
"nexus_security_ldap_order": resourceSecurityLDAPOrder(),
"nexus_security_realms": resourceSecurityRealms(),
"nexus_user": resourceUser(),
},
Schema: map[string]*schema.Schema{
"insecure": {
Expand Down
53 changes: 53 additions & 0 deletions nexus/resource_security_ldap_order.go
@@ -0,0 +1,53 @@
package nexus

import (
nexus "github.com/datadrivers/go-nexus-client"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
)

func resourceSecurityLDAPOrder() *schema.Resource {
return &schema.Resource{
Create: resourceSecurityLDAPOrderCreate,
Read: resourceSecurityLDAPOrderRead,
Update: resourceSecurityLDAPOrderUpdate,
Delete: resourceSecurityLDAPOrderDelete,

Schema: map[string]*schema.Schema{
"order": {
Elem: &schema.Schema{
Type: schema.TypeString,
},
Required: true,
Type: schema.TypeList,
},
},
}
}

func resourceSecurityLDAPOrderCreate(d *schema.ResourceData, m interface{}) error {
client := m.(nexus.Client)
order := interfaceSliceToStringSlice(d.Get("order").([]interface{}))
if err := client.LDAPChangeOrder(order); err != nil {
return err
}

d.SetId("change-order")
d.Set("order", order)

return resourceSecurityLDAPOrderRead(d, m)
}

func resourceSecurityLDAPOrderRead(d *schema.ResourceData, m interface{}) error {
// d.Set("order", d.Get("order"))

return nil
}

func resourceSecurityLDAPOrderUpdate(d *schema.ResourceData, m interface{}) error {
return resourceSecurityLDAPOrderCreate(d, m)
}

func resourceSecurityLDAPOrderDelete(d *schema.ResourceData, m interface{}) error {
// return fmt.Errorf("Nexus API does not support deleting LDAP server order")
return nil
}
38 changes: 38 additions & 0 deletions nexus/resource_security_ldap_order_test.go
@@ -0,0 +1,38 @@
package nexus

import (
"fmt"
"log"
"strings"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
)

func TestAccResourceSecurityLDAPOrder(t *testing.T) {
resName := "nexus_security_ldap_order.acceptance"
ldap := testAccResourceSecurityLDAP()
log.Println(testAccResourceSecurityLDAPConfig(ldap) + testAccResourceSecurityLDAPOrder([]string{fmt.Sprintf("nexus_security_ldap.%s.name", ldap.Name)}))
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccResourceSecurityLDAPConfig(ldap) + testAccResourceSecurityLDAPOrder([]string{fmt.Sprintf("nexus_security_ldap.%s.name", ldap.Name)}),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(resName, "order.#", "1"),
resource.TestCheckResourceAttr(resName, "order.0", ldap.Name),
),
},
},
},
)
}

func testAccResourceSecurityLDAPOrder(order []string) string {
return fmt.Sprintf(`
resource "nexus_security_ldap_order" "acceptance" {
order = [%s]
}
`, strings.Join(order, ", "))
}

0 comments on commit 5ea7d3b

Please sign in to comment.