Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Resource] Update workspace creation #167

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ toolchain go1.22.5
require (
github.com/IBM-Cloud/bluemix-go v0.0.0-20240719075425-078fcb3a55be
github.com/IBM-Cloud/container-services-go-sdk v0.0.0-20240725064144-454a2ae23113
github.com/IBM-Cloud/power-go-client v1.7.0
github.com/IBM-Cloud/power-go-client v1.8.1
github.com/IBM/apigateway-go-sdk v0.0.0-20210714141226-a5d5d49caaca
github.com/IBM/appconfiguration-go-admin-sdk v0.3.0
github.com/IBM/appid-management-go-sdk v0.0.0-20210908164609-dd0e0eaf732f
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ github.com/IBM-Cloud/bluemix-go v0.0.0-20240719075425-078fcb3a55be/go.mod h1:/7h
github.com/IBM-Cloud/container-services-go-sdk v0.0.0-20240725064144-454a2ae23113 h1:f2Erqfea1dKpaTFagTJM6W/wnD3JGq/Vn9URh8nuRwk=
github.com/IBM-Cloud/container-services-go-sdk v0.0.0-20240725064144-454a2ae23113/go.mod h1:xUQL9SGAjoZFd4GNjrjjtEpjpkgU7RFXRyHesbKTjiY=
github.com/IBM-Cloud/ibm-cloud-cli-sdk v0.5.3/go.mod h1:RiUvKuHKTBmBApDMUQzBL14pQUGKcx/IioKQPIcRQjs=
github.com/IBM-Cloud/power-go-client v1.7.0 h1:/GuGwPMTKoCZACfnwt7b6wKr4v32q1VO1AMFGNETRN4=
github.com/IBM-Cloud/power-go-client v1.7.0/go.mod h1:9izycYAmNQ+NAdVPXDC3fHYxqWLjlR2YiwqKYveMv5Y=
github.com/IBM-Cloud/power-go-client v1.8.1 h1:tx1aPJmIQrNru1MD1VHGNasGx3eRIs0zzPZ0KvdFQrg=
github.com/IBM-Cloud/power-go-client v1.8.1/go.mod h1:N4RxrsMUvBQjSQ/qPk0iMZ8zK+fZPRTnHi/gTaASw0g=
github.com/IBM-Cloud/softlayer-go v1.0.5-tf h1:koUAyF9b6X78lLLruGYPSOmrfY2YcGYKOj/Ug9nbKNw=
github.com/IBM-Cloud/softlayer-go v1.0.5-tf/go.mod h1:6HepcfAXROz0Rf63krk5hPZyHT6qyx2MNvYyHof7ik4=
github.com/IBM/apigateway-go-sdk v0.0.0-20210714141226-a5d5d49caaca h1:crniVcf+YcmgF03NmmfonXwSQ73oJF+IohFYBwknMxs=
Expand Down
1 change: 1 addition & 0 deletions ibm/service/power/ibm_pi_constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ const (
Arg_SysType = "pi_sys_type"
Arg_TargetStorageTier = "pi_target_storage_tier"
Arg_UserData = "pi_user_data"
Arg_UserTags = "pi_user_tags"
Arg_VirtualCoresAssigned = "pi_virtual_cores_assigned"
Arg_VirtualOpticalDevice = "pi_virtual_optical_device"
Arg_VolumeCloneName = "pi_volume_clone_name"
Expand Down
36 changes: 34 additions & 2 deletions ibm/service/power/resource_ibm_pi_workspace.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,23 @@ func ResourceIBMPIWorkspace() *schema.Resource {
Type: schema.TypeString,
ValidateFunc: validation.NoZeroValues,
},
Arg_UserTags: {
Description: "The user tags attached to this resource.",
Elem: &schema.Schema{Type: schema.TypeString},
ForceNew: true,
Optional: true,
Type: schema.TypeList,
},

// Attributes
Attr_CRN: {
Computed: true,
Description: "The Workspace crn.",
Type: schema.TypeString,
},
Attr_WorkspaceDetails: {
Computed: true,
Deprecated: "This field is deprecated, use crn instead.",
Description: "Workspace information.",
Type: schema.TypeMap,
},
Expand Down Expand Up @@ -95,6 +108,23 @@ func resourceIBMPIWorkspaceCreate(ctx context.Context, d *schema.ResourceData, m
return diag.FromErr(err)
}

// Add user tags for newly created workspace
if tags, ok := d.GetOk(Arg_UserTags); ok {
if len(tags.([]interface{})) > 0 {
userTags := flex.ExpandStringList(tags.([]interface{}))
gtClient, err := meta.(conns.ClientSession).GlobalTaggingAPI()
if err != nil {
log.Printf("[ERROR] Error getting global tagging client settings: %s", err)
return diag.FromErr(err)
}
_, err = gtClient.Tags().AttachTags(*controller.CRN, userTags)
if err != nil {
log.Printf(
"[ERROR] The resource instance has failed updating user tags (%s) err: %s", d.Id(), err)
return diag.FromErr(err)
}
}
}
return resourceIBMPIWorkspaceRead(ctx, d, meta)
}

Expand Down Expand Up @@ -137,11 +167,13 @@ func resourceIBMPIWorkspaceRead(ctx context.Context, d *schema.ResourceData, met
return diag.FromErr(err)
}
d.Set(Arg_Name, controller.Name)
d.Set(Attr_CRN, controller.CRN)

// Deprecated Workspace Details Set
wsDetails := map[string]interface{}{
Attr_CreationDate: controller.CreatedAt,
Attr_CRN: controller.TargetCRN,
Attr_CRN: controller.CRN,
}

d.Set(Attr_WorkspaceDetails, flex.Flatten(wsDetails))

return nil
Expand Down
4 changes: 3 additions & 1 deletion website/docs/r/pi_workspace.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,15 @@ Review the argument references that you can specify for your resource.
- `pi_name` - (Required, String) A descriptive name used to identify the workspace.
- `pi_plan` - (Optional, String) Plan associated with the offering; Valid values are `public` or `private`. The default value is `public`.
- `pi_resource_group_id` - (Required, String) The ID of the resource group where you want to create the workspace. You can retrieve the value from data source `ibm_resource_group`.
- `pi_user_tags` - (Optional, List) The user tags attached to this resource.

## Attribute reference

In addition to all argument reference listed, you can access the following attribute references after your resource source is created.

- `id` - (String) Workspace ID.
- `workspace_details` - (Map) Workspace information.
- `crn` - (String) Workspace crn.
- `workspace_details` - (Deprecated, Map) Workspace information.

Nested schema for `workspace_details`:
- `creation_date` - (String) Date of workspace creation.
Expand Down
Loading