Skip to content

Commit 5eb9e27

Browse files
release-1.0.29-bugfix
1 parent 6ad8023 commit 5eb9e27

6 files changed

Lines changed: 83 additions & 9 deletions

File tree

‎docs/resources/delivery_group.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ Optional:
432432

433433
Read-Only:
434434

435-
- `id` (String) ID of the resource location.
435+
- `id` (String) ID of the access policy.
436436

437437
<a id="nestedatt--custom_access_policies--exclude_criteria_filters"></a>
438438
### Nested Schema for `custom_access_policies.exclude_criteria_filters`
@@ -474,7 +474,7 @@ Optional:
474474

475475
Read-Only:
476476

477-
- `id` (String) ID of the resource location.
477+
- `id` (String) ID of the access policy.
478478

479479
<a id="nestedatt--default_access_policies--exclude_criteria_filters"></a>
480480
### Nested Schema for `default_access_policies.exclude_criteria_filters`

‎internal/daas/delivery_group/delivery_group_resource_model.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -903,7 +903,7 @@ func (DeliveryGroupAccessPolicyModel) GetSchema() schema.NestedAttributeObject {
903903
return schema.NestedAttributeObject{
904904
Attributes: map[string]schema.Attribute{
905905
"id": schema.StringAttribute{
906-
Description: "ID of the resource location.",
906+
Description: "ID of the access policy.",
907907
Computed: true,
908908
PlanModifiers: []planmodifier.String{
909909
stringplanmodifier.UseStateForUnknown(),

‎internal/quickcreate/qcs_deployment/aws_workspaces_deployment_resource.go‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,14 @@ func (r *awsWorkspacesDeploymentResource) Create(ctx context.Context, req resour
115115
"Error creating AWS WorkSpaces Deployment: "+plan.Name.ValueString(),
116116
"Number of workspaces created does not match the number of workspaces in the plan",
117117
)
118+
plan = plan.RefreshPropertyValues(ctx, &resp.Diagnostics, *deploymentResult)
119+
120+
// Set state to populated data
121+
diags = resp.State.Set(ctx, plan)
122+
resp.Diagnostics.Append(diags...)
118123
return
119124
}
125+
120126
if len(workspaces) > 0 {
121127
if plan.UserDecoupledWorkspaces.ValueBool() {
122128
deploymentWorkspaces := deploymentResult.GetWorkspaces()
@@ -129,6 +135,11 @@ func (r *awsWorkspacesDeploymentResource) Create(ctx context.Context, req resour
129135
err = updateMachinesMaintenanceModeWithUsername(ctx, &resp.Diagnostics, r.client, deploymentResult, workspaces)
130136
}
131137
if err != nil {
138+
plan = plan.RefreshPropertyValues(ctx, &resp.Diagnostics, *deploymentResult)
139+
140+
// Set state to populated data
141+
diags = resp.State.Set(ctx, plan)
142+
resp.Diagnostics.Append(diags...)
132143
return
133144
}
134145
}

‎internal/quickcreate/qcs_deployment/aws_workspaces_deployment_resource_model.go‎

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,14 @@ package qcs_deployment
44
import (
55
"context"
66
"regexp"
7+
"strings"
78

89
"github.com/citrix/citrix-daas-rest-go/citrixquickcreate"
910
"github.com/citrix/terraform-provider-citrix/internal/util"
11+
"github.com/citrix/terraform-provider-citrix/internal/util/planmodifiers"
1012
"github.com/citrix/terraform-provider-citrix/internal/validators"
1113
"github.com/hashicorp/terraform-plugin-framework-validators/int64validator"
14+
"github.com/hashicorp/terraform-plugin-framework-validators/listvalidator"
1215
"github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator"
1316
"github.com/hashicorp/terraform-plugin-framework/diag"
1417
"github.com/hashicorp/terraform-plugin-framework/path"
@@ -94,6 +97,10 @@ type AwsWorkspacesDeploymentWorkspaceModel struct {
9497
}
9598

9699
func (r AwsWorkspacesDeploymentWorkspaceModel) GetKey() string {
100+
// For user-assigned workspaces, return the username. For user decoupled workspaces, return the machine ID
101+
if !r.Username.IsNull() {
102+
return strings.ToLower(r.Username.ValueString())
103+
}
97104
return r.MachineId.ValueString()
98105
}
99106

@@ -134,28 +141,28 @@ func (AwsWorkspacesDeploymentWorkspaceModel) GetSchema() schema.NestedAttributeO
134141
Description: "Id of the AWS WorkSpaces machine.",
135142
Computed: true,
136143
PlanModifiers: []planmodifier.String{
137-
stringplanmodifier.UseStateForUnknown(),
144+
planmodifiers.UseStateIfUnknownAndStateValueExists(),
138145
},
139146
},
140147
"machine_id": schema.StringAttribute{
141148
Description: "Id of the machine.",
142149
Computed: true,
143150
PlanModifiers: []planmodifier.String{
144-
stringplanmodifier.UseStateForUnknown(),
151+
planmodifiers.UseStateIfUnknownAndStateValueExists(),
145152
},
146153
},
147154
"machine_name": schema.StringAttribute{
148155
Description: "Name of the machine.",
149156
Computed: true,
150157
PlanModifiers: []planmodifier.String{
151-
stringplanmodifier.UseStateForUnknown(),
158+
planmodifiers.UseStateIfUnknownAndStateValueExists(),
152159
},
153160
},
154161
"broker_machine_id": schema.StringAttribute{
155162
Description: "GUID identifier of the machine.",
156163
Computed: true,
157164
PlanModifiers: []planmodifier.String{
158-
stringplanmodifier.UseStateForUnknown(),
165+
planmodifiers.UseStateIfUnknownAndStateValueExists(),
159166
},
160167
},
161168
},
@@ -177,7 +184,7 @@ func (workspace AwsWorkspacesDeploymentWorkspaceModel) RefreshListItem(ctx conte
177184

178185
if desktop.GetUsername() == "" {
179186
workspace.Username = types.StringNull()
180-
} else {
187+
} else if !strings.EqualFold(workspace.Username.ValueString(), desktop.GetUsername()) {
181188
workspace.Username = types.StringValue(desktop.GetUsername())
182189
}
183190

@@ -344,6 +351,9 @@ func (AwsWorkspacesDeploymentResourceModel) GetSchema() schema.Schema {
344351
Description: "Set of workspaces with assigned users.",
345352
Optional: true,
346353
NestedObject: AwsWorkspacesDeploymentWorkspaceModel{}.GetSchema(),
354+
Validators: []validator.List{
355+
listvalidator.SizeAtLeast(1),
356+
},
347357
},
348358
},
349359
}
@@ -395,7 +405,12 @@ func (r AwsWorkspacesDeploymentResourceModel) RefreshPropertyValues(ctx context.
395405

396406
r.UserDecoupledWorkspaces = types.BoolValue(deployment.GetUserDecoupledWorkspaces())
397407

398-
r.Workspaces = util.RefreshListValueProperties[AwsWorkspacesDeploymentWorkspaceModel, citrixquickcreate.AwsEdcDeploymentMachine](ctx, diagnostics, r.Workspaces, deployment.GetWorkspaces(), util.GetQcsAwsWorkspacesWithMachineIdKey)
408+
clientKey := util.GetQcsAwsWorkspacesWithUsernameKey
409+
if deployment.GetUserDecoupledWorkspaces() {
410+
clientKey = util.GetQcsAwsWorkspacesWithMachineIdKey
411+
}
412+
413+
r.Workspaces = util.RefreshListValueProperties[AwsWorkspacesDeploymentWorkspaceModel, citrixquickcreate.AwsEdcDeploymentMachine](ctx, diagnostics, r.Workspaces, deployment.GetWorkspaces(), clientKey)
399414

400415
return r
401416
}

‎internal/util/common.go‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -853,6 +853,10 @@ func GetQcsAwsWorkspacesWithMachineIdKey(remote citrixquickcreate.AwsEdcDeployme
853853
return remote.GetMachineId()
854854
}
855855

856+
func GetQcsAwsWorkspacesWithUsernameKey(remote citrixquickcreate.AwsEdcDeploymentMachine) string {
857+
return strings.ToLower(remote.GetUsername())
858+
}
859+
856860
func GetOrchestrationAutoscalePluginKey(remote citrixorchestration.AutoscaleGroupPluginModel) string {
857861
return strconv.Itoa(int(remote.GetUid()))
858862
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package planmodifiers
2+
3+
import (
4+
"context"
5+
6+
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
7+
)
8+
9+
func UseStateIfUnknownAndStateValueExists() planmodifier.String {
10+
return useStateIfUnknownAndStateValueExists{}
11+
}
12+
13+
// useStateForUnknownModifier implements the plan modifier.
14+
type useStateIfUnknownAndStateValueExists struct{}
15+
16+
// Description returns a human-readable description of the plan modifier.
17+
func (m useStateIfUnknownAndStateValueExists) Description(_ context.Context) string {
18+
return "Once set, the value of this attribute in state will not change."
19+
}
20+
21+
// MarkdownDescription returns a markdown description of the plan modifier.
22+
func (m useStateIfUnknownAndStateValueExists) MarkdownDescription(_ context.Context) string {
23+
return "Once set, the value of this attribute in state will not change."
24+
}
25+
26+
// PlanModifyString implements the plan modification logic.
27+
func (m useStateIfUnknownAndStateValueExists) PlanModifyString(ctx context.Context, req planmodifier.StringRequest, resp *planmodifier.StringResponse) {
28+
// Do nothing if there is no state (resource is being created).
29+
if req.StateValue.IsNull() {
30+
return
31+
}
32+
33+
// Do nothing if there is a known planned value.
34+
if !req.PlanValue.IsUnknown() {
35+
return
36+
}
37+
38+
// Do nothing if there is an unknown configuration value, otherwise interpolation gets messed up.
39+
if req.ConfigValue.IsUnknown() {
40+
return
41+
}
42+
43+
resp.PlanValue = req.StateValue
44+
}

0 commit comments

Comments
 (0)