Skip to content

Commit 3067ede

Browse files
author
Adam Bowen
committed
environment resource can now also take public_key credential
1 parent 288e63b commit 3067ede

File tree

2 files changed

+70
-8
lines changed

2 files changed

+70
-8
lines changed

resource_delphix_environment.go

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ type Environment struct {
1818
address string
1919
toolkitPath string
2020
serverID string
21+
publicKey bool
2122
}
2223

2324
func resourceDelphixEnvironment() *schema.Resource {
@@ -36,7 +37,7 @@ func resourceDelphixEnvironment() *schema.Resource {
3637
},
3738
"user_password": &schema.Schema{
3839
Type: schema.TypeString,
39-
Required: true,
40+
Optional: true,
4041
ForceNew: true,
4142
Sensitive: true,
4243
},
@@ -62,6 +63,11 @@ func resourceDelphixEnvironment() *schema.Resource {
6263
Optional: true,
6364
ForceNew: true,
6465
},
66+
"public_key": &schema.Schema{
67+
Type: schema.TypeBool,
68+
Optional: true,
69+
ForceNew: true,
70+
},
6571
},
6672
}
6773
}
@@ -85,18 +91,28 @@ func resourceDelphixEnvironmentCreate(d *schema.ResourceData, meta interface{})
8591
userPassword: d.Get("user_password").(string),
8692
address: d.Get("address").(string),
8793
toolkitPath: d.Get("toolkit_path").(string),
94+
publicKey: d.Get("public_key").(bool),
8895
}
89-
var reference interface{}
96+
var reference, thisCrendential interface{}
97+
9098
client := meta.(*delphix.Client)
99+
100+
thisCrendential = &delphix.PasswordCredential{
101+
Type: "PasswordCredential",
102+
Password: env.userPassword,
103+
}
104+
if env.publicKey == true {
105+
thisCrendential = &delphix.SystemKeyCredential{
106+
Type: "SystemKeyCredential",
107+
}
108+
}
109+
91110
environmentCreateParams := delphix.HostEnvironmentCreateParameters{
92111
Type: "HostEnvironmentCreateParameters",
93112
PrimaryUser: &delphix.EnvironmentUser{
94-
Type: "EnvironmentUser",
95-
Name: env.userName,
96-
Credential: &delphix.PasswordCredential{
97-
Type: "PasswordCredential",
98-
Password: env.userPassword,
99-
},
113+
Type: "EnvironmentUser",
114+
Name: env.userName,
115+
Credential: thisCrendential,
100116
},
101117
HostEnvironment: &delphix.UnixHostEnvironment{
102118
Type: "UnixHostEnvironment",

resource_delphix_environment_test.go

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,27 @@ func TestAccEnvironmentDoesExistBasicCheck(t *testing.T) {
3232
})
3333
}
3434

35+
func TestAccEnvironmentDoesExistBasicCheckPublicKey(t *testing.T) {
36+
37+
resource.Test(t, resource.TestCase{
38+
PreCheck: func() { testAccPreCheck(t) },
39+
Providers: testAccProviders,
40+
CheckDestroy: testEnvironmentCheckDestroy,
41+
Steps: []resource.TestStep{
42+
resource.TestStep{
43+
Config: testAccCheckEnvironmentConfigPublicKey(&testAccDelphixAdminConfig, &testAccEnvironment),
44+
Check: resource.ComposeTestCheckFunc(
45+
testEnvironmentCheckDoesExist(testAccEnvironment.name),
46+
resource.TestCheckResourceAttr(
47+
"delphix_environment.test_acc_env", "name", testAccEnvironment.name),
48+
resource.TestCheckResourceAttr(
49+
"delphix_environment.test_acc_env", "description", testAccEnvironment.description),
50+
),
51+
},
52+
},
53+
})
54+
}
55+
3556
func TestAccEnvironmentDoesExist_UpdatedName(t *testing.T) {
3657
updatedEnvironmentName := "UpdatedName"
3758
updatedDescription := "UpdatedDescription"
@@ -183,6 +204,31 @@ func testAccCheckEnvironmentConfigImported(c *Config, e *Environment) string {
183204
)
184205
}
185206

207+
func testAccCheckEnvironmentConfigPublicKey(c *Config, e *Environment) string {
208+
return fmt.Sprintf(`
209+
provider "delphix" {
210+
url = "${var.url}"
211+
delphix_admin_username = "%s"
212+
delphix_admin_password = "%s"
213+
}
214+
215+
resource "delphix_environment" "test_acc_env" {
216+
name = "%s"
217+
description = "%s"
218+
address = "%s"
219+
user_name = "%s"
220+
toolkit_path = "%s"
221+
public_key = true
222+
}
223+
224+
variable "url" {
225+
default = "%s"
226+
}
227+
`,
228+
c.username, c.password, e.name, e.description, e.address, e.userName, e.toolkitPath, c.url,
229+
)
230+
}
231+
186232
func testAccCheckEnvironmentConfigUpdatedName(c *Config, e *Environment, n string, d string) string {
187233
return fmt.Sprintf(`
188234
provider "delphix" {

0 commit comments

Comments
 (0)