Skip to content

Commit 6c9bad9

Browse files
authored
Fix: support boot volume profile configuration for is_instance creation (IBM-Cloud#6528)
1 parent 1ffd00a commit 6c9bad9

File tree

3 files changed

+161
-1
lines changed

3 files changed

+161
-1
lines changed

ibm/service/vpc/resource_ibm_is_instance.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3110,6 +3110,11 @@ func instanceCreateByCatalogOffering(context context.Context, d *schema.Resource
31103110
}
31113111

31123112
volprof := "general-purpose"
3113+
// profile changes
3114+
bootvolProfileOk, ok := bootvol["profile"]
3115+
if ok && bootvolProfileOk.(string) != "" {
3116+
volprof = bootvolProfileOk.(string)
3117+
}
31133118
volTemplate.Profile = &vpcv1.VolumeProfileIdentity{
31143119
Name: &volprof,
31153120
}
@@ -3676,7 +3681,11 @@ func instanceCreateByTemplate(context context.Context, d *schema.ResourceData, m
36763681
}
36773682

36783683
volprof := "general-purpose"
3679-
3684+
// profile changes
3685+
bootvolProfileOk, ok := bootvol["profile"]
3686+
if ok && bootvolProfileOk.(string) != "" {
3687+
volprof = bootvolProfileOk.(string)
3688+
}
36803689
volTemplate.Profile = &vpcv1.VolumeProfileIdentity{
36813690
Name: &volprof,
36823691
}
@@ -4237,6 +4246,11 @@ func instanceCreateBySnapshot(context context.Context, d *schema.ResourceData, m
42374246
}
42384247
}
42394248
volprof := "general-purpose"
4249+
// profile changes
4250+
bootvolProfileOk, ok := bootvol["profile"]
4251+
if ok && bootvolProfileOk.(string) != "" {
4252+
volprof = bootvolProfileOk.(string)
4253+
}
42404254
volTemplate.Profile = &vpcv1.VolumeProfileIdentity{
42414255
Name: &volprof,
42424256
}

ibm/service/vpc/resource_ibm_is_instance_test.go

Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4633,3 +4633,148 @@ func testAccCheckIBMISInstanceConfig_AllowedUse(vpcname, subnetname, sshname, pu
46334633
}
46344634
`, insName, acc.InstanceProfileName, acc.ISZoneName, apiVersion, bareMetalServer, instanceval, apiVersion, bareMetalServer, instanceval)
46354635
}
4636+
4637+
// boot volume profile test
4638+
4639+
func TestAccIBMISInstance_BootVolumeVariations(t *testing.T) {
4640+
var instance string
4641+
vpcname := fmt.Sprintf("tf-vpc-%d", acctest.RandIntRange(10, 100))
4642+
subnetname := fmt.Sprintf("tf-subnet-%d", acctest.RandIntRange(10, 100))
4643+
sshname := fmt.Sprintf("tf-ssh-%d", acctest.RandIntRange(10, 100))
4644+
templatename := fmt.Sprintf("tf-template-%d", acctest.RandIntRange(10, 100))
4645+
sourceInstanceName := fmt.Sprintf("tf-instance-source-%d", acctest.RandIntRange(10, 100))
4646+
instanceFromTemplateName := fmt.Sprintf("tf-instance-template-%d", acctest.RandIntRange(10, 100))
4647+
instanceFromCatalogName := fmt.Sprintf("tf-instance-catalog-%d", acctest.RandIntRange(10, 100))
4648+
snapshotname := fmt.Sprintf("tf-snapshot-%d", acctest.RandIntRange(10, 100))
4649+
instanceFromSnapshotName := fmt.Sprintf("tf-instance-snapshot-%d", acctest.RandIntRange(10, 100))
4650+
publicKey := strings.TrimSpace(`
4651+
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCKVmnMOlHKcZK8tpt3MP1lqOLAcqcJzhsvJcjscgVERRN7/9484SOBJ3HSKxxNG5JN8owAjy5f9yYwcUg+JaUVuytn5Pv3aeYROHGGg+5G346xaq3DAwX6Y5ykr2fvjObgncQBnuU5KHWCECO/4h8uWuwh/kfniXPVjFToc+gnkqA+3RKpAecZhFXwfalQ9mMuYGFxn+fwn8cYEApsJbsEmb0iJwPiZ5hjFC8wREuiTlhPHDgkBLOiycd20op2nXzDbHfCHInquEe/gYxEitALONxm0swBOwJZwlTDOB7C6y2dzlrtxr1L59m7pCkWI4EtTRLvleehBoj3u7jB4usR
4652+
`)
4653+
4654+
resource.Test(t, resource.TestCase{
4655+
PreCheck: func() { acc.TestAccPreCheck(t) },
4656+
Providers: acc.TestAccProviders,
4657+
CheckDestroy: testAccCheckIBMISInstanceDestroy,
4658+
Steps: []resource.TestStep{
4659+
{
4660+
Config: testAccCheckIBMISInstanceBootVolumeConfig(vpcname, subnetname, sshname, publicKey, templatename, sourceInstanceName, snapshotname, instanceFromTemplateName, instanceFromCatalogName, instanceFromSnapshotName),
4661+
Check: resource.ComposeTestCheckFunc(
4662+
// Verify instance from template with boot volume
4663+
testAccCheckIBMISInstanceExists("ibm_is_instance.testacc_instance_template", instance),
4664+
resource.TestCheckResourceAttr(
4665+
"ibm_is_instance.testacc_instance_template", "name", instanceFromTemplateName),
4666+
resource.TestCheckResourceAttrSet(
4667+
"ibm_is_instance.testacc_instance_template", "instance_template"),
4668+
resource.TestCheckResourceAttr(
4669+
"ibm_is_instance.testacc_instance_template", "boot_volume.0.profile", "sdp"),
4670+
resource.TestCheckResourceAttrSet(
4671+
"ibm_is_instance.testacc_instance_template", "boot_volume.0.name"),
4672+
resource.TestCheckResourceAttrSet(
4673+
"ibm_is_instance.testacc_instance_template", "primary_network_attachment.0.id"),
4674+
resource.TestCheckResourceAttr(
4675+
"ibm_is_instance.testacc_instance_template", "zone", acc.ISZoneName),
4676+
4677+
// Verify instance from catalog with boot volume
4678+
testAccCheckIBMISInstanceExists("ibm_is_instance.testacc_instance_catalog", instance),
4679+
resource.TestCheckResourceAttr(
4680+
"ibm_is_instance.testacc_instance_catalog", "name", instanceFromCatalogName),
4681+
resource.TestCheckResourceAttr(
4682+
"ibm_is_instance.testacc_instance_catalog", "boot_volume.0.profile", "sdp"),
4683+
resource.TestCheckResourceAttrSet(
4684+
"ibm_is_instance.testacc_instance_catalog", "boot_volume.0.name"),
4685+
resource.TestCheckResourceAttrSet(
4686+
"ibm_is_instance.testacc_instance_catalog", "catalog_offering.0.version_crn"),
4687+
resource.TestCheckResourceAttrSet(
4688+
"ibm_is_instance.testacc_instance_catalog", "primary_network_attachment.0.id"),
4689+
resource.TestCheckResourceAttr(
4690+
"ibm_is_instance.testacc_instance_catalog", "zone", acc.ISZoneName),
4691+
),
4692+
},
4693+
},
4694+
})
4695+
}
4696+
4697+
func testAccCheckIBMISInstanceBootVolumeConfig(vpcname, subnetname, sshname, publicKey, templatename, sourceInstanceName, snapshotname, instanceFromTemplateName, instanceFromCatalogName, instanceFromSnapshotName string) string {
4698+
return fmt.Sprintf(`
4699+
resource "ibm_is_vpc" "testacc_vpc" {
4700+
name = "%s"
4701+
}
4702+
4703+
resource "ibm_is_subnet" "testacc_subnet" {
4704+
name = "%s"
4705+
vpc = ibm_is_vpc.testacc_vpc.id
4706+
zone = "%s"
4707+
total_ipv4_address_count = 64
4708+
}
4709+
4710+
resource "ibm_is_ssh_key" "testacc_sshkey" {
4711+
name = "%s"
4712+
public_key = "%s"
4713+
}
4714+
4715+
resource "ibm_is_instance_template" "instancetemplate1" {
4716+
name = "%s"
4717+
image = "%s"
4718+
profile = "bxf-2x8"
4719+
primary_network_attachment {
4720+
name = "pna-template"
4721+
virtual_network_interface {
4722+
subnet = ibm_is_subnet.testacc_subnet.id
4723+
}
4724+
}
4725+
vpc = ibm_is_vpc.testacc_vpc.id
4726+
zone = "%s"
4727+
keys = [ibm_is_ssh_key.testacc_sshkey.id]
4728+
}
4729+
4730+
resource "ibm_is_instance" "testacc_instance_source" {
4731+
name = "%s"
4732+
primary_network_attachment {
4733+
name = "pna-from-template"
4734+
virtual_network_interface {
4735+
subnet = ibm_is_subnet.testacc_subnet.id
4736+
}
4737+
}
4738+
instance_template = ibm_is_instance_template.instancetemplate1.id
4739+
}
4740+
4741+
resource "ibm_is_instance" "testacc_instance_template" {
4742+
name = "%s"
4743+
boot_volume {
4744+
profile = "sdp"
4745+
}
4746+
primary_network_attachment {
4747+
name = "pna-ins-from-template"
4748+
virtual_network_interface {
4749+
subnet = ibm_is_subnet.testacc_subnet.id
4750+
}
4751+
}
4752+
instance_template = ibm_is_instance_template.instancetemplate1.id
4753+
}
4754+
4755+
data "ibm_is_image" "catalog_image" {
4756+
name = "%s"
4757+
}
4758+
4759+
resource "ibm_is_instance" "testacc_instance_catalog" {
4760+
name = "%s"
4761+
profile = "bxf-2x8"
4762+
primary_network_attachment {
4763+
name = "pna-catalog"
4764+
virtual_network_interface {
4765+
subnet = ibm_is_subnet.testacc_subnet.id
4766+
}
4767+
}
4768+
boot_volume {
4769+
profile = "sdp"
4770+
}
4771+
catalog_offering {
4772+
version_crn = data.ibm_is_image.catalog_image.catalog_offering.0.version.0.crn
4773+
}
4774+
vpc = ibm_is_vpc.testacc_vpc.id
4775+
zone = ibm_is_subnet.testacc_subnet.zone
4776+
keys = [ibm_is_ssh_key.testacc_sshkey.id]
4777+
}
4778+
4779+
`, vpcname, subnetname, acc.ISZoneName, sshname, publicKey, templatename, acc.IsImage, acc.ISZoneName, sourceInstanceName, instanceFromTemplateName, acc.ISCatalogImageName, instanceFromCatalogName)
4780+
}

website/docs/r/is_instance.html.markdown

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -633,6 +633,7 @@ Review the argument references that you can specify for your resource.
633633
- `bandwidth` - (Optional, Integer) The maximum bandwidth (in megabits per second) for the volume. For this property to be specified, the volume storage_generation must be 2.
634634
- `encryption` - (Optional, String) The type of encryption to use for the boot volume.
635635
- `name` - (Optional, String) The name of the boot volume.
636+
- `profile` - (Optional, String) The name of the profile for this boot volume(not applicable for creating VSI with `volume_id`).
636637
- `size` - (Optional, Integer) The size of the boot volume.(The capacity of the volume in gigabytes. This defaults to minimum capacity of the image and maximum to `250`.)
637638

638639
~> **NOTE:**

0 commit comments

Comments
 (0)