Skip to content

Commit cd8bc79

Browse files
Instance template rebase changes
1 parent 560cbfd commit cd8bc79

File tree

2 files changed

+145
-8
lines changed

2 files changed

+145
-8
lines changed

ibm/service/vpc/resource_ibm_is_instance_template.go

Lines changed: 48 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3380,13 +3380,6 @@ func instanceTemplateGet(context context.Context, d *schema.ResourceData, meta i
33803380
err = fmt.Errorf("Error setting primary_network_interface: %s", err)
33813381
return flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_is_instance_template", "read", "set-primary_network_interface").GetDiag()
33823382
}
3383-
//allowed use
3384-
allowedUses := []map[string]interface{}{}
3385-
if volumeIntf.AllowedUse != nil {
3386-
modelMap, _ := ResourceIBMIsVolumeAllowedUseToMap(volumeIntf.AllowedUse)
3387-
allowedUses = append(allowedUses, modelMap)
3388-
}
3389-
bootVol["allowed_use"] = allowedUses
33903383
}
33913384

33923385
// catalog offering if any
@@ -3533,6 +3526,24 @@ func instanceTemplateGet(context context.Context, d *schema.ResourceData, meta i
35333526
if volumeInst.Bandwidth != nil {
35343527
newVolume["bandwidth"] = volumeInst.Bandwidth
35353528
}
3529+
// source_snapshot
3530+
if volumeInst.SourceSnapshot != nil {
3531+
sourceSnapshot := volumeInst.SourceSnapshot.(*vpcv1.SnapshotIdentity)
3532+
newVolume["source_snapshot"] = *sourceSnapshot.ID
3533+
}
3534+
3535+
//allowed use
3536+
allowedUses := []map[string]interface{}{}
3537+
if volumeInst.AllowedUse != nil {
3538+
modelMap, err := ResourceIBMIsVolumeAllowedUseToMap(volumeInst.AllowedUse)
3539+
if err != nil {
3540+
tfErr := flex.TerraformErrorf(err, err.Error(), "(Resource) ibm_is_instance_template", "read")
3541+
log.Println(tfErr.GetDiag())
3542+
}
3543+
allowedUses = append(allowedUses, modelMap)
3544+
newVolume["allowed_use"] = allowedUses
3545+
}
3546+
35363547
if len(newVolume) > 0 {
35373548
newVolumeArr = append(newVolumeArr, newVolume)
35383549
}
@@ -3568,6 +3579,13 @@ func instanceTemplateGet(context context.Context, d *schema.ResourceData, meta i
35683579
if volumeIntf.Bandwidth != nil {
35693580
bootVol["bandwidth"] = volumeIntf.Bandwidth
35703581
}
3582+
3583+
allowedUses := []map[string]interface{}{}
3584+
if volumeIntf.AllowedUse != nil {
3585+
modelMap, _ := ResourceIBMIsVolumeAllowedUseToMap(volumeIntf.AllowedUse)
3586+
allowedUses = append(allowedUses, modelMap)
3587+
}
3588+
bootVol["allowed_use"] = allowedUses
35713589
}
35723590

35733591
bootVolList = append(bootVolList, bootVol)
@@ -3923,6 +3941,23 @@ func instanceTemplateGet(context context.Context, d *schema.ResourceData, meta i
39233941
if volumeInst.Bandwidth != nil {
39243942
newVolume["bandwidth"] = volumeInst.Bandwidth
39253943
}
3944+
// source_snapshot
3945+
if volumeInst.SourceSnapshot != nil {
3946+
sourceSnapshot := volumeInst.SourceSnapshot.(*vpcv1.SnapshotIdentity)
3947+
newVolume["source_snapshot"] = *sourceSnapshot.ID
3948+
}
3949+
3950+
//allowed use
3951+
allowedUses := []map[string]interface{}{}
3952+
if volumeInst.AllowedUse != nil {
3953+
modelMap, err := ResourceIBMIsVolumeAllowedUseToMap(volumeInst.AllowedUse)
3954+
if err != nil {
3955+
tfErr := flex.TerraformErrorf(err, err.Error(), "(Resource) ibm_is_instance_template", "read")
3956+
log.Println(tfErr.GetDiag())
3957+
}
3958+
allowedUses = append(allowedUses, modelMap)
3959+
newVolume["allowed_use"] = allowedUses
3960+
}
39263961
if len(newVolume) > 0 {
39273962
newVolumeArr = append(newVolumeArr, newVolume)
39283963
}
@@ -3960,6 +3995,12 @@ func instanceTemplateGet(context context.Context, d *schema.ResourceData, meta i
39603995
if volumeIntf.Bandwidth != nil {
39613996
bootVol["bandwidth"] = volumeIntf.Bandwidth
39623997
}
3998+
allowedUses := []map[string]interface{}{}
3999+
if volumeIntf.AllowedUse != nil {
4000+
modelMap, _ := ResourceIBMIsVolumeAllowedUseToMap(volumeIntf.AllowedUse)
4001+
allowedUses = append(allowedUses, modelMap)
4002+
bootVol["allowed_use"] = allowedUses
4003+
}
39634004
}
39644005

39654006
bootVolList = append(bootVolList, bootVol)

ibm/service/vpc/resource_ibm_is_instance_template_test.go

Lines changed: 97 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1346,7 +1346,7 @@ func TestAccIBMISInstanceTemplate_comprehensive(t *testing.T) {
13461346
})
13471347
}
13481348

1349-
func TestAccIBMISInstanceTemplate_WithAllowedUse(t *testing.T) {
1349+
func TestAccIBMISInstanceTemplateBoot_WithAllowedUse(t *testing.T) {
13501350
randInt := acctest.RandIntRange(10, 100)
13511351

13521352
publicKey := strings.TrimSpace(`
@@ -1436,3 +1436,99 @@ func testAccCheckIBMISInstanceTemplateWithBoot_AllowedUse(vpcName, subnetName, s
14361436
`, vpcName, subnetName, acc.ISZoneName, sshKeyName, publicKey, templateName, acc.IsImage, userTag, bandwidth, apiVersion, bareMetalServer, instanceval, acc.ISZoneName)
14371437

14381438
}
1439+
1440+
func TestAccIBMISInstanceTemplate_WithAllowedUse(t *testing.T) {
1441+
vpcname := fmt.Sprintf("tf-vpc-%d", acctest.RandIntRange(10, 100))
1442+
name := fmt.Sprintf("tf-instnace-%d", acctest.RandIntRange(10, 100))
1443+
subnetname := fmt.Sprintf("tf-subnet-%d", acctest.RandIntRange(10, 100))
1444+
templateName := fmt.Sprintf("tf-instance-template-%d", acctest.RandIntRange(10, 100))
1445+
publicKey := strings.TrimSpace(`
1446+
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCKVmnMOlHKcZK8tpt3MP1lqOLAcqcJzhsvJcjscgVERRN7/9484SOBJ3HSKxxNG5JN8owAjy5f9yYwcUg+JaUVuytn5Pv3aeYROHGGg+5G346xaq3DAwX6Y5ykr2fvjObgncQBnuU5KHWCECO/4h8uWuwh/kfniXPVjFToc+gnkqA+3RKpAecZhFXwfalQ9mMuYGFxn+fwn8cYEApsJbsEmb0iJwPiZ5hjFC8wREuiTlhPHDgkBLOiycd20op2nXzDbHfCHInquEe/gYxEitALONxm0swBOwJZwlTDOB7C6y2dzlrtxr1L59m7pCkWI4EtTRLvleehBoj3u7jB4usR
1447+
`)
1448+
sshname := fmt.Sprintf("tf-ssh-%d", acctest.RandIntRange(10, 100))
1449+
volname := fmt.Sprintf("tf-vol-%d", acctest.RandIntRange(10, 100))
1450+
name1 := fmt.Sprintf("tfsnapshotuat-%d", acctest.RandIntRange(10, 100))
1451+
apiVersion := "2025-07-01"
1452+
bareMetalServer := "true"
1453+
instanceVal := "true"
1454+
resource.Test(t, resource.TestCase{
1455+
PreCheck: func() { acc.TestAccPreCheck(t) },
1456+
Providers: acc.TestAccProviders,
1457+
CheckDestroy: testAccCheckIBMISInstanceTemplateDestroy,
1458+
Steps: []resource.TestStep{
1459+
{
1460+
Config: testAccCheckIBMISInstanceTemplateWith_AllowedUse(vpcname, subnetname, sshname, publicKey, volname, name, name1, apiVersion, bareMetalServer, instanceVal, templateName),
1461+
Check: resource.ComposeTestCheckFunc(
1462+
resource.TestCheckResourceAttr(
1463+
"ibm_is_instance_template.instancetemplate1", "name", templateName),
1464+
// boot volume allowed use
1465+
resource.TestCheckResourceAttrSet(
1466+
"ibm_is_instance_template.instancetemplate1", "boot_volume.0.allowed_use.#"),
1467+
resource.TestCheckResourceAttrSet(
1468+
"ibm_is_instance_template.instancetemplate1", "boot_volume.0.allowed_use.0.bare_metal_server"),
1469+
resource.TestCheckResourceAttrSet(
1470+
"ibm_is_instance_template.instancetemplate1", "boot_volume.0.allowed_use.0.instance"),
1471+
resource.TestCheckResourceAttrSet(
1472+
"ibm_is_instance_template.instancetemplate1", "boot_volume.0.allowed_use.0.api_version"),
1473+
resource.TestCheckResourceAttr("ibm_is_instance_template.instancetemplate1", "boot_volume.0.allowed_use.0.bare_metal_server", bareMetalServer),
1474+
resource.TestCheckResourceAttr("ibm_is_instance_template.instancetemplate1", "boot_volume.0.allowed_use.0.instance", instanceVal),
1475+
resource.TestCheckResourceAttr("ibm_is_instance_template.instancetemplate1", "boot_volume.0.allowed_use.0.api_version", apiVersion),
1476+
1477+
// volume attchment volume_prototype allowed use
1478+
resource.TestCheckResourceAttrSet(
1479+
"ibm_is_instance_template.instancetemplate1", "volume_attachments.0.volume_prototype.0.allowed_use.#"),
1480+
resource.TestCheckResourceAttrSet(
1481+
"ibm_is_instance_template.instancetemplate1", "volume_attachments.0.volume_prototype.0.allowed_use.0.bare_metal_server"),
1482+
resource.TestCheckResourceAttrSet(
1483+
"ibm_is_instance_template.instancetemplate1", "volume_attachments.0.volume_prototype.0.allowed_use.0.instance"),
1484+
resource.TestCheckResourceAttrSet(
1485+
"ibm_is_instance_template.instancetemplate1", "volume_attachments.0.volume_prototype.0.allowed_use.0.api_version"),
1486+
resource.TestCheckResourceAttr("ibm_is_instance_template.instancetemplate1", "volume_attachments.0.volume_prototype.0.allowed_use.0.bare_metal_server", bareMetalServer),
1487+
resource.TestCheckResourceAttr("ibm_is_instance_template.instancetemplate1", "volume_attachments.0.volume_prototype.0.allowed_use.0.instance", instanceVal),
1488+
resource.TestCheckResourceAttr("ibm_is_instance_template.instancetemplate1", "volume_attachments.0.volume_prototype.0.allowed_use.0.api_version", apiVersion),
1489+
),
1490+
},
1491+
},
1492+
})
1493+
}
1494+
1495+
func testAccCheckIBMISInstanceTemplateWith_AllowedUse(vpcname, subnetname, sshname, publicKey, volname, name, sname, apiVersion, bareMetalServer, instanceVal, templateName string) string {
1496+
return testAccCheckIBMISSnapshotConfigAllowedUse(vpcname, subnetname, sshname, publicKey, volname, name, sname, apiVersion, bareMetalServer, instanceVal) + fmt.Sprintf(`
1497+
resource "ibm_is_instance_template" "instancetemplate1" {
1498+
name = "%s"
1499+
profile = "bx2-8x32"
1500+
primary_network_interface {
1501+
subnet = ibm_is_subnet.testacc_subnet.id
1502+
}
1503+
boot_volume {
1504+
profile = "general-purpose"
1505+
size = 250
1506+
source_snapshot = ibm_is_snapshot.testacc_snapshot.id
1507+
allowed_use {
1508+
api_version = "%s"
1509+
bare_metal_server = "%s"
1510+
instance = "%s"
1511+
}
1512+
}
1513+
volume_attachments {
1514+
delete_volume_on_instance_delete = true
1515+
name = "volume-attachment-tfp"
1516+
volume_prototype {
1517+
iops = 6000
1518+
profile = "custom"
1519+
capacity = 100
1520+
source_snapshot = ibm_is_snapshot.testacc_snapshot.id
1521+
allowed_use {
1522+
api_version = "%s"
1523+
bare_metal_server = "%s"
1524+
instance = "%s"
1525+
}
1526+
}
1527+
}
1528+
vpc = ibm_is_vpc.testacc_vpc.id
1529+
zone = "%s"
1530+
keys = [ibm_is_ssh_key.testacc_sshkey.id]
1531+
}
1532+
`, templateName, apiVersion, bareMetalServer, instanceVal, apiVersion, bareMetalServer, instanceVal, acc.ISZoneName)
1533+
1534+
}

0 commit comments

Comments
 (0)