Skip to content
Open
Show file tree
Hide file tree
Changes from 3 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
11 changes: 9 additions & 2 deletions ibm/acctest/acctest.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ var (
Pi_image_bucket_region string
Pi_image_bucket_secret_key string
Pi_image_id string
Pi_instance_id string
Pi_instance_name string
Pi_key_name string
Pi_network_address_group_id string
Expand Down Expand Up @@ -1315,10 +1316,16 @@ func init() {
fmt.Println("[INFO] Set the environment variable PI_SNAPSHOT_ID for testing ibm_pi_instance_snapshot data source else it is set to default value '1ea33118-4c43-4356-bfce-904d0658de82'")
}

Pi_instance_name = os.Getenv("PI_PVM_INSTANCE_NAME")
Pi_instance_id = os.Getenv("PI_INSTANCE_ID")
if Pi_instance_id == "" {
Pi_instance_id = "terraform-test-power"
fmt.Println("[INFO] Set the environment variable PI_INSTANCE_ID for testing ibm_pi_instance resource else it is set to default value 'terraform-test-power'")
}

Pi_instance_name = os.Getenv("PI_INSTANCE_NAME")
if Pi_instance_name == "" {
Pi_instance_name = "terraform-test-power"
fmt.Println("[INFO] Set the environment variable PI_PVM_INSTANCE_ID for testing Pi_instance_name resource else it is set to default value 'terraform-test-power'")
fmt.Println("[INFO] Set the environment variable PI_INSTANCE_NAME for testing ibm_pi_instance resource else it is set to default value 'terraform-test-power'")
}

Pi_dhcp_id = os.Getenv("PI_DHCP_ID")
Expand Down
27 changes: 22 additions & 5 deletions ibm/service/power/data_source_ibm_pi_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,22 @@ func DataSourceIBMPIInstance() *schema.Resource {
Type: schema.TypeString,
ValidateFunc: validation.NoZeroValues,
},
Arg_InstanceID: {
AtLeastOneOf: []string{Arg_InstanceID, Arg_InstanceName},
ConflictsWith: []string{Arg_InstanceName},
Description: "The ID of the PVM instance.",
Optional: true,
Type: schema.TypeString,
ValidateFunc: validation.NoZeroValues,
},
Arg_InstanceName: {
Description: "The unique identifier or name of the instance.",
Required: true,
Type: schema.TypeString,
ValidateFunc: validation.NoZeroValues,
AtLeastOneOf: []string{Arg_InstanceID, Arg_InstanceName},
ConflictsWith: []string{Arg_InstanceID},
Deprecated: "The pi_instance_name field is deprecated. Please use pi_instance_id instead",
Description: "The name of the PVM instance.",
Optional: true,
Type: schema.TypeString,
ValidateFunc: validation.NoZeroValues,
},

// Attributes
Expand Down Expand Up @@ -301,9 +312,15 @@ func dataSourceIBMPIInstancesRead(ctx context.Context, d *schema.ResourceData, m
}

cloudInstanceID := d.Get(Arg_CloudInstanceID).(string)
var instanceID string
if v, ok := d.GetOk(Arg_InstanceID); ok {
instanceID = v.(string)
} else if v, ok := d.GetOk(Arg_InstanceName); ok {
instanceID = v.(string)
}

powerC := instance.NewIBMPIInstanceClient(ctx, sess, cloudInstanceID)
powervmdata, err := powerC.Get(d.Get(Arg_InstanceName).(string))
powervmdata, err := powerC.Get(instanceID)
if err != nil {
tfErr := flex.TerraformErrorf(err, fmt.Sprintf("Get failed: %s", err.Error()), "(Data) ibm_pi_instance", "read")
log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,22 @@ func DataSourceIBMPIInstanceConsoleLanguages() *schema.Resource {
Type: schema.TypeString,
ValidateFunc: validation.NoZeroValues,
},
Arg_InstanceID: {
AtLeastOneOf: []string{Arg_InstanceID, Arg_InstanceName},
ConflictsWith: []string{Arg_InstanceName},
Description: "The ID of the PVM instance.",
Optional: true,
Type: schema.TypeString,
ValidateFunc: validation.NoZeroValues,
},
Arg_InstanceName: {
Description: "The unique identifier or name of the instance.",
Required: true,
Type: schema.TypeString,
ValidateFunc: validation.NoZeroValues,
AtLeastOneOf: []string{Arg_InstanceID, Arg_InstanceName},
ConflictsWith: []string{Arg_InstanceID},
Deprecated: "The pi_instance_name field is deprecated. Please use pi_instance_id instead",
Description: "The name of the PVM instance.",
Optional: true,
Type: schema.TypeString,
ValidateFunc: validation.NoZeroValues,
},

// Attributes
Expand Down Expand Up @@ -69,10 +80,15 @@ func dataSourceIBMPIInstanceConsoleLanguagesRead(ctx context.Context, d *schema.
}

cloudInstanceID := d.Get(Arg_CloudInstanceID).(string)
instanceName := d.Get(Arg_InstanceName).(string)
var instanceID string
if v, ok := d.GetOk(Arg_InstanceID); ok {
instanceID = v.(string)
} else if v, ok := d.GetOk(Arg_InstanceName); ok {
instanceID = v.(string)
}

client := instance.NewIBMPIInstanceClient(ctx, sess, cloudInstanceID)
languages, err := client.GetConsoleLanguages(instanceName)
languages, err := client.GetConsoleLanguages(instanceID)
if err != nil {
tfErr := flex.TerraformErrorf(err, fmt.Sprintf("GetConsoleLanguages failed: %s", err.Error()), "(Data) ibm_pi_instance_console_languages", "read")
log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func TestAccIBMPIInstanceConsoleLanguages(t *testing.T) {
func testAccCheckIBMPIInstanceConsoleLanguagesConfig() string {
return fmt.Sprintf(`
data "ibm_pi_console_languages" "example" {
pi_cloud_instance_id = "%s"
pi_instance_name = "%s"
}`, acc.Pi_cloud_instance_id, acc.Pi_instance_name)
pi_cloud_instance_id = "%[1]s"
pi_instance_id = "%[2]s"
}`, acc.Pi_cloud_instance_id, acc.Pi_instance_id)
}
27 changes: 22 additions & 5 deletions ibm/service/power/data_source_ibm_pi_instance_ip.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,22 @@ func DataSourceIBMPIInstanceIP() *schema.Resource {
Type: schema.TypeString,
ValidateFunc: validation.NoZeroValues,
},
Arg_InstanceID: {
AtLeastOneOf: []string{Arg_InstanceID, Arg_InstanceName},
ConflictsWith: []string{Arg_InstanceName},
Description: "The ID of the PVM instance.",
Optional: true,
Type: schema.TypeString,
ValidateFunc: validation.NoZeroValues,
},
Arg_InstanceName: {
Description: "The unique identifier or name of the instance.",
Required: true,
Type: schema.TypeString,
ValidateFunc: validation.NoZeroValues,
AtLeastOneOf: []string{Arg_InstanceID, Arg_InstanceName},
ConflictsWith: []string{Arg_InstanceID},
Deprecated: "The pi_instance_name field is deprecated. Please use pi_instance_id instead",
Description: "The name of the PVM instance.",
Optional: true,
Type: schema.TypeString,
ValidateFunc: validation.NoZeroValues,
},
Arg_NetworkName: {
Description: "The subnet that the instance belongs to.",
Expand Down Expand Up @@ -109,10 +120,16 @@ func dataSourceIBMPIInstancesIPRead(ctx context.Context, d *schema.ResourceData,
}

cloudInstanceID := d.Get(Arg_CloudInstanceID).(string)
var instanceID string
if v, ok := d.GetOk(Arg_InstanceID); ok {
instanceID = v.(string)
} else if v, ok := d.GetOk(Arg_InstanceName); ok {
instanceID = v.(string)
}
networkName := d.Get(Arg_NetworkName).(string)
powerC := instance.NewIBMPIInstanceClient(ctx, sess, cloudInstanceID)

powervmdata, err := powerC.Get(d.Get(Arg_InstanceName).(string))
powervmdata, err := powerC.Get(instanceID)
if err != nil {
tfErr := flex.TerraformErrorf(err, fmt.Sprintf("Get failed: %s", err.Error()), "(Data) ibm_pi_instance_ip", "read")
log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage())
Expand Down
8 changes: 4 additions & 4 deletions ibm/service/power/data_source_ibm_pi_instance_ip_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ func TestAccIBMPIInstanceIPDataSource_basic(t *testing.T) {
func testAccCheckIBMPIInstanceIPDataSourceConfig() string {
return fmt.Sprintf(`
data "ibm_pi_instance_ip" "testacc_ds_instance_ip" {
pi_network_name = "%[1]s"
pi_instance_name = "%[2]s"
pi_cloud_instance_id = "%[3]s"
}`, acc.Pi_network_name, acc.Pi_instance_name, acc.Pi_cloud_instance_id)
pi_cloud_instance_id = "%[1]s"
pi_instance_id = "%[2]s"
pi_network_name = "%[3]s"
}`, acc.Pi_cloud_instance_id, acc.Pi_instance_id, acc.Pi_network_name)
}
6 changes: 3 additions & 3 deletions ibm/service/power/data_source_ibm_pi_instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func TestAccIBMPIInstanceDataSource_basic(t *testing.T) {
func testAccCheckIBMPIInstanceDataSourceConfig() string {
return fmt.Sprintf(`
data "ibm_pi_instance" "testacc_ds_instance" {
pi_instance_name="%s"
pi_cloud_instance_id = "%s"
}`, acc.Pi_instance_name, acc.Pi_cloud_instance_id)
pi_cloud_instance_id = "%[1]s"
pi_instance_id = "%[2]s"
}`, acc.Pi_cloud_instance_id, acc.Pi_instance_id)
}
Loading
Loading