Skip to content

Commit f7fa81e

Browse files
committed
Update resource_ibm_is_instance_test.go
1 parent 571dd88 commit f7fa81e

File tree

1 file changed

+93
-0
lines changed

1 file changed

+93
-0
lines changed

ibm/service/vpc/resource_ibm_is_instance_test.go

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4232,3 +4232,96 @@ ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCKVmnMOlHKcZK8tpt3MP1lqOLAcqcJzhsvJcjscgVE
42324232
},
42334233
})
42344234
}
4235+
4236+
func TestAccIBMISInstance_ProfileAndBandwidthUpdate(t *testing.T) {
4237+
var instance string
4238+
vpcname := fmt.Sprintf("tf-vpc-%d", acctest.RandIntRange(10, 100))
4239+
name := fmt.Sprintf("tf-instance-%d", acctest.RandIntRange(10, 100))
4240+
subnetname := fmt.Sprintf("tf-subnet-%d", acctest.RandIntRange(10, 100))
4241+
publicKey := strings.TrimSpace(`
4242+
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCKVmnMOlHKcZK8tpt3MP1lqOLAcqcJzhsvJcjscgVERRN7/9484SOBJ3HSKxxNG5JN8owAjy5f9yYwcUg+JaUVuytn5Pv3aeYROHGGg+5G346xaq3DAwX6Y5ykr2fvjObgncQBnuU5KHWCECO/4h8uWuwh/kfniXPVjFToc+gnkqA+3RKpAecZhFXwfalQ9mMuYGFxn+fwn8cYEApsJbsEmb0iJwPiZ5hjFC8wREuiTlhPHDgkBLOiycd20op2nXzDbHfCHInquEe/gYxEitALONxm0swBOwJZwlTDOB7C6y2dzlrtxr1L59m7pCkWI4EtTRLvleehBoj3u7jB4usR
4243+
`)
4244+
sshname := fmt.Sprintf("tf-ssh-%d", acctest.RandIntRange(10, 100))
4245+
initialProfile := "cx2-4x8" // Initial profile
4246+
updatedProfile := "cx2-48x96" // Updated profile
4247+
initialBandwidth := 2000 // Initial bandwidth
4248+
updatedBandwidth := 20000 // Updated bandwidth
4249+
prefix := fmt.Sprintf("tf-prefix-%d", acctest.RandIntRange(10, 100))
4250+
4251+
resource.Test(t, resource.TestCase{
4252+
PreCheck: func() { acc.TestAccPreCheck(t) },
4253+
Providers: acc.TestAccProviders,
4254+
CheckDestroy: testAccCheckIBMISInstanceDestroy,
4255+
Steps: []resource.TestStep{
4256+
// Step 1: Create instance with initial profile and bandwidth
4257+
{
4258+
Config: testAccCheckIBMISInstanceConfigWithProfileAndBandwidth(
4259+
vpcname, subnetname, sshname, publicKey, name, prefix, initialProfile, initialBandwidth),
4260+
Check: resource.ComposeTestCheckFunc(
4261+
testAccCheckIBMISInstanceExists("ibm_is_instance.testacc_instance", instance),
4262+
resource.TestCheckResourceAttr(
4263+
"ibm_is_instance.testacc_instance", "name", name),
4264+
resource.TestCheckResourceAttr(
4265+
"ibm_is_instance.testacc_instance", "profile", initialProfile),
4266+
resource.TestCheckResourceAttr(
4267+
"ibm_is_instance.testacc_instance", "total_volume_bandwidth", fmt.Sprintf("%d", initialBandwidth)),
4268+
resource.TestCheckResourceAttr(
4269+
"ibm_is_instance.testacc_instance", "zone", acc.ISZoneName),
4270+
),
4271+
},
4272+
// Step 2: Update both profile and bandwidth in a single operation
4273+
{
4274+
Config: testAccCheckIBMISInstanceConfigWithProfileAndBandwidth(
4275+
vpcname, subnetname, sshname, publicKey, name, prefix, updatedProfile, updatedBandwidth),
4276+
Check: resource.ComposeTestCheckFunc(
4277+
testAccCheckIBMISInstanceExists("ibm_is_instance.testacc_instance", instance),
4278+
resource.TestCheckResourceAttr(
4279+
"ibm_is_instance.testacc_instance", "name", name),
4280+
resource.TestCheckResourceAttr(
4281+
"ibm_is_instance.testacc_instance", "profile", updatedProfile),
4282+
resource.TestCheckResourceAttr(
4283+
"ibm_is_instance.testacc_instance", "total_volume_bandwidth", fmt.Sprintf("%d", updatedBandwidth)),
4284+
resource.TestCheckResourceAttr(
4285+
"ibm_is_instance.testacc_instance", "zone", acc.ISZoneName),
4286+
),
4287+
},
4288+
},
4289+
})
4290+
}
4291+
4292+
// Configuration function that allows specifying both profile and bandwidth with primary network attachment
4293+
func testAccCheckIBMISInstanceConfigWithProfileAndBandwidth(vpcname, subnetname, sshname, publicKey, name, prefix, profile string, bandwidth int) string {
4294+
return fmt.Sprintf(`
4295+
resource "ibm_is_vpc" "testacc_vpc" {
4296+
name = "%s"
4297+
}
4298+
4299+
resource "ibm_is_subnet" "testacc_subnet" {
4300+
name = "%s"
4301+
vpc = ibm_is_vpc.testacc_vpc.id
4302+
zone = "%s"
4303+
ipv4_cidr_block = "%s"
4304+
}
4305+
4306+
resource "ibm_is_ssh_key" "testacc_sshkey" {
4307+
name = "%s"
4308+
public_key = "%s"
4309+
}
4310+
4311+
resource "ibm_is_instance" "testacc_instance" {
4312+
name = "%s"
4313+
image = "%s"
4314+
profile = "%s"
4315+
total_volume_bandwidth = %d
4316+
primary_network_attachment {
4317+
name = "%s-pna"
4318+
virtual_network_interface {
4319+
subnet = ibm_is_subnet.testacc_subnet.id
4320+
}
4321+
}
4322+
vpc = ibm_is_vpc.testacc_vpc.id
4323+
zone = "%s"
4324+
keys = [ibm_is_ssh_key.testacc_sshkey.id]
4325+
wait_before_delete = false
4326+
}`, vpcname, subnetname, acc.ISZoneName, acc.ISCIDR, sshname, publicKey, name, acc.IsImage, profile, bandwidth, prefix, acc.ISZoneName)
4327+
}

0 commit comments

Comments
 (0)