From 4c1735aeb804f72ce241763e02b2fdd1228ca455 Mon Sep 17 00:00:00 2001 From: Alexander Kita Date: Tue, 19 Nov 2024 14:35:22 -0600 Subject: [PATCH] Granular CRN for power dedicated hosts --- ibm/service/power/data_source_ibm_pi_host.go | 22 +++ .../power/data_source_ibm_pi_host_test.go | 3 +- ibm/service/power/data_source_ibm_pi_hosts.go | 22 +++ .../power/data_source_ibm_pi_hosts_test.go | 3 +- ibm/service/power/resource_ibm_pi_host.go | 134 ++++++++++++++++-- .../power/resource_ibm_pi_host_group.go | 9 ++ .../power/resource_ibm_pi_host_test.go | 57 +++++++- website/docs/d/pi_host.html.markdown | 4 + website/docs/d/pi_hosts.html.markdown | 2 + website/docs/r/pi_host.html.markdown | 71 ++++++---- website/docs/r/pi_host_group.html.markdown | 27 ++-- 11 files changed, 297 insertions(+), 57 deletions(-) diff --git a/ibm/service/power/data_source_ibm_pi_host.go b/ibm/service/power/data_source_ibm_pi_host.go index 0b6ea2c7e6..bc8490d6de 100644 --- a/ibm/service/power/data_source_ibm_pi_host.go +++ b/ibm/service/power/data_source_ibm_pi_host.go @@ -5,6 +5,7 @@ package power import ( "context" + "log" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" @@ -12,6 +13,7 @@ import ( "github.com/IBM-Cloud/power-go-client/clients/instance" "github.com/IBM-Cloud/terraform-provider-ibm/ibm/conns" + "github.com/IBM-Cloud/terraform-provider-ibm/ibm/flex" ) func DataSourceIBMPIHost() *schema.Resource { @@ -84,6 +86,11 @@ func DataSourceIBMPIHost() *schema.Resource { }, Type: schema.TypeList, }, + Attr_CRN: { + Computed: true, + Description: "The CRN of this resource.", + Type: schema.TypeString, + }, Attr_DisplayName: { Computed: true, Description: "Name of the host (chosen by the user).", @@ -109,6 +116,13 @@ func DataSourceIBMPIHost() *schema.Resource { Description: "System type.", Type: schema.TypeString, }, + Attr_UserTags: { + Computed: true, + Description: "List of user tags attached to the resource.", + Elem: &schema.Schema{Type: schema.TypeString}, + Set: schema.HashString, + Type: schema.TypeSet, + }, }, } } @@ -131,6 +145,14 @@ func dataSourceIBMPIHostRead(ctx context.Context, d *schema.ResourceData, meta i if host.Capacity != nil { d.Set(Attr_Capacity, hostCapacityToMap(host.Capacity)) } + if host.Crn != "" { + d.Set(Attr_CRN, host.Crn) + tags, err := flex.GetGlobalTagsUsingCRN(meta, string(host.Crn), "", UserTagType) + if err != nil { + log.Printf("Error on get of pi host (%s) user_tags: %s", hostID, err) + } + d.Set(Attr_UserTags, tags) + } if host.DisplayName != "" { d.Set(Attr_DisplayName, host.DisplayName) } diff --git a/ibm/service/power/data_source_ibm_pi_host_test.go b/ibm/service/power/data_source_ibm_pi_host_test.go index b8d9c775a2..87a06a7ebc 100644 --- a/ibm/service/power/data_source_ibm_pi_host_test.go +++ b/ibm/service/power/data_source_ibm_pi_host_test.go @@ -13,6 +13,7 @@ import ( ) func TestAccIBMPIHostDataSourceBasic(t *testing.T) { + hostResData := "data.ibm_pi_host.pi_host_instance" resource.Test(t, resource.TestCase{ PreCheck: func() { acc.TestAccPreCheck(t) }, Providers: acc.TestAccProviders, @@ -20,7 +21,7 @@ func TestAccIBMPIHostDataSourceBasic(t *testing.T) { { Config: testAccCheckIBMPIHostDataSourceConfigBasic(), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttrSet("data.ibm_pi_host.pi_host_instance", "id"), + resource.TestCheckResourceAttrSet(hostResData, "id"), ), }, }, diff --git a/ibm/service/power/data_source_ibm_pi_hosts.go b/ibm/service/power/data_source_ibm_pi_hosts.go index c7476bec05..3e71bf41c7 100644 --- a/ibm/service/power/data_source_ibm_pi_hosts.go +++ b/ibm/service/power/data_source_ibm_pi_hosts.go @@ -5,6 +5,7 @@ package power import ( "context" + "log" "github.com/hashicorp/go-uuid" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" @@ -13,6 +14,7 @@ import ( "github.com/IBM-Cloud/power-go-client/clients/instance" "github.com/IBM-Cloud/terraform-provider-ibm/ibm/conns" + "github.com/IBM-Cloud/terraform-provider-ibm/ibm/flex" ) func DataSourceIBMPIHosts() *schema.Resource { @@ -82,6 +84,11 @@ func DataSourceIBMPIHosts() *schema.Resource { }, Type: schema.TypeList, }, + Attr_CRN: { + Computed: true, + Description: "The CRN of this resource.", + Type: schema.TypeString, + }, Attr_DisplayName: { Computed: true, Description: "Name of the host (chosen by the user).", @@ -112,6 +119,13 @@ func DataSourceIBMPIHosts() *schema.Resource { Description: "System type.", Type: schema.TypeString, }, + Attr_UserTags: { + Computed: true, + Description: "List of user tags attached to the resource.", + Elem: &schema.Schema{Type: schema.TypeString}, + Set: schema.HashString, + Type: schema.TypeSet, + }, }, }, Type: schema.TypeList, @@ -142,6 +156,14 @@ func dataSourceIBMPIHostsRead(ctx context.Context, d *schema.ResourceData, meta if host.Capacity != nil { hs[Attr_Capacity] = hostCapacityToMap(host.Capacity) } + if host.Crn != "" { + hs[Attr_CRN] = host.Crn + tags, err := flex.GetTagsUsingCRN(meta, string(host.Crn)) + if err != nil { + log.Printf("Error on get of pi host (%s) user_tags: %s", host.ID, err) + } + hs[Attr_UserTags] = tags + } if host.DisplayName != "" { hs[Attr_DisplayName] = host.DisplayName } diff --git a/ibm/service/power/data_source_ibm_pi_hosts_test.go b/ibm/service/power/data_source_ibm_pi_hosts_test.go index 91d18be785..d7c63bea21 100644 --- a/ibm/service/power/data_source_ibm_pi_hosts_test.go +++ b/ibm/service/power/data_source_ibm_pi_hosts_test.go @@ -13,6 +13,7 @@ import ( ) func TestAccIBMPIHostsDataSourceBasic(t *testing.T) { + hostsResData := "data.ibm_pi_hosts.pi_hosts_instance" resource.Test(t, resource.TestCase{ PreCheck: func() { acc.TestAccPreCheck(t) }, Providers: acc.TestAccProviders, @@ -20,7 +21,7 @@ func TestAccIBMPIHostsDataSourceBasic(t *testing.T) { { Config: testAccCheckIBMPIHostsDataSourceConfigBasic(), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttrSet("data.ibm_pi_hosts.pi_hosts_instance", "id"), + resource.TestCheckResourceAttrSet(hostsResData, "id"), ), }, }, diff --git a/ibm/service/power/resource_ibm_pi_host.go b/ibm/service/power/resource_ibm_pi_host.go index 8ec769293c..f1c535171b 100644 --- a/ibm/service/power/resource_ibm_pi_host.go +++ b/ibm/service/power/resource_ibm_pi_host.go @@ -7,10 +7,12 @@ import ( "context" "fmt" "log" + "os" "strings" "time" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/customdiff" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" @@ -18,11 +20,17 @@ import ( "github.com/IBM-Cloud/power-go-client/clients/instance" "github.com/IBM-Cloud/power-go-client/power/models" "github.com/IBM-Cloud/terraform-provider-ibm/ibm/conns" + "github.com/IBM-Cloud/terraform-provider-ibm/ibm/flex" "github.com/IBM/go-sdk-core/v5/core" ) func ResourceIBMPIHost() *schema.Resource { return &schema.Resource{ + CustomizeDiff: customdiff.Sequence( + func(_ context.Context, diff *schema.ResourceDiff, v interface{}) error { + return customizeUserTagsPIHostDiff(diff) + }, + ), CreateContext: resourceIBMPIHostCreate, ReadContext: resourceIBMPIHostRead, UpdateContext: resourceIBMPIHostUpdate, @@ -55,20 +63,29 @@ func ResourceIBMPIHost() *schema.Resource { Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ Attr_DisplayName: { - Type: schema.TypeString, - Required: true, Description: "Name of the host chosen by the user.", + Required: true, + Type: schema.TypeString, }, Attr_SysType: { - Type: schema.TypeString, + Description: "System type.", ForceNew: true, Required: true, - Description: "System type.", + Type: schema.TypeString, + }, + Attr_UserTags: { + Computed: true, + Description: "List of user tags attached to the resource.", + Elem: &schema.Schema{Type: schema.TypeString}, + Optional: true, + Set: schema.HashString, + Type: schema.TypeSet, }, }, }, + MaxItems: 1, Required: true, - Type: schema.TypeSet, + Type: schema.TypeList, }, // Attributes Attr_Capacity: { @@ -119,6 +136,11 @@ func ResourceIBMPIHost() *schema.Resource { }, Type: schema.TypeList, }, + Attr_CRN: { + Computed: true, + Description: "The CRN of this resource.", + Type: schema.TypeString, + }, Attr_DisplayName: { Computed: true, Description: "Name of the host (chosen by the user).", @@ -149,6 +171,12 @@ func ResourceIBMPIHost() *schema.Resource { Description: "System type.", Type: schema.TypeString, }, + Attr_UserTags: { + Computed: true, + Description: "List of user tags attached to resource.", + Elem: &schema.Schema{Type: schema.TypeString}, + Type: schema.TypeList, + }, }, } } @@ -160,7 +188,7 @@ func resourceIBMPIHostCreate(ctx context.Context, d *schema.ResourceData, meta i } cloudInstanceID := d.Get(Arg_CloudInstanceID).(string) client := instance.NewIBMPIHostGroupsClient(ctx, sess, cloudInstanceID) - hosts := d.Get(Arg_Host).(*schema.Set).List() + hosts := d.Get(Arg_Host).([]interface{}) hostGroupID := d.Get(Arg_HostGroupID).(string) body := models.HostCreate{} hostBody := make([]*models.AddHost, 0, len(hosts)) @@ -169,6 +197,7 @@ func resourceIBMPIHostCreate(ctx context.Context, d *schema.ResourceData, meta i hs := models.AddHost{ DisplayName: core.StringPtr(host[Attr_DisplayName].(string)), SysType: core.StringPtr(host[Attr_SysType].(string)), + UserTags: flex.FlattenSet(host[Attr_UserTags].(*schema.Set)), } hostBody = append(hostBody, &hs) } @@ -186,6 +215,17 @@ func resourceIBMPIHostCreate(ctx context.Context, d *schema.ResourceData, meta i if err != nil { return diag.FromErr(err) } + + host := hosts[0].(map[string]interface{}) + tags := flex.FlattenSet(host[Attr_UserTags].(*schema.Set)) + if hostResponse[0].Crn != "" && len(tags) > 0 { + oldList, newList := d.GetChange(Arg_Host + ".0." + Attr_UserTags) + err := flex.UpdateGlobalTagsUsingCRN(oldList, newList, meta, string(hostResponse[0].Crn), "", UserTagType) + if err != nil { + log.Printf("Error on update of pi host (%s) user_tags during creation: %s", hostResponse[0].ID, err) + } + } + return resourceIBMPIHostRead(ctx, d, meta) } @@ -207,11 +247,25 @@ func resourceIBMPIHostRead(ctx context.Context, d *schema.ResourceData, meta int } return diag.FromErr(err) } + d.Set(Arg_CloudInstanceID, cloudInstanceID) + hostGroupID, err := getLastPart(host.HostGroup.Href) + if err != nil { + return diag.FromErr(err) + } + d.Set(Arg_HostGroupID, hostGroupID) d.Set(Attr_HostID, host.ID) if host.Capacity != nil { d.Set(Attr_Capacity, hostCapacityToMap(host.Capacity)) } + if host.Crn != "" { + d.Set(Attr_CRN, host.Crn) + tags, err := flex.GetGlobalTagsUsingCRN(meta, string(host.Crn), "", UserTagType) + if err != nil { + log.Printf("Error on get of pi host (%s) user_tags: %s", host.ID, err) + } + d.Set(Attr_UserTags, tags.List()) + } if host.DisplayName != "" { d.Set(Attr_DisplayName, host.DisplayName) } @@ -227,6 +281,7 @@ func resourceIBMPIHostRead(ctx context.Context, d *schema.ResourceData, meta int if host.SysType != "" { d.Set(Attr_SysType, host.SysType) } + d.Set(Arg_Host, flattenHostArgumentToList(d, meta)) return nil } @@ -240,18 +295,36 @@ func resourceIBMPIHostUpdate(ctx context.Context, d *schema.ResourceData, meta i if err != nil { return diag.FromErr(err) } - displayName := d.Get(Arg_Host + ".0").(map[string]interface{})[Attr_DisplayName].(string) client := instance.NewIBMPIHostGroupsClient(ctx, sess, cloudInstanceID) if d.HasChange(Arg_Host) { + oldHost, newHost := d.GetChange(Arg_Host + ".0") + + displayNameOld := oldHost.(map[string]interface{})[Attr_DisplayName].(string) + displayNameNew := newHost.(map[string]interface{})[Attr_DisplayName].(string) - hostBody := models.HostPut{ - DisplayName: &displayName, + if displayNameNew != displayNameOld { + hostBody := models.HostPut{ + DisplayName: &displayNameNew, + } + _, err := client.UpdateHost(&hostBody, hostID) + if err != nil { + return diag.FromErr(err) + } } - _, err := client.UpdateHost(&hostBody, hostID) - if err != nil { - return diag.FromErr(err) + + if crn, ok := d.GetOk(Attr_CRN); ok { + userTagsOld := oldHost.(map[string]interface{})[Attr_UserTags].(*schema.Set) + userTagsNew := newHost.(map[string]interface{})[Attr_UserTags].(*schema.Set) + if !userTagsNew.Equal(userTagsOld) { + err = flex.UpdateGlobalTagsUsingCRN(userTagsOld, userTagsNew, meta, crn.(string), "", UserTagType) + if err != nil { + log.Printf("Error on update of pi host (%s) pi_host user_tags: %s", d.Get(Attr_HostID), err) + } + } } + } + return resourceIBMPIHostRead(ctx, d, meta) } @@ -372,3 +445,40 @@ func isIBMPIHostRefreshFunc(client *instance.IBMPIHostGroupsClient, id string) r return host, State_Down, nil } } + +func flattenHostArgumentToList(d *schema.ResourceData, meta interface{}) []map[string]interface{} { + hostListType := make([]map[string]interface{}, 0) + h := map[string]interface{}{} + if v, ok := d.GetOk(Attr_DisplayName); ok { + displayName := v.(string) + h[Attr_DisplayName] = displayName + } + if v, ok := d.GetOk(Attr_SysType); ok { + sysType := v.(string) + h[Attr_SysType] = sysType + } + if v, ok := d.GetOk(Attr_UserTags); ok { + tags := v.([]interface{}) + h[Attr_UserTags] = tags + } + hostListType = append(hostListType, h) + return hostListType +} + +func customizeUserTagsPIHostDiff(diff *schema.ResourceDiff) error { + if diff.Id() != "" && diff.HasChange(Arg_Host+".0."+Attr_UserTags) { + o, n := diff.GetChange(Arg_Host + ".0." + Attr_UserTags) + oldSet := o.(*schema.Set) + newSet := n.(*schema.Set) + removeInt := oldSet.Difference(newSet).List() + addInt := newSet.Difference(oldSet).List() + if v := os.Getenv("IC_ENV_TAGS"); v != "" { + s := strings.Split(v, ",") + if len(removeInt) == len(s) && len(addInt) == 0 { + fmt.Println("Suppresing the TAG diff ") + return diff.Clear(Arg_Host + ".0." + Attr_UserTags) + } + } + } + return nil +} diff --git a/ibm/service/power/resource_ibm_pi_host_group.go b/ibm/service/power/resource_ibm_pi_host_group.go index f5229e9e3e..69ec4d53dc 100644 --- a/ibm/service/power/resource_ibm_pi_host_group.go +++ b/ibm/service/power/resource_ibm_pi_host_group.go @@ -19,6 +19,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" "github.com/IBM-Cloud/terraform-provider-ibm/ibm/conns" + "github.com/IBM-Cloud/terraform-provider-ibm/ibm/flex" "github.com/IBM/go-sdk-core/v5/core" ) @@ -60,6 +61,13 @@ func ResourceIBMPIHostGroup() *schema.Resource { Type: schema.TypeString, ValidateFunc: validation.NoZeroValues, }, + Attr_UserTags: { + Description: "List of user tags attached to the resource.", + Elem: &schema.Schema{Type: schema.TypeString}, + Optional: true, + Set: schema.HashString, + Type: schema.TypeSet, + }, }, }, Required: true, @@ -353,6 +361,7 @@ func hostMapToAddHost(modelMap map[string]interface{}) *models.AddHost { host := &models.AddHost{} host.DisplayName = core.StringPtr(modelMap[Attr_DisplayName].(string)) host.SysType = core.StringPtr(modelMap[Attr_SysType].(string)) + host.UserTags = flex.FlattenSet(modelMap[Attr_UserTags].(*schema.Set)) return host } diff --git a/ibm/service/power/resource_ibm_pi_host_test.go b/ibm/service/power/resource_ibm_pi_host_test.go index 1ca0fd9018..746195bc33 100644 --- a/ibm/service/power/resource_ibm_pi_host_test.go +++ b/ibm/service/power/resource_ibm_pi_host_test.go @@ -19,6 +19,7 @@ import ( func TestAccIBMIHostBasic(t *testing.T) { displayName := fmt.Sprintf("tf_display_name_%d", acctest.RandIntRange(10, 100)) + hostRes := "ibm_pi_host.host" resource.Test(t, resource.TestCase{ PreCheck: func() { acc.TestAccPreCheck(t) @@ -29,13 +30,14 @@ func TestAccIBMIHostBasic(t *testing.T) { { Config: testAccCheckIBMPIHostConfig(displayName), Check: resource.ComposeAggregateTestCheckFunc( - testAccCheckIBMPIHostExists("ibm_pi_host.host"), - resource.TestCheckResourceAttr("ibm_pi_host.host", "display_name", displayName), + testAccCheckIBMPIHostExists(hostRes), + resource.TestCheckResourceAttr(hostRes, "display_name", displayName), ), }, }, }) } + func testAccCheckIBMPIHostConfig(name string) string { return fmt.Sprintf(` resource "ibm_pi_host" "host" { @@ -49,6 +51,57 @@ func testAccCheckIBMPIHostConfig(name string) string { `, acc.Pi_cloud_instance_id, name, acc.Pi_host_group_id) } +func TestAccIBMIHostUserTags(t *testing.T) { + displayName := fmt.Sprintf("tf_display_name_%d", acctest.RandIntRange(10, 100)) + hostRes := "ibm_pi_host.host" + userTagsString := `["env:dev", "test_tag1"]` + userTagsStringUpdated := `["env:dev", "test_tag1", "ibm"]` + resource.Test(t, resource.TestCase{ + PreCheck: func() { + acc.TestAccPreCheck(t) + }, + Providers: acc.TestAccProviders, + CheckDestroy: testAccCheckIBMPIHostDestroy, + Steps: []resource.TestStep{ + { + Config: testAccCheckIBMPIHostUserTagsConfig(displayName, userTagsString), + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckIBMPIHostExists(hostRes), + resource.TestCheckResourceAttr(hostRes, "display_name", displayName), + resource.TestCheckResourceAttr(hostRes, "user_tags.#", "2"), + resource.TestCheckTypeSetElemAttr(hostRes, "user_tags.*", "env:dev"), + resource.TestCheckTypeSetElemAttr(hostRes, "user_tags.*", "test_tag1"), + ), + }, + { + Config: testAccCheckIBMPIHostUserTagsConfig(displayName, userTagsStringUpdated), + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckIBMPIHostExists(hostRes), + resource.TestCheckResourceAttr(hostRes, "display_name", displayName), + resource.TestCheckResourceAttr(hostRes, "user_tags.#", "3"), + resource.TestCheckTypeSetElemAttr(hostRes, "user_tags.*", "env:dev"), + resource.TestCheckTypeSetElemAttr(hostRes, "user_tags.*", "test_tag1"), + resource.TestCheckTypeSetElemAttr(hostRes, "user_tags.*", "ibm"), + ), + }, + }, + }) +} + +func testAccCheckIBMPIHostUserTagsConfig(name string, userTagsString string) string { + return fmt.Sprintf(` + resource "ibm_pi_host" "host" { + pi_cloud_instance_id = "%[1]s" + pi_host { + display_name = "%[2]s" + sys_type = "s922" + user_tags = %[4]s + } + pi_host_group_id = "%[3]s" + } + `, acc.Pi_cloud_instance_id, name, acc.Pi_host_group_id, userTagsString) +} + func testAccCheckIBMPIHostDestroy(s *terraform.State) error { sess, err := acc.TestAccProvider.Meta().(conns.ClientSession).IBMPISession() if err != nil { diff --git a/website/docs/d/pi_host.html.markdown b/website/docs/d/pi_host.html.markdown index 721c7bd065..b925e022ff 100644 --- a/website/docs/d/pi_host.html.markdown +++ b/website/docs/d/pi_host.html.markdown @@ -59,6 +59,7 @@ After your data source is created, you can read values from the following attrib - `used_core` - (Float) Number of cores in use on the host. - `used_memory` - (Float) Amount of memory used on the host (in GB). +- `crn` - (String) The CRN of this resource. - `display_name` - (String) Name of the host. - `host_group` - (Map) Information about the owning host group. @@ -74,3 +75,6 @@ After your data source is created, you can read values from the following attrib - `status` - (String) Status of the host `enabled` or `disabled`. - `sys_type` - (String) System type. + +- `user_tags` - (List) List of user tags attached to the resource. + diff --git a/website/docs/d/pi_hosts.html.markdown b/website/docs/d/pi_hosts.html.markdown index 460f7e8fd1..45faf7d7ee 100644 --- a/website/docs/d/pi_hosts.html.markdown +++ b/website/docs/d/pi_hosts.html.markdown @@ -60,6 +60,7 @@ After your data source is created, you can read values from the following attrib - `used_core` - (Float) Number of cores in use on the host. - `used_memory` - (Float) Amount of memory used on the host (in GB). + - `crn` - (String) The CRN of this resource. - `display_name` - (String) Name of the host. - `host_group` - (Map) Information about the owning host group. @@ -72,3 +73,4 @@ After your data source is created, you can read values from the following attrib - `state` - (String) State of the host `up` or `down`. - `status` - (String) Status of the host `enabled` or `disabled`. - `sys_type` - (String) System type. + - `user_tags` - (List) List of user tags attached to the resource. diff --git a/website/docs/r/pi_host.html.markdown b/website/docs/r/pi_host.html.markdown index 2da0d51cb5..474e2cd09a 100644 --- a/website/docs/r/pi_host.html.markdown +++ b/website/docs/r/pi_host.html.markdown @@ -45,45 +45,60 @@ resource "ibm_pi_host" "host" { The ibm_pi_host provides the following [timeouts](https://www.terraform.io/docs/language/resources/syntax.html) configuration options: -* **create** - (Default 10 minutes) The creating of the host is considered failed if no response is received for 10 minutes. -* **delete** - (Default 10 minutes) The deletion of the host is considered failed if no response is received for 10 minutes. +- **create** - (Default 10 minutes) The creating of the host is considered failed if no response is received for 10 minutes. +- **delete** - (Default 10 minutes) The deletion of the host is considered failed if no response is received for 10 minutes. ## Argument Reference You can specify the following arguments for this resource. -* `pi_cloud_instance_id` - (Required, String) The GUID of the service instance associated with an account. -* `pi_host` - (Required, List) Host to add to a host group. +- `pi_cloud_instance_id` - (Required, String) The GUID of the service instance associated with an account. +- `pi_host` - (Required, List) Host to add to a host group. Nested schema for `pi_host`: - * `display_name` - (Required, String) Name of the host chosen by the user. - * `sys_type` - (Required, String) System type. -* `pi_host_group_id` - (Required, String) ID of the host group to which the host should be added. + - `display_name` - (Required, String) Name of the host chosen by the user. + - `sys_type` - (Required, String) System type. + - `user_tags` - (Optional, List) The user tags attached to this resource. +- `pi_host_group_id` - (Required, String) ID of the host group to which the host should be added. + ## Attribute Reference In addition to all argument reference list, you can access the following attribute reference after your resource is created. -* `capacity` - (List) Capacities of the host. - - Nested schema for `capacity`: - * `available_core` - (Float) Number of cores currently available. - * `available_memory` - (Float) Amount of memory currently available (in GB). - * `reserved_core` - (Float) Number of cores reserved for system use. - * `reserved_memory` - (Float) Amount of memory reserved for system use (in GB). - * `total_core` - (Float) Total number of cores of the host. - * `total_memory` - (Float) Total amount of memory of the host (in GB). - * `used_core` - (Float) Number of cores in use on the host. - * `used_memory` - (Float) Amount of memory used on the host (in GB). -* `host_group` - (Map) Information about the owning host group. +- `capacity` - (List) Capacities of the host. + + Nested schema for `capacity`: + - `available_core` - (Float) Number of cores currently available. + - `available_memory` - (Float) Amount of memory currently available (in GB). + - `reserved_core` - (Float) Number of cores reserved for system use. + - `reserved_memory` - (Float) Amount of memory reserved for system use (in GB). + - `total_core` - (Float) Total number of cores of the host. + - `total_memory` - (Float) Total amount of memory of the host (in GB). + - `used_core` - (Float) Number of cores in use on the host. + - `used_memory` - (Float) Amount of memory used on the host (in GB). + +- `crn` - (String) The CRN of this resource. +- `host_group` - (Map) Information about the owning host group. - Nested schema for `host_group`: - * `access` - (String) Whether the host group is a primary or secondary host group. - * `href` - (String) Link to the host group resource. - * `name` - (String) Name of the host group. + Nested schema for `host_group`: + - `access` - (String) Whether the host group is a primary or secondary host group. + - `href` - (String) Link to the host group resource. + - `name` - (String) Name of the host group. -* `host_id` - (String) ID of the host. -* `id` - The unique identifier of the host. The ID is composed of `/`. -* `state` - (String) State of the host `up` or `down`. -* `status` - (String) Status of the host `enabled` or `disabled`. -* `sys_type` - (String) System type. +- `host_id` - (String) ID of the host. +- `id` - The unique identifier of the host. The ID is composed of `/`. +- `state` - (String) State of the host `up` or `down`. +- `status` - (String) Status of the host `enabled` or `disabled`. +- `sys_type` - (String) System type. +- `user_tags` - (List) The user tags attached to this resource. + +## Import + +The `ibm_pi_host` resource can be imported by using `pi_cloud_instance_id` and `host_id`. + +### Example + +```bash +terraform import ibm_pi_host.example d7bec597-4726-451f-8a63-e62e6f19c32c/b17a2b7f-77ab-491c-811e-495f8d4c8947 +``` \ No newline at end of file diff --git a/website/docs/r/pi_host_group.html.markdown b/website/docs/r/pi_host_group.html.markdown index e1d2cd1d35..7999d6bb96 100644 --- a/website/docs/r/pi_host_group.html.markdown +++ b/website/docs/r/pi_host_group.html.markdown @@ -49,25 +49,26 @@ resource "ibm_pi_host_group" "hostGroup" { The `ibm_pi_host_group` provides the following [timeouts](https://www.terraform.io/docs/language/resources/syntax.html) configuration options: -* **delete** - (Default 10 minutes) Used for deleting a host group. +- **delete** - (Default 10 minutes) Used for deleting a host group. ## Argument Reference You can specify the following arguments for this resource. -* `pi_cloud_instance_id` - (Required, String) The GUID of the service instance associated with an account. +- `pi_cloud_instance_id` - (Required, String) The GUID of the service instance associated with an account. -* `pi_hosts` - (Required, List) List of hosts to add to the group. +- `pi_hosts` - (Required, List) List of hosts to add to the group. Nested schema for `pi_hosts`: - `display_name` - (Required, String) Name of the host chosen by the user. - `sys_type` - (Required, String) System type. + - `user_tags` - (Optional, List) The user tags attached to this resource. Please avoid reading user tags from this attribute as environment tags will not be included. Please use appropriate data sources such as `ibm_pi_host` and `ibm_pi_hosts`. -* `pi_name` - (Required, String) Name of the host group to create. -* `pi_remove` - (Optional, String) A workspace ID to stop sharing the host group with. -* `pi_secondaries` - (Optional, List) List of workspaces to share the host group with. +- `pi_name` - (Required, String) Name of the host group to create. +- `pi_remove` - (Optional, String) A workspace ID to stop sharing the host group with. +- `pi_secondaries` - (Optional, List) List of workspaces to share the host group with. - Nested schema for `pi_secondaries`: + Nested schema for `pi_secondaries`: - `name` - (Optional, String) Name of the host group to create in the secondary workspace. - `workspace` - (Required, String) ID of the workspace to share the host group with. @@ -75,9 +76,9 @@ You can specify the following arguments for this resource. In addition to all argument reference list, you can access the following attribute references after your data source is created. -* `creation_date` - (String) Date/Time of host group creation. -* `host_group_id` - (String) The id of the created host group. -* `hosts` - (List) List of hosts. -* `id` - (String) The unique identifier of the host group. The ID is composed of `/`. -* `primary` - (String) The ID of the workspace owning the host group. -* `secondaries` - (List) IDs of workspaces the host group has been shared with. +- `creation_date` - (String) Date/Time of host group creation. +- `host_group_id` - (String) The id of the created host group. +- `hosts` - (List) List of hosts. +- `id` - (String) The unique identifier of the host group. The ID is composed of `/`. +- `primary` - (String) The ID of the workspace owning the host group. +- `secondaries` - (List) IDs of workspaces the host group has been shared with.