Skip to content

Commit

Permalink
Update based on changes and rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
Dylan-Christopherson committed Jan 9, 2025
1 parent 0acc114 commit c7a4686
Show file tree
Hide file tree
Showing 10 changed files with 109 additions and 83 deletions.
15 changes: 10 additions & 5 deletions examples/ibm-sdsaas/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,10 @@ resource "ibm_sds_volume" "sds_volume_instance" {

| Name | Description |
|------|-------------|
| host_mappings | List of host details that volume is mapped to. |
| bandwidth | The maximum bandwidth (in megabits per second) for the volume. |
| created_at | The date and time that the volume was created. |
| hosts | List of host details that volume is mapped to. |
| iops | Iops The maximum I/O operations per second (IOPS) for this volume. |
| resource_type | The resource type of the volume. |
| status | The current status of the volume. |
| status_reasons | Reasons for the current status of the volume. |
Expand All @@ -55,7 +57,7 @@ resource "ibm_sds_volume" "sds_volume_instance" {
resource "ibm_sds_host" "sds_host_instance" {
name = var.sds_host_name
nqn = var.sds_host_nqn
volume_mappings = var.sds_host_volume_mappings
volumes = var.sds_host_volumes
}
```

Expand All @@ -66,19 +68,22 @@ resource "ibm_sds_host" "sds_host_instance" {
| ibmcloud\_api\_key | IBM Cloud API key | `string` | true |
| name | The name for this host. The name must not be used by another host. If unspecified, the name will be a hyphenated list of randomly-selected words. | `string` | false |
| nqn | The NQN of the host configured in customer's environment. | `string` | true |
| volume_mappings | The host-to-volume map. | `list()` | false |
| volumes | The host-to-volume map. | `list()` | false |

#### Outputs

| Name | Description |
|------|-------------|
| created_at | The date and time that the host was created. |
| service_instance_id | The service instance ID this host should be created in. |


## Assumptions

The `IBMCLOUD_SDS_ENDPOINT` is required to be set by the user before running the terraform commands. This is the endpoint provided to customers to perform operations against their service.
1. TODO

## Notes

1. TODO

## Requirements

Expand Down
4 changes: 2 additions & 2 deletions examples/ibm-sdsaas/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ resource "ibm_sds_host" "sds_host_instance" {

name = var.sds_host_name
nqn = var.sds_host_nqn
volume_mappings {
volumes {
volume_id = ibm_sds_volume.sds_volume_instance_1.id
volume_name = ibm_sds_volume.sds_volume_instance_1.name
}
volume_mappings {
volumes {
volume_id = ibm_sds_volume.sds_volume_instance_2.id
volume_name = ibm_sds_volume.sds_volume_instance_2.name
}
Expand Down
19 changes: 10 additions & 9 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/IBM-Cloud/terraform-provider-ibm

go 1.22.5
go 1.23.0

toolchain go1.23.2

Expand Down Expand Up @@ -39,7 +39,7 @@ require (
github.com/IBM/sarama v1.41.2
github.com/IBM/scc-go-sdk/v5 v5.4.1
github.com/IBM/schematics-go-sdk v0.3.0
github.com/IBM/sds-go-sdk v0.0.0
github.com/IBM/sds-go-sdk v0.0.3
github.com/IBM/secrets-manager-go-sdk/v2 v2.0.7
github.com/IBM/vmware-go-sdk v0.1.2
github.com/IBM/vpc-beta-go-sdk v0.8.0
Expand Down Expand Up @@ -101,11 +101,10 @@ require (
github.com/emicklei/go-restful/v3 v3.12.1 // indirect
github.com/evanphx/json-patch/v5 v5.9.0 // indirect
github.com/fatih/color v1.16.0 // indirect
github.com/frankban/quicktest v1.14.3 // indirect
github.com/fsnotify/fsnotify v1.8.0 // indirect
github.com/fxamacker/cbor/v2 v2.7.0 // indirect
github.com/gabriel-vasile/mimetype v1.4.6 // indirect
github.com/go-jose/go-jose/v3 v3.0.3 // indirect
github.com/go-logr/logr v1.4.1 // indirect
github.com/go-jose/go-jose/v4 v4.0.1 // indirect
github.com/go-logr/logr v1.4.2 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-openapi/analysis v0.21.5 // indirect
github.com/go-openapi/errors v0.22.0 // indirect
Expand Down Expand Up @@ -200,10 +199,12 @@ require (
github.com/vmihailenco/msgpack v4.0.4+incompatible // indirect
github.com/vmihailenco/msgpack/v5 v5.4.1 // indirect
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect
github.com/zclconf/go-cty v1.14.1 // indirect
github.com/x448/float16 v0.8.4 // indirect
github.com/zclconf/go-cty v1.15.0 // indirect
go.mongodb.org/mongo-driver v1.17.1 // indirect
go.opentelemetry.io/otel v1.14.0 // indirect
go.opentelemetry.io/otel/trace v1.14.0 // indirect
go.opentelemetry.io/otel v1.28.0 // indirect
go.opentelemetry.io/otel/metric v1.28.0 // indirect
go.opentelemetry.io/otel/trace v1.28.0 // indirect
go.uber.org/ratelimit v0.2.0 // indirect
go.uber.org/zap v1.27.0 // indirect
golang.org/x/mod v0.21.0 // indirect
Expand Down
12 changes: 3 additions & 9 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,8 @@ github.com/IBM/scc-go-sdk/v5 v5.4.1 h1:RXIuxOo9/hxkWyHCI69ae+KIJgSbXcAkJwTEl+fO3
github.com/IBM/scc-go-sdk/v5 v5.4.1/go.mod h1:2xQTDgNXG5QMEfQxBDKB067z+5ha6OgcaKCTcdGDAo8=
github.com/IBM/schematics-go-sdk v0.3.0 h1:Vwxw85SONflakiBsNHAfViKLyp9zJiH5/hh6SewOP5Q=
github.com/IBM/schematics-go-sdk v0.3.0/go.mod h1:Tw2OSAPdpC69AxcwoyqcYYaGTTW6YpERF9uNEU+BFRQ=
github.com/IBM/sds-go-sdk v0.0.0 h1:N269p6vCIDSzJh2dy+hLeSVExH9ZB2yLmBnZZB+3HMs=
github.com/IBM/sds-go-sdk v0.0.0/go.mod h1:YMEsGRcyYRd1eYM0DEZPucVsRwPbzWoqVDczXIJInOY=
github.com/IBM/sds-go-sdk v0.0.3 h1:AlC2SOFdiD8hPHei7DIcwNLNq2ami3jDvb0MxZLpIE0=
github.com/IBM/sds-go-sdk v0.0.3/go.mod h1:mUak/6lrP0H7Pr5XBoZfosPe92cmV4emWMI4amRvAhQ=
github.com/IBM/secrets-manager-go-sdk/v2 v2.0.7 h1:5lKt1rHuKaAaiZtbPfsF8dgiko/gGbVgreiut3zU128=
github.com/IBM/secrets-manager-go-sdk/v2 v2.0.7/go.mod h1:RglK3v6CPe3T1myRtQCD6z+nBygXvNJwufAon0qcZok=
github.com/IBM/vmware-go-sdk v0.1.2 h1:5lKWFyInWz9e2hwGsoFTEoLa1jYkD30SReN0fQ10w9M=
Expand Down Expand Up @@ -372,8 +372,6 @@ github.com/fxamacker/cbor/v2 v2.7.0/go.mod h1:pxXPTn3joSm21Gbwsv0w9OSA2y1HFR9qXE
github.com/gabriel-vasile/mimetype v1.4.3/go.mod h1:d8uq/6HKRL6CGdk+aubisF/M5GcPfT7nKyLpA0lbSSk=
github.com/gabriel-vasile/mimetype v1.4.6 h1:3+PzJTKLkvgjeTbts6msPJt4DixhT4YtFNf1gtGe3zc=
github.com/gabriel-vasile/mimetype v1.4.6/go.mod h1:JX1qVKqZd40hUPpAfiNTe0Sne7hdfKSbOqqmkq8GCXc=
github.com/gammazero/deque v0.0.0-20190130191400-2afb3858e9c7/go.mod h1:GeIq9qoE43YdGnDXURnmKTnGg15pQz4mYkXSTChbneI=
github.com/gammazero/workerpool v0.0.0-20190406235159-88d534f22b56/go.mod h1:w9RqFVO2BM3xwWEcAB8Fwp0OviTBBEiRmSBDfbXnd3w=
github.com/getkin/kin-openapi v0.76.0/go.mod h1:660oXbgy5JFMKreazJaQTw7o+X00qeSyhcnluiMv+Xg=
github.com/ghodss/yaml v0.0.0-20150909031657-73d445a93680/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
Expand Down Expand Up @@ -1274,9 +1272,6 @@ go.mongodb.org/mongo-driver v1.11.3/go.mod h1:PTSz5yu21bkT/wXpkS7WR5f0ddqw5queth
go.mongodb.org/mongo-driver v1.14.0/go.mod h1:Vzb0Mk/pa7e6cWw85R4F/endUC3u0U9jGcNU603k65c=
go.mongodb.org/mongo-driver v1.17.1 h1:Wic5cJIwJgSpBhe3lx3+/RybR5PiYRMpVFgO7cOHyIM=
go.mongodb.org/mongo-driver v1.17.1/go.mod h1:wwWm/+BuOddhcq3n68LKRmgk2wXzmF6s0SFOa0GINL4=
go.opencensus.io v0.19.1/go.mod h1:gug0GbSHa8Pafr0d2urOSgoXHZ6x/RUlaiT0d9pqb4A=
go.opencensus.io v0.19.2/go.mod h1:NO/8qkisMZLZ1FCsKNqtJPwc8/TaclWyY0B6wcYNg9M=
go.opencensus.io v0.20.1/go.mod h1:6WKK9ahsWS3RSO+PY9ZHZUfv2irvY6gN279GOPZjmmk=
go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU=
go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8=
go.opencensus.io v0.22.2/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw=
Expand All @@ -1295,9 +1290,8 @@ go.opentelemetry.io/otel/trace v1.28.0/go.mod h1:jPyXzNPg6da9+38HEwElrQiHlVMTnVf
go.opentelemetry.io/proto/otlp v0.7.0/go.mod h1:PqfVotwruBrMGOCsRd/89rSnXhoiJIqeYNgFYFoEGnI=
go.uber.org/atomic v1.3.2/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=
go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=
go.uber.org/atomic v1.7.0 h1:ADUqmZGgLDDfbSL9ZmPxKTybcoEYHgpYfELNoN+7hsw=
go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
go.uber.org/atomic v1.9.0 h1:ECmE8Bn/WFTYwEW/bpKD3M8VtR/zQVbavAoalC1PYyE=
go.uber.org/atomic v1.9.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0=
go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0=
go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y=
Expand Down
47 changes: 18 additions & 29 deletions ibm/service/sdsaas/resource_ibm_sds_host.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright IBM Corp. 2024 All Rights Reserved.
// Copyright IBM Corp. 2025 All Rights Reserved.
// Licensed under the Mozilla Public License v2.0

/*
Expand Down Expand Up @@ -43,7 +43,7 @@ func ResourceIBMSdsHost() *schema.Resource {
ValidateFunc: validate.InvokeValidator("ibm_sds_host", "nqn"),
Description: "The NQN of the host configured in customer's environment.",
},
"volume_mappings": &schema.Schema{
"volumes": &schema.Schema{
Type: schema.TypeList,
Optional: true,
Description: "The host-to-volume map.",
Expand Down Expand Up @@ -116,11 +116,6 @@ func ResourceIBMSdsHost() *schema.Resource {
Computed: true,
Description: "The date and time that the host was created.",
},
"service_instance_id": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "The service instance ID this host should be created in.",
},
},
}
}
Expand Down Expand Up @@ -166,17 +161,17 @@ func resourceIBMSdsHostCreate(context context.Context, d *schema.ResourceData, m
if _, ok := d.GetOk("name"); ok {
hostCreateOptions.SetName(d.Get("name").(string))
}
if _, ok := d.GetOk("volume_mappings"); ok {
var volumeMappings []sdsaasv1.VolumeMappingIdentity
for _, v := range d.Get("volume_mappings").([]interface{}) {
if _, ok := d.GetOk("volumes"); ok {
var volumes []sdsaasv1.VolumeMappingIdentity
for _, v := range d.Get("volumes").([]interface{}) {
value := v.(map[string]interface{})
volumeMappingsItem, err := ResourceIBMSdsHostMapToVolumeMappingIdentity(value)
volumesItem, err := ResourceIBMSdsHostMapToVolumeMappingIdentity(value)
if err != nil {
return flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_sds_host", "create", "parse-volume_mappings").GetDiag()
return flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_sds_host", "create", "parse-volumes").GetDiag()
}
volumeMappings = append(volumeMappings, *volumeMappingsItem)
volumes = append(volumes, *volumesItem)
}
hostCreateOptions.SetVolumeMappings(volumeMappings)
hostCreateOptions.SetVolumes(volumes)
}

host, _, err := sdsaasClient.HostCreateWithContext(context, hostCreateOptions)
Expand Down Expand Up @@ -224,18 +219,18 @@ func resourceIBMSdsHostRead(context context.Context, d *schema.ResourceData, met
err = fmt.Errorf("Error setting nqn: %s", err)
return flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_sds_host", "read", "set-nqn").GetDiag()
}
if !core.IsNil(host.VolumeMappings) {
volumeMappings := []map[string]interface{}{}
for _, volumeMappingsItem := range host.VolumeMappings {
volumeMappingsItemMap, err := ResourceIBMSdsHostVolumeMappingReferenceToMap(&volumeMappingsItem) // #nosec G601
if !core.IsNil(host.Volumes) {
volumes := []map[string]interface{}{}
for _, volumesItem := range host.Volumes {
volumesItemMap, err := ResourceIBMSdsHostVolumeMappingReferenceToMap(&volumesItem) // #nosec G601
if err != nil {
return flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_sds_host", "read", "volume_mappings-to-map").GetDiag()
return flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_sds_host", "read", "volumes-to-map").GetDiag()
}
volumeMappings = append(volumeMappings, volumeMappingsItemMap)
volumes = append(volumes, volumesItemMap)
}
if err = d.Set("volume_mappings", volumeMappings); err != nil {
err = fmt.Errorf("Error setting volume_mappings: %s", err)
return flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_sds_host", "read", "set-volume_mappings").GetDiag()
if err = d.Set("volumes", volumes); err != nil {
err = fmt.Errorf("Error setting volumes: %s", err)
return flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_sds_host", "read", "set-volumes").GetDiag()
}
}
if !core.IsNil(host.CreatedAt) {
Expand All @@ -244,12 +239,6 @@ func resourceIBMSdsHostRead(context context.Context, d *schema.ResourceData, met
return flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_sds_host", "read", "set-created_at").GetDiag()
}
}
if !core.IsNil(host.ServiceInstanceID) {
if err = d.Set("service_instance_id", host.ServiceInstanceID); err != nil {
err = fmt.Errorf("Error setting service_instance_id: %s", err)
return flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_sds_host", "read", "set-service_instance_id").GetDiag()
}
}

return nil
}
Expand Down
4 changes: 2 additions & 2 deletions ibm/service/sdsaas/resource_ibm_sds_host_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright IBM Corp. 2024 All Rights Reserved.
// Copyright IBM Corp. 2025 All Rights Reserved.
// Licensed under the Mozilla Public License v2.0

package sdsaas_test
Expand Down Expand Up @@ -105,7 +105,7 @@ func testAccCheckIBMSdsHostConfig(name string, nqn string) string {
resource "ibm_sds_host" "sds_host_instance" {
name = "%s"
nqn = "%s"
volume_mappings {
volumes {
volume_name = ibm_sds_volume.sds_volume_instance.name
volume_id = ibm_sds_volume.sds_volume_instance.id
}
Expand Down
56 changes: 39 additions & 17 deletions ibm/service/sdsaas/resource_ibm_sds_volume.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright IBM Corp. 2024 All Rights Reserved.
// Copyright IBM Corp. 2025 All Rights Reserved.
// Licensed under the Mozilla Public License v2.0

/*
Expand Down Expand Up @@ -48,7 +48,17 @@ func ResourceIBMSdsVolume() *schema.Resource {
ValidateFunc: validate.InvokeValidator("ibm_sds_volume", "name"),
Description: "The name of the volume.",
},
"host_mappings": &schema.Schema{
"bandwidth": &schema.Schema{
Type: schema.TypeInt,
Computed: true,
Description: "The maximum bandwidth (in megabits per second) for the volume.",
},
"created_at": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "The date and time that the volume was created.",
},
"hosts": &schema.Schema{
Type: schema.TypeList,
Computed: true,
Description: "List of host details that volume is mapped to.",
Expand All @@ -75,10 +85,10 @@ func ResourceIBMSdsVolume() *schema.Resource {
},
},
},
"created_at": &schema.Schema{
Type: schema.TypeString,
"iops": &schema.Schema{
Type: schema.TypeInt,
Computed: true,
Description: "The date and time that the volume was created.",
Description: "Iops The maximum I/O operations per second (IOPS) for this volume.",
},
"resource_type": &schema.Schema{
Type: schema.TypeString,
Expand Down Expand Up @@ -190,18 +200,10 @@ func resourceIBMSdsVolumeRead(context context.Context, d *schema.ResourceData, m
return flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_sds_volume", "read", "set-name").GetDiag()
}
}
if !core.IsNil(volume.HostMappings) {
hostMappings := []map[string]interface{}{}
for _, hostMappingsItem := range volume.HostMappings {
hostMappingsItemMap, err := ResourceIBMSdsVolumeHostMappingToMap(&hostMappingsItem) // #nosec G601
if err != nil {
return flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_sds_volume", "read", "host_mappings-to-map").GetDiag()
}
hostMappings = append(hostMappings, hostMappingsItemMap)
}
if err = d.Set("host_mappings", hostMappings); err != nil {
err = fmt.Errorf("Error setting host_mappings: %s", err)
return flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_sds_volume", "read", "set-host_mappings").GetDiag()
if !core.IsNil(volume.Bandwidth) {
if err = d.Set("bandwidth", flex.IntValue(volume.Bandwidth)); err != nil {
err = fmt.Errorf("Error setting bandwidth: %s", err)
return flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_sds_volume", "read", "set-bandwidth").GetDiag()
}
}
if !core.IsNil(volume.CreatedAt) {
Expand All @@ -210,6 +212,26 @@ func resourceIBMSdsVolumeRead(context context.Context, d *schema.ResourceData, m
return flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_sds_volume", "read", "set-created_at").GetDiag()
}
}
if !core.IsNil(volume.Hosts) {
hosts := []map[string]interface{}{}
for _, hostsItem := range volume.Hosts {
hostsItemMap, err := ResourceIBMSdsVolumeHostMappingToMap(&hostsItem) // #nosec G601
if err != nil {
return flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_sds_volume", "read", "hosts-to-map").GetDiag()
}
hosts = append(hosts, hostsItemMap)
}
if err = d.Set("hosts", hosts); err != nil {
err = fmt.Errorf("Error setting hosts: %s", err)
return flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_sds_volume", "read", "set-hosts").GetDiag()
}
}
if !core.IsNil(volume.Iops) {
if err = d.Set("iops", flex.IntValue(volume.Iops)); err != nil {
err = fmt.Errorf("Error setting iops: %s", err)
return flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_sds_volume", "read", "set-iops").GetDiag()
}
}
if !core.IsNil(volume.ResourceType) {
if err = d.Set("resource_type", volume.ResourceType); err != nil {
err = fmt.Errorf("Error setting resource_type: %s", err)
Expand Down
2 changes: 1 addition & 1 deletion ibm/service/sdsaas/resource_ibm_sds_volume_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright IBM Corp. 2024 All Rights Reserved.
// Copyright IBM Corp. 2025 All Rights Reserved.
// Licensed under the Mozilla Public License v2.0

package sdsaas_test
Expand Down
Loading

0 comments on commit c7a4686

Please sign in to comment.