Skip to content

Commit 2350ea5

Browse files
committed
added acceptance test and fixed bugs
1 parent 3d41b0a commit 2350ea5

8 files changed

+232
-23
lines changed

ibm/service/vpc/data_source_ibm_is_instance.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2197,7 +2197,7 @@ func DataSourceIBMIsInstanceDeletedToMap(model *vpcv1.Deleted) (map[string]inter
21972197

21982198
func DataSourceIBMIsInstanceInstanceVcpuToMap(model *vpcv1.InstanceVcpu) (map[string]interface{}, error) {
21992199
modelMap := make(map[string]interface{})
2200-
modelMap["architecture"] = *model.Architecture
2200+
modelMap["architecture"] = model.Architecture
22012201
if model.Burst != nil {
22022202
burstMap, err := DataSourceIBMIsInstanceInstanceVcpuBurstToMap(model.Burst)
22032203
if err != nil {
@@ -2206,9 +2206,9 @@ func DataSourceIBMIsInstanceInstanceVcpuToMap(model *vpcv1.InstanceVcpu) (map[st
22062206
modelMap["burst"] = []map[string]interface{}{burstMap}
22072207
}
22082208
modelMap["count"] = flex.IntValue(model.Count)
2209-
modelMap["manufacturer"] = *model.Manufacturer
2209+
modelMap["manufacturer"] = model.Manufacturer
22102210
modelMap["percentage"] = flex.IntValue(model.Percentage)
2211-
modelMap["tenancy"] = *model.Tenancy
2211+
modelMap["tenancy"] = model.Tenancy
22122212
return modelMap, nil
22132213
}
22142214

ibm/service/vpc/data_source_ibm_is_instance_template.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3674,7 +3674,7 @@ func DataSourceIBMIsInstanceTemplateInstanceVcpuPrototypeToMap(model *vpcv1.Inst
36743674
modelMap["percentage"] = flex.IntValue(model.Percentage)
36753675
}
36763676
if model.Tenancy != nil {
3677-
modelMap["tenancy"] = *model.Tenancy
3677+
modelMap["tenancy"] = model.Tenancy
36783678
}
36793679
return modelMap, nil
36803680
}

ibm/service/vpc/data_source_ibm_is_instance_templates.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2073,7 +2073,7 @@ func DataSourceIBMIsInstanceTemplatesInstanceVcpuPrototypeToMap(model *vpcv1.Ins
20732073
modelMap["percentage"] = flex.IntValue(model.Percentage)
20742074
}
20752075
if model.Tenancy != nil {
2076-
modelMap["tenancy"] = *model.Tenancy
2076+
modelMap["tenancy"] = model.Tenancy
20772077
}
20782078
return modelMap, nil
20792079
}

ibm/service/vpc/data_source_ibm_is_instances.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1919,7 +1919,7 @@ func dataSourceInstancesCollectionHealthReasonsToMap(statusReasonsItem vpcv1.Ins
19191919

19201920
func DataSourceIBMIsInstancesInstanceVcpuToMap(model *vpcv1.InstanceVcpu) (map[string]interface{}, error) {
19211921
modelMap := make(map[string]interface{})
1922-
modelMap["architecture"] = *model.Architecture
1922+
modelMap["architecture"] = model.Architecture
19231923
if model.Burst != nil {
19241924
burstMap, err := DataSourceIBMIsInstancesInstanceVcpuBurstToMap(model.Burst)
19251925
if err != nil {
@@ -1928,9 +1928,9 @@ func DataSourceIBMIsInstancesInstanceVcpuToMap(model *vpcv1.InstanceVcpu) (map[s
19281928
modelMap["burst"] = []map[string]interface{}{burstMap}
19291929
}
19301930
modelMap["count"] = flex.IntValue(model.Count)
1931-
modelMap["manufacturer"] = *model.Manufacturer
1931+
modelMap["manufacturer"] = model.Manufacturer
19321932
modelMap["percentage"] = flex.IntValue(model.Percentage)
1933-
modelMap["tenancy"] = *model.Tenancy
1933+
modelMap["tenancy"] = model.Tenancy
19341934
return modelMap, nil
19351935
}
19361936

ibm/service/vpc/resource_ibm_is_instance.go

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -730,6 +730,7 @@ func ResourceIBMISInstance() *schema.Resource {
730730
Type: schema.TypeList,
731731
MaxItems: 1,
732732
Optional: true,
733+
Computed: true,
733734
Description: "The virtual server instance VCPU configuration.",
734735
Elem: &schema.Resource{
735736
Schema: map[string]*schema.Schema{
@@ -763,12 +764,14 @@ func ResourceIBMISInstance() *schema.Resource {
763764
},
764765
"percentage": &schema.Schema{
765766
Type: schema.TypeInt,
766-
Required: true,
767+
Optional: true,
768+
Computed: true,
767769
Description: "The percentage of VCPU time allocated to the virtual server instance.The virtual server instance `vcpu.percentage` will be `100` when:- The virtual server instance `placement_target` is a dedicated host or dedicated host group.- The virtual server instance `reservation_affinity.policy` is `disabled`.",
768770
},
769771
"tenancy": &schema.Schema{
770772
Type: schema.TypeString,
771-
Required: true,
773+
Optional: true,
774+
Computed: true,
772775
Description: "Indicates the tenancy of the VCPU cores for this virtual server instance.- `dedicated` - The VCPU time is only used by this virtual server instance.- `shared` - The VCPU time is shared across virtual server instances.The enumerated values for this property may[expand](https://cloud.ibm.com/apidocs/vpc#property-value-expansion) in the future.",
773776
},
774777
},
@@ -5483,18 +5486,6 @@ func instanceGet(context context.Context, d *schema.ResourceData, meta interface
54835486
return flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_is_instance", "read", "set-profile").GetDiag()
54845487
}
54855488
}
5486-
cpuList := make([]map[string]interface{}, 0)
5487-
if instance.Vcpu != nil {
5488-
currentCPU := map[string]interface{}{}
5489-
currentCPU[isInstanceCPUArch] = *instance.Vcpu.Architecture
5490-
currentCPU[isInstanceCPUCount] = *instance.Vcpu.Count
5491-
currentCPU[isInstanceCPUManufacturer] = instance.Vcpu.Manufacturer
5492-
cpuList = append(cpuList, currentCPU)
5493-
}
5494-
if err = d.Set(isInstanceCPU, cpuList); err != nil {
5495-
err = fmt.Errorf("Error setting vcpu: %s", err)
5496-
return flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_is_instance", "read", "set-vcpu").GetDiag()
5497-
}
54985489
if instance.Bandwidth != nil {
54995490
if err = d.Set("bandwidth", flex.IntValue(instance.Bandwidth)); err != nil {
55005491
err = fmt.Errorf("Error setting bandwidth: %s", err)
@@ -7417,6 +7408,7 @@ func instanceUpdate(context context.Context, d *schema.ResourceData, meta interf
74177408
instanceCCMPatchModel := &vpcv1.InstancePatch{}
74187409
if d.HasChange("vcpu") {
74197410
vcpu, err := ResourceIBMIsInstanceMapToInstanceVcpuPatch(d.Get("vcpu.0").(map[string]interface{}))
7411+
restartNeeded = true
74207412
if err != nil {
74217413
return flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_is_instance", "update", "parse-vcpu").GetDiag()
74227414
}
@@ -9558,7 +9550,7 @@ func ResourceIBMIsInstanceMapToInstanceVcpuPatch(modelMap map[string]interface{}
95589550
}
95599551
func ResourceIBMIsInstanceMapToInstanceVcpuPrototype(modelMap map[string]interface{}) (*vpcv1.InstanceVcpuPrototype, error) {
95609552
model := &vpcv1.InstanceVcpuPrototype{}
9561-
if modelMap["percentage"] != nil {
9553+
if modelMap["percentage"] != nil && modelMap["percentage"].(int) != 0 {
95629554
model.Percentage = core.Int64Ptr(int64(modelMap["percentage"].(int)))
95639555
}
95649556
if modelMap["tenancy"] != nil && modelMap["tenancy"].(string) != "" {

ibm/service/vpc/resource_ibm_is_instance_template.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1310,6 +1310,7 @@ func ResourceIBMISInstanceTemplate() *schema.Resource {
13101310
Type: schema.TypeList,
13111311
MaxItems: 1,
13121312
Optional: true,
1313+
ForceNew: true,
13131314
Elem: &schema.Resource{
13141315
Schema: map[string]*schema.Schema{
13151316
"percentage": &schema.Schema{

ibm/service/vpc/resource_ibm_is_instance_template_test.go

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1532,3 +1532,88 @@ func testAccCheckIBMISInstanceTemplateWith_AllowedUse(vpcname, subnetname, sshna
15321532
`, templateName, apiVersion, bareMetalServer, instanceVal, apiVersion, bareMetalServer, instanceVal, acc.ISZoneName)
15331533

15341534
}
1535+
1536+
// shared core
1537+
func TestAccIBMISInstanceTemplate_vcpu(t *testing.T) {
1538+
randInt := acctest.RandIntRange(10, 100)
1539+
1540+
publicKey := strings.TrimSpace(`
1541+
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQDVtuCfWKVGKaRmaRG6JQZY8YdxnDgGzVOK93IrV9R5Hl0JP1oiLLWlZQS2reAKb8lBqyDVEREpaoRUDjqDqXG8J/kR42FKN51su914pjSBc86wJ02VtT1Wm1zRbSg67kT+g8/T1jCgB5XBODqbcICHVP8Z1lXkgbiHLwlUrbz6OZkGJHo/M/kD1Eme8lctceIYNz/Ilm7ewMXZA4fsidpto9AjyarrJLufrOBl4MRVcZTDSJ7rLP982aHpu9pi5eJAjOZc7Og7n4ns3NFppiCwgVMCVUQbN5GBlWhZ1OsT84ZiTf+Zy8ew+Yg5T7Il8HuC7loWnz+esQPf0s3xhC/kTsGgZreIDoh/rxJfD67wKXetNSh5RH/n5BqjaOuXPFeNXmMhKlhj9nJ8scayx/wsvOGuocEIkbyJSLj3sLUU403OafgatEdnJOwbqg6rUNNF5RIjpJpL7eEWlKIi1j9LyhmPJ+fEO7TmOES82VpCMHpLbe4gf/MhhJ/Xy8DKh9s= root@ffd8363b1226
1542+
`)
1543+
vpcName := fmt.Sprintf("tf-testvpc%d", randInt)
1544+
subnetName := fmt.Sprintf("tf-testsubnet%d", randInt)
1545+
sshKeyName := fmt.Sprintf("tf-testsshkey%d", randInt)
1546+
prefix := fmt.Sprintf("tf-%d", randInt)
1547+
1548+
resource.Test(t, resource.TestCase{
1549+
PreCheck: func() { acc.TestAccPreCheck(t) },
1550+
Providers: acc.TestAccProviders,
1551+
CheckDestroy: testAccCheckIBMISInstanceTemplateDestroy,
1552+
Steps: []resource.TestStep{
1553+
{
1554+
Config: testAccCheckIBMISInstanceTemplateVCPUConfig(vpcName, subnetName, sshKeyName, publicKey, prefix),
1555+
Check: resource.ComposeTestCheckFunc(
1556+
resource.TestCheckResourceAttr(
1557+
"ibm_is_instance_template.is_instance_template", "name", fmt.Sprintf("%s-ins", prefix)),
1558+
resource.TestCheckResourceAttr(
1559+
"ibm_is_instance_template.is_instance_template", "vcpu.0.percentage", "100"),
1560+
resource.TestCheckResourceAttr(
1561+
"ibm_is_instance_template.is_instance_template", "vcpu.0.tenancy", "dedicated"),
1562+
resource.TestCheckResourceAttr(
1563+
"ibm_is_instance_template.is_instance_template", "reservation_affinity.0.policy", "disabled"),
1564+
resource.TestCheckResourceAttr(
1565+
"ibm_is_instance_template.is_instance_template", "zone", acc.ISZoneName),
1566+
resource.TestCheckResourceAttrSet(
1567+
"ibm_is_instance_template.is_instance_template", "profile"),
1568+
resource.TestCheckResourceAttrSet(
1569+
"ibm_is_instance_template.is_instance_template", "primary_network_attachment.0.name"),
1570+
),
1571+
},
1572+
},
1573+
})
1574+
}
1575+
1576+
func testAccCheckIBMISInstanceTemplateVCPUConfig(vpcName, subnetName, sshKeyName, publicKey, prefix string) string {
1577+
return fmt.Sprintf(`
1578+
resource "ibm_is_vpc" "vpc1" {
1579+
name = "%s"
1580+
}
1581+
1582+
resource "ibm_is_subnet" "subnet1" {
1583+
name = "%s"
1584+
vpc = ibm_is_vpc.vpc1.id
1585+
zone = "%s"
1586+
ipv4_cidr_block = "%s"
1587+
}
1588+
1589+
resource "ibm_is_ssh_key" "is_key" {
1590+
name = "%s"
1591+
public_key = "%s"
1592+
}
1593+
1594+
data "ibm_is_images" "is_images" {
1595+
}
1596+
1597+
resource "ibm_is_instance_template" "is_instance_template" {
1598+
name = "%s-ins"
1599+
image = data.ibm_is_images.is_images.images.0.id
1600+
profile = "%s"
1601+
vpc = ibm_is_vpc.vpc1.id
1602+
zone = ibm_is_subnet.subnet1.zone
1603+
keys = [ibm_is_ssh_key.is_key.id]
1604+
primary_network_attachment {
1605+
name = "%s-pna2"
1606+
virtual_network_interface {
1607+
subnet = ibm_is_subnet.subnet1.id
1608+
}
1609+
}
1610+
reservation_affinity {
1611+
policy = "disabled"
1612+
}
1613+
vcpu {
1614+
percentage = 100
1615+
tenancy = "dedicated"
1616+
}
1617+
}
1618+
`, vpcName, subnetName, acc.ISZoneName, acc.ISCIDR, sshKeyName, publicKey, prefix, acc.InstanceProfileName, prefix)
1619+
}

ibm/service/vpc/resource_ibm_is_instance_test.go

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4562,3 +4562,134 @@ func testAccCheckIBMISInstanceConfig_AllowedUse(vpcname, subnetname, sshname, pu
45624562
}
45634563
`, insName, acc.InstanceProfileName, acc.ISZoneName, apiVersion, bareMetalServer, instanceval, apiVersion, bareMetalServer, instanceval)
45644564
}
4565+
4566+
// shared core
4567+
4568+
func TestAccIBMISInstance_vcpu(t *testing.T) {
4569+
var instance string
4570+
4571+
vpcname := fmt.Sprintf("tf-vpc-%d", acctest.RandIntRange(10, 100))
4572+
subnetname := fmt.Sprintf("tf-subnet-%d", acctest.RandIntRange(10, 100))
4573+
sshname := fmt.Sprintf("tf-ssh-%d", acctest.RandIntRange(10, 100))
4574+
prefix := fmt.Sprintf("tf-%d", acctest.RandIntRange(10, 100))
4575+
4576+
publicKey := strings.TrimSpace(`
4577+
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCKVmnMOlHKcZK8tpt3MP1lqOLAcqcJzhsvJcjscgVERRN7/9484SOBJ3HSKxxNG5JN8owAjy5f9yYwcUg+JaUVuytn5Pv3aeYROHGGg+5G346xaq3DAwX6Y5ykr2fvjObgncQBnuU5KHWCECO/4h8uWuwh/kfniXPVjFToc+gnkqA+3RKpAecZhFXwfalQ9mMuYGFxn+fwn8cYEApsJbsEmb0iJwPiZ5hjFC8wREuiTlhPHDgkBLOiycd20op2nXzDbHfCHInquEe/gYxEitALONxm0swBOwJZwlTDOB7C6y2dzlrtxr1L59m7pCkWI4EtTRLvleehBoj3u7jB4usR
4578+
`)
4579+
4580+
resource.Test(t, resource.TestCase{
4581+
PreCheck: func() { acc.TestAccPreCheck(t) },
4582+
Providers: acc.TestAccProviders,
4583+
CheckDestroy: testAccCheckIBMISInstanceDestroy,
4584+
Steps: []resource.TestStep{
4585+
{
4586+
Config: testAccCheckIBMISInstanceVCPUConfig(vpcname, subnetname, sshname, publicKey, prefix),
4587+
Check: resource.ComposeTestCheckFunc(
4588+
testAccCheckIBMISInstanceExists("ibm_is_instance.is_instance", instance),
4589+
resource.TestCheckResourceAttr("ibm_is_instance.is_instance", "name", fmt.Sprintf("%s-ins", prefix)),
4590+
resource.TestCheckResourceAttr("ibm_is_instance.is_instance", "vcpu.0.percentage", "100"),
4591+
resource.TestCheckResourceAttr("ibm_is_instance.is_instance", "vcpu.0.tenancy", "dedicated"),
4592+
resource.TestCheckResourceAttr("ibm_is_instance.is_instance", "reservation_affinity.0.policy", "disabled"),
4593+
resource.TestCheckResourceAttr("ibm_is_instance.is_instance", "zone", acc.ISZoneName),
4594+
resource.TestCheckResourceAttrSet("ibm_is_instance.is_instance", "primary_network_attachment.0.name"),
4595+
),
4596+
},
4597+
{
4598+
Config: testAccCheckIBMISInstanceVCPUConfigUpdate(vpcname, subnetname, sshname, publicKey, prefix),
4599+
Check: resource.ComposeTestCheckFunc(
4600+
testAccCheckIBMISInstanceExists("ibm_is_instance.is_instance", instance),
4601+
resource.TestCheckResourceAttr("ibm_is_instance.is_instance", "name", fmt.Sprintf("%s-ins", prefix)),
4602+
resource.TestCheckResourceAttr("ibm_is_instance.is_instance", "vcpu.0.percentage", "25"),
4603+
resource.TestCheckResourceAttr("ibm_is_instance.is_instance", "vcpu.0.tenancy", "shared"),
4604+
resource.TestCheckResourceAttr("ibm_is_instance.is_instance", "reservation_affinity.0.policy", "disabled"),
4605+
resource.TestCheckResourceAttr("ibm_is_instance.is_instance", "zone", acc.ISZoneName),
4606+
resource.TestCheckResourceAttrSet("ibm_is_instance.is_instance", "primary_network_attachment.0.name"),
4607+
),
4608+
},
4609+
},
4610+
})
4611+
}
4612+
4613+
func testAccCheckIBMISInstanceVCPUConfig(vpcname, subnetname, sshname, publicKey, prefix string) string {
4614+
return fmt.Sprintf(`
4615+
resource "ibm_is_vpc" "vpc1" {
4616+
name = "%s"
4617+
}
4618+
4619+
resource "ibm_is_subnet" "subnet1" {
4620+
name = "%s"
4621+
vpc = ibm_is_vpc.vpc1.id
4622+
zone = "%s"
4623+
ipv4_cidr_block = "%s"
4624+
}
4625+
4626+
resource "ibm_is_ssh_key" "is_key" {
4627+
name = "%s"
4628+
public_key = "%s"
4629+
}
4630+
4631+
resource "ibm_is_instance" "is_instance" {
4632+
name = "%s-ins"
4633+
image = "%s"
4634+
profile = "%s"
4635+
vpc = ibm_is_vpc.vpc1.id
4636+
zone = ibm_is_subnet.subnet1.zone
4637+
keys = [ibm_is_ssh_key.is_key.id]
4638+
primary_network_attachment {
4639+
name = "%s-pna2"
4640+
virtual_network_interface {
4641+
subnet = ibm_is_subnet.subnet1.id
4642+
}
4643+
}
4644+
reservation_affinity {
4645+
policy = "disabled"
4646+
}
4647+
vcpu {
4648+
percentage = 100
4649+
tenancy = "dedicated"
4650+
}
4651+
}
4652+
`, vpcname, subnetname, acc.ISZoneName, acc.ISCIDR, sshname, publicKey, prefix, acc.IsImage, acc.InstanceProfileName, prefix)
4653+
}
4654+
4655+
func testAccCheckIBMISInstanceVCPUConfigUpdate(vpcname, subnetname, sshname, publicKey, prefix string) string {
4656+
return fmt.Sprintf(`
4657+
resource "ibm_is_vpc" "vpc1" {
4658+
name = "%s"
4659+
}
4660+
4661+
resource "ibm_is_subnet" "subnet1" {
4662+
name = "%s"
4663+
vpc = ibm_is_vpc.vpc1.id
4664+
zone = "%s"
4665+
ipv4_cidr_block = "%s"
4666+
}
4667+
4668+
resource "ibm_is_ssh_key" "is_key" {
4669+
name = "%s"
4670+
public_key = "%s"
4671+
}
4672+
4673+
resource "ibm_is_instance" "is_instance" {
4674+
name = "%s-ins"
4675+
image = "%s"
4676+
profile = "%s"
4677+
vpc = ibm_is_vpc.vpc1.id
4678+
zone = ibm_is_subnet.subnet1.zone
4679+
keys = [ibm_is_ssh_key.is_key.id]
4680+
primary_network_attachment {
4681+
name = "%s-pna2"
4682+
virtual_network_interface {
4683+
subnet = ibm_is_subnet.subnet1.id
4684+
}
4685+
}
4686+
reservation_affinity {
4687+
policy = "disabled"
4688+
}
4689+
vcpu {
4690+
percentage = 25
4691+
tenancy = "shared"
4692+
}
4693+
}
4694+
`, vpcname, subnetname, acc.ISZoneName, acc.ISCIDR, sshname, publicKey, prefix, acc.IsImage, acc.InstanceProfileName, prefix)
4695+
}

0 commit comments

Comments
 (0)