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

support resource instance's parameter to be an array type #1953

Merged
merged 3 commits into from
Oct 9, 2020
Merged
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
6 changes: 3 additions & 3 deletions examples/ibm-event-streams/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ resource "ibm_resource_instance" "es_instance_1" {
resource_group_id = data.ibm_resource_group.group.id

# parameters = {
# service-endpoint = "private" # for enterprise instance only, Options are: "public", "public-and-private", "private". Default is "public" when not specified.
# private_ip_allowlist = ["1.0.0.0/32", "1.0.0.1/32"] # for enterprise instance only. Specify 1 or more IP range in CIDR format
# service-endpoints = "private" # for enterprise instance only, Options are: "public", "public-and-private", "private". Default is "public" when not specified.
# private_ip_allowlist = "[10.0.0.0/32,10.0.0.1/32]" # for enterprise instance only. Specify 1 or more IP range in CIDR format
# # document about using private service endpoint and IP allowlist to restrict access: https://cloud.ibm.com/docs/EventStreams?topic=EventStreams-restrict_access

# throughput = "150" # for enterprise instance only. Options are: "150", "300", "450". Default is "150" when not specified.
# storage_size = "2048" # for enterprise instance only. Options are: "2048", "4096", "6144", "8192", "10240", "12288". Default is "2048" when not specified.
# # Note: when throughput is "300", storage_size starts from "4096", when throughput is "450", storage_size starts from "6144"
Expand Down
6 changes: 3 additions & 3 deletions examples/ibm-event-streams/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ resource "ibm_resource_instance" "es_instance_1" {
resource_group_id = data.ibm_resource_group.group.id

# parameters = {
# service-endpoint = "private" # for enterprise instance only, Options are: "public", "public-and-private", "private". Default is "public" when not specified.
# private_ip_allowlist = ["1.0.0.0/32", "1.0.0.1/32"] # for enterprise instance only. Specify 1 or more IP range in CIDR format
# service-endpoints = "private" # for enterprise instance only, Options are: "public", "public-and-private", "private". Default is "public" when not specified.
# private_ip_allowlist = "[10.0.0.0/32,10.0.0.1/32]" # for enterprise instance only. Specify 1 or more IP range in CIDR format
# # document about using private service endpoint and IP allowlist to restrict access: https://cloud.ibm.com/docs/EventStreams?topic=EventStreams-restrict_access

# throughput = "150" # for enterprise instance only. Options are: "150", "300", "450". Default is "150" when not specified.
# storage_size = "2048" # for enterprise instance only. Options are: "2048", "4096", "6144", "8192", "10240", "12288". Default is "2048" when not specified.
# # Note: when throughput is "300", storage_size starts from "4096", when throughput is "450", storage_size starts from "6144"
Expand Down
25 changes: 23 additions & 2 deletions ibm/resource_ibm_resource_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"log"
"os"
"strconv"
"strings"
"time"

"github.com/IBM-Cloud/bluemix-go/api/resource/resourcev1/controller"
Expand Down Expand Up @@ -253,7 +254,17 @@ func resourceIBMResourceInstanceCreate(d *schema.ResourceData, meta interface{})
if v == "true" || v == "false" {
b, _ := strconv.ParseBool(v.(string))
params[k] = b

} else if strings.HasPrefix(v.(string), "[") && strings.HasSuffix(v.(string), "]") {
//transform v.(string) to be []string
arrayString := v.(string)
trimLeft := strings.TrimLeft(arrayString, "[")
trimRight := strings.TrimRight(trimLeft, "]")
array := strings.Split(trimRight, ",")
result := []string{}
for _, a := range array {
result = append(result, strings.Trim(a, "\""))
}
params[k] = result
} else {
params[k] = v
}
Expand Down Expand Up @@ -413,7 +424,17 @@ func resourceIBMResourceInstanceUpdate(d *schema.ResourceData, meta interface{})
if v == "true" || v == "false" {
b, _ := strconv.ParseBool(v.(string))
params[k] = b

} else if strings.HasPrefix(v.(string), "[") && strings.HasSuffix(v.(string), "]") {
//transform v.(string) to be []string
arrayString := v.(string)
trimLeft := strings.TrimLeft(arrayString, "[")
trimRight := strings.TrimRight(trimLeft, "]")
array := strings.Split(trimRight, ",")
result := []string{}
for _, a := range array {
result = append(result, strings.Trim(a, "\""))
}
params[k] = result
} else {
params[k] = v
}
Expand Down