Skip to content

Commit a70d9f7

Browse files
authored
Move the password check for SDC (#212)
1 parent 28b9e53 commit a70d9f7

File tree

5 files changed

+30
-19
lines changed

5 files changed

+30
-19
lines changed

powerflex/helper/sdc_host_dpkg.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import (
2020
"context"
2121
"errors"
2222
"fmt"
23-
"path/filepath"
2423
"strings"
2524
"terraform-provider-powerflex/client"
2625
"terraform-provider-powerflex/powerflex/models"
@@ -84,7 +83,7 @@ func (r *SdcHostResource) CreateUbuntu(ctx context.Context, plan models.SdcHostM
8483

8584
// upload sw
8685
scpProv := client.NewScpProvisioner(sshP)
87-
pkgTarget := filepath.Join(dir, "emc-sdc-package.tar")
86+
pkgTarget := strings.TrimSuffix(dir, "/") + "/" + "emc-sdc-package.tar"
8887
err := scpProv.Upload(plan.Pkg.ValueString(), pkgTarget, "")
8988
if err != nil {
9089
respDiagnostics.AddError(

powerflex/helper/sdc_host_esxi.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ package helper
1919
import (
2020
"context"
2121
"fmt"
22-
"path/filepath"
2322
"regexp"
2423
"strings"
2524
"terraform-provider-powerflex/client"
@@ -78,7 +77,7 @@ func (r *SdcHostResource) CreateEsxi(ctx context.Context, plan models.SdcHostMod
7877
}
7978
defer sshP.Close()
8079

81-
pkgTarget := filepath.Join(dir, "emc-sdc-package.zip")
80+
pkgTarget := strings.TrimSuffix(dir, "/") + "/" + "emc-sdc-package.zip"
8281
if !plan.UseRemotePath.ValueBool() {
8382
// upload sw
8483
scpProv := client.NewScpProvisioner(sshP)

powerflex/helper/sdc_host_rpm.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ package helper
1919
import (
2020
"context"
2121
"fmt"
22-
"path/filepath"
2322
"strings"
2423
"terraform-provider-powerflex/client"
2524
"terraform-provider-powerflex/powerflex/models"
@@ -36,7 +35,7 @@ func (r *SdcHostResource) CreateRhel(ctx context.Context, plan models.SdcHostMod
3635
if !plan.UseRemotePath.ValueBool() {
3736
// upload sw
3837
scpProv := client.NewScpProvisioner(sshP)
39-
pkgTarget := filepath.Join(dir, "emc-sdc-package.rpm")
38+
pkgTarget := strings.TrimSuffix(dir, "/") + "/" + "emc-sdc-package.rpm"
4039
err := scpProv.Upload(plan.Pkg.ValueString(), pkgTarget, "")
4140
if err != nil {
4241
respDiagnostics.AddError(

powerflex/provider/sdc_host_resource.go

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -95,18 +95,6 @@ func (r *sdcHostResource) ValidateConfig(ctx context.Context, req resource.Valid
9595
)
9696
}
9797

98-
if !cfg.OS.IsUnknown() && cfg.OS.ValueString() == "windows" && !cfg.Remote.IsNull() {
99-
var remote models.SdcHostRemoteModel
100-
cfg.Remote.As(ctx, &remote, basetypes.ObjectAsOptions{UnhandledNullAsEmpty: true, UnhandledUnknownAsEmpty: true})
101-
102-
if remote.Password == nil {
103-
resp.Diagnostics.AddAttributeError(
104-
path.Root("remote").AtName("password"),
105-
"Password is required for Windows SDC",
106-
"",
107-
)
108-
}
109-
}
11098
}
11199

112100
func (r *sdcHostResource) Schema(_ context.Context, _ resource.SchemaRequest, resp *resource.SchemaResponse) {
@@ -402,6 +390,19 @@ func (r *sdcHostResource) Create(ctx context.Context, req resource.CreateRequest
402390
return
403391
}
404392

393+
if !plan.OS.IsUnknown() && plan.OS.ValueString() == "windows" && !plan.Remote.IsNull() {
394+
var remote models.SdcHostRemoteModel
395+
plan.Remote.As(ctx, &remote, basetypes.ObjectAsOptions{UnhandledNullAsEmpty: true, UnhandledUnknownAsEmpty: true})
396+
397+
if remote.Password == nil {
398+
resp.Diagnostics.AddAttributeError(
399+
path.Root("remote").AtName("password"),
400+
"Password is required for Windows SDC",
401+
"",
402+
)
403+
return
404+
}
405+
}
405406
//Checking that SDC exist or not
406407
allSdcs, _ := r.system.GetSdc()
407408
for _, sdcData := range allSdcs {
@@ -599,6 +600,19 @@ func (r *sdcHostResource) Delete(ctx context.Context, req resource.DeleteRequest
599600
if resp.Diagnostics.HasError() {
600601
return
601602
}
603+
if !state.OS.IsUnknown() && state.OS.ValueString() == "windows" && !state.Remote.IsNull() {
604+
var remote models.SdcHostRemoteModel
605+
state.Remote.As(ctx, &remote, basetypes.ObjectAsOptions{UnhandledNullAsEmpty: true, UnhandledUnknownAsEmpty: true})
606+
607+
if remote.Password == nil {
608+
resp.Diagnostics.AddAttributeError(
609+
path.Root("remote").AtName("password"),
610+
"Password is required for Windows SDC",
611+
"",
612+
)
613+
return
614+
}
615+
}
602616

603617
resHelper := helper.SdcHostResource{
604618
System: r.system,

powerflex/provider/sdc_host_resource_win_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ func TestAccResourceSDCHostNegative(t *testing.T) {
3636
//Create
3737
{
3838
Config: ProviderConfigForTesting + SDCHostConfig1,
39-
ExpectError: regexp.MustCompile(`.*Password is required for Windows SDC.*`),
39+
ExpectError: regexp.MustCompile(`.*Exactly one of these attributes must be configured.*`),
4040
},
4141
{
4242
Config: ProviderConfigForTesting + SDCHostConfig2,

0 commit comments

Comments
 (0)