Skip to content

Commit 67161fe

Browse files
authored
added primary_ip refernce to nac for consistency (IBM-Cloud#5847)
* added primary_ip refernce to nac for consistency * Added the documents for primary_ip addition * Added test cases
1 parent 9a70188 commit 67161fe

File tree

4 files changed

+233
-3
lines changed

4 files changed

+233
-3
lines changed

ibm/acctest/acctest.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -841,8 +841,8 @@ func init() {
841841
IsImage = os.Getenv("IS_IMAGE")
842842
if IsImage == "" {
843843
// IsImage = "fc538f61-7dd6-4408-978c-c6b85b69fe76" // for classic infrastructure
844-
IsImage = "r006-907911a7-0ffe-467e-8821-3cc9a0d82a39" // for next gen infrastructure ibm-centos-7-9-minimal-amd64-10 image
845-
fmt.Println("[INFO] Set the environment variable IS_IMAGE for testing ibm_is_instance, ibm_is_floating_ip else it is set to default value 'r006-907911a7-0ffe-467e-8821-3cc9a0d82a39'")
844+
IsImage = "r006-587a041d-9246-44f0-980b-56a327cf5bd7" // for next gen infrastructure ibm-ubuntu-24-04-6-minimal-amd64-1 us-south
845+
fmt.Println("[INFO] Set the environment variable IS_IMAGE for testing ibm_is_instance, ibm_is_floating_ip else it is set to default value 'r006-587a041d-9246-44f0-980b-56a327cf5bd7'")
846846
}
847847

848848
IsImage2 = os.Getenv("IS_IMAGE2")

ibm/service/vpc/resource_ibm_is_instance.go

+120-1
Original file line numberDiff line numberDiff line change
@@ -834,6 +834,55 @@ func ResourceIBMISInstance() *schema.Resource {
834834
Computed: true,
835835
Description: "The resource type.",
836836
},
837+
// primary_ip for consistency
838+
"primary_ip": &schema.Schema{
839+
Type: schema.TypeList,
840+
Computed: true,
841+
Description: "The primary IP address of the virtual network interface for the network attachment.",
842+
Elem: &schema.Resource{
843+
Schema: map[string]*schema.Schema{
844+
"address": &schema.Schema{
845+
Type: schema.TypeString,
846+
Computed: true,
847+
Description: "The IP address.If the address has not yet been selected, the value will be `0.0.0.0`.This property may add support for IPv6 addresses in the future. When processing a value in this property, verify that the address is in an expected format. If it is not, log an error. Optionally halt processing and surface the error, or bypass the resource on which the unexpected IP address format was encountered.",
848+
},
849+
"deleted": &schema.Schema{
850+
Type: schema.TypeList,
851+
Computed: true,
852+
Description: "If present, this property indicates the referenced resource has been deleted, and providessome supplementary information.",
853+
Elem: &schema.Resource{
854+
Schema: map[string]*schema.Schema{
855+
"more_info": &schema.Schema{
856+
Type: schema.TypeString,
857+
Computed: true,
858+
Description: "Link to documentation about deleted resources.",
859+
},
860+
},
861+
},
862+
},
863+
"href": &schema.Schema{
864+
Type: schema.TypeString,
865+
Computed: true,
866+
Description: "The URL for this reserved IP.",
867+
},
868+
"id": &schema.Schema{
869+
Type: schema.TypeString,
870+
Computed: true,
871+
Description: "The unique identifier for this reserved IP.",
872+
},
873+
"name": &schema.Schema{
874+
Type: schema.TypeString,
875+
Computed: true,
876+
Description: "The name for this reserved IP. The name is unique across all reserved IPs in a subnet.",
877+
},
878+
"resource_type": &schema.Schema{
879+
Type: schema.TypeString,
880+
Computed: true,
881+
Description: "The resource type.",
882+
},
883+
},
884+
},
885+
},
837886
"id": &schema.Schema{
838887
Type: schema.TypeString,
839888
Computed: true,
@@ -1198,7 +1247,55 @@ func ResourceIBMISInstance() *schema.Resource {
11981247
},
11991248
},
12001249
},
1201-
1250+
// primary_ip for consistency
1251+
"primary_ip": &schema.Schema{
1252+
Type: schema.TypeList,
1253+
Computed: true,
1254+
Description: "The primary IP address of the virtual network interface for the network attachment.",
1255+
Elem: &schema.Resource{
1256+
Schema: map[string]*schema.Schema{
1257+
"address": &schema.Schema{
1258+
Type: schema.TypeString,
1259+
Computed: true,
1260+
Description: "The IP address.If the address has not yet been selected, the value will be `0.0.0.0`.This property may add support for IPv6 addresses in the future. When processing a value in this property, verify that the address is in an expected format. If it is not, log an error. Optionally halt processing and surface the error, or bypass the resource on which the unexpected IP address format was encountered.",
1261+
},
1262+
"deleted": &schema.Schema{
1263+
Type: schema.TypeList,
1264+
Computed: true,
1265+
Description: "If present, this property indicates the referenced resource has been deleted, and providessome supplementary information.",
1266+
Elem: &schema.Resource{
1267+
Schema: map[string]*schema.Schema{
1268+
"more_info": &schema.Schema{
1269+
Type: schema.TypeString,
1270+
Computed: true,
1271+
Description: "Link to documentation about deleted resources.",
1272+
},
1273+
},
1274+
},
1275+
},
1276+
"href": &schema.Schema{
1277+
Type: schema.TypeString,
1278+
Computed: true,
1279+
Description: "The URL for this reserved IP.",
1280+
},
1281+
"id": &schema.Schema{
1282+
Type: schema.TypeString,
1283+
Computed: true,
1284+
Description: "The unique identifier for this reserved IP.",
1285+
},
1286+
"name": &schema.Schema{
1287+
Type: schema.TypeString,
1288+
Computed: true,
1289+
Description: "The name for this reserved IP. The name is unique across all reserved IPs in a subnet.",
1290+
},
1291+
"resource_type": &schema.Schema{
1292+
Type: schema.TypeString,
1293+
Computed: true,
1294+
Description: "The resource type.",
1295+
},
1296+
},
1297+
},
1298+
},
12021299
"virtual_network_interface": &schema.Schema{
12031300
Type: schema.TypeList,
12041301
MaxItems: 1,
@@ -7257,6 +7354,10 @@ func resourceIBMIsInstanceInstanceNetworkAttachmentReferenceToMap(model *vpcv1.I
72577354
vniMap["name"] = pna.VirtualNetworkInterface.Name
72587355
vniMap["resource_type"] = pna.VirtualNetworkInterface.ResourceType
72597356
}
7357+
if model.PrimaryIP != nil {
7358+
primaryipmap, _ := resourceIBMIsInstancePrimaryIPReferenceToMap(model.PrimaryIP)
7359+
modelMap["primary_ip"] = []map[string]interface{}{primaryipmap}
7360+
}
72607361
getVirtualNetworkInterfaceOptions := &vpcv1.GetVirtualNetworkInterfaceOptions{
72617362
ID: pna.VirtualNetworkInterface.ID,
72627363
}
@@ -7333,6 +7434,24 @@ func resourceIBMIsInstanceReservedIPReferenceToMap(model *vpcv1.ReservedIPRefere
73337434
}
73347435
return modelMap, nil
73357436
}
7437+
func resourceIBMIsInstancePrimaryIPReferenceToMap(model *vpcv1.ReservedIPReference) (map[string]interface{}, error) {
7438+
modelMap := make(map[string]interface{})
7439+
modelMap["address"] = model.Address
7440+
if model.Deleted != nil {
7441+
deletedMap, err := resourceIBMIsInstanceReservedIPReferenceDeletedToMap(model.Deleted)
7442+
if err != nil {
7443+
return modelMap, err
7444+
}
7445+
modelMap["deleted"] = []map[string]interface{}{deletedMap}
7446+
}
7447+
modelMap["href"] = model.Href
7448+
modelMap["id"] = model.ID
7449+
modelMap["name"] = model.Name
7450+
if model.ResourceType != nil {
7451+
modelMap["resource_type"] = model.ResourceType
7452+
}
7453+
return modelMap, nil
7454+
}
73367455

73377456
func resourceIBMIsInstanceReservedIPReferenceDeletedToMap(model *vpcv1.Deleted) (map[string]interface{}, error) {
73387457
modelMap := make(map[string]interface{})

ibm/service/vpc/resource_ibm_is_instance_test.go

+91
Original file line numberDiff line numberDiff line change
@@ -3573,3 +3573,94 @@ func testAccCheckIBMISInstanceClusterNetworkAttachmentConfig(vpcname, clustersub
35733573
}
35743574
`, vpcname, acc.ISClusterNetworkProfileName, acc.ISZoneName, clustersubnetname, clustersubnetreservedipname, clusternetworkinterfacename, subnetName, acc.ISZoneName, sshKeyName, publicKey, instanceName, acc.IsImage, acc.ISInstanceGPUProfileName)
35753575
}
3576+
3577+
func TestAccIBMISInstance_primary_ip_consistency(t *testing.T) {
3578+
var instance string
3579+
vpcname := fmt.Sprintf("tf-vpc-%d", acctest.RandIntRange(10, 100))
3580+
name := fmt.Sprintf("tf-instnace-%d", acctest.RandIntRange(10, 100))
3581+
subnetname := fmt.Sprintf("tf-subnet-%d", acctest.RandIntRange(10, 100))
3582+
publicKey := strings.TrimSpace(`
3583+
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCKVmnMOlHKcZK8tpt3MP1lqOLAcqcJzhsvJcjscgVERRN7/9484SOBJ3HSKxxNG5JN8owAjy5f9yYwcUg+JaUVuytn5Pv3aeYROHGGg+5G346xaq3DAwX6Y5ykr2fvjObgncQBnuU5KHWCECO/4h8uWuwh/kfniXPVjFToc+gnkqA+3RKpAecZhFXwfalQ9mMuYGFxn+fwn8cYEApsJbsEmb0iJwPiZ5hjFC8wREuiTlhPHDgkBLOiycd20op2nXzDbHfCHInquEe/gYxEitALONxm0swBOwJZwlTDOB7C6y2dzlrtxr1L59m7pCkWI4EtTRLvleehBoj3u7jB4usR
3584+
`)
3585+
sshname := fmt.Sprintf("tf-ssh-%d", acctest.RandIntRange(10, 100))
3586+
userData1 := "a"
3587+
3588+
resource.Test(t, resource.TestCase{
3589+
PreCheck: func() { acc.TestAccPreCheck(t) },
3590+
Providers: acc.TestAccProviders,
3591+
CheckDestroy: testAccCheckIBMISInstanceDestroy,
3592+
Steps: []resource.TestStep{
3593+
{
3594+
Config: testAccCheckIBMISInstancePrimaryIpConsistencyConfig(vpcname, subnetname, sshname, publicKey, name, userData1),
3595+
Check: resource.ComposeTestCheckFunc(
3596+
testAccCheckIBMISInstanceExists("ibm_is_instance.testacc_instance", instance),
3597+
resource.TestCheckResourceAttr(
3598+
"ibm_is_instance.testacc_instance", "name", name),
3599+
resource.TestCheckResourceAttr(
3600+
"ibm_is_instance.testacc_instance", "user_data", userData1),
3601+
resource.TestCheckResourceAttr(
3602+
"ibm_is_instance.testacc_instance", "zone", acc.ISZoneName),
3603+
resource.TestCheckResourceAttrSet(
3604+
"ibm_is_instance.testacc_instance", "vcpu.#"),
3605+
resource.TestCheckResourceAttrSet(
3606+
"ibm_is_instance.testacc_instance", "vcpu.0.manufacturer"),
3607+
resource.TestCheckResourceAttrSet(
3608+
"ibm_is_instance.testacc_instance", "primary_network_attachment.#"),
3609+
resource.TestCheckResourceAttrSet(
3610+
"ibm_is_instance.testacc_instance", "primary_network_attachment.0.primary_ip.#"),
3611+
resource.TestCheckResourceAttrSet(
3612+
"ibm_is_instance.testacc_instance", "primary_network_attachment.0.primary_ip.0.address"),
3613+
resource.TestCheckResourceAttrSet(
3614+
"ibm_is_instance.testacc_instance", "network_attachments.#"),
3615+
resource.TestCheckResourceAttrSet(
3616+
"ibm_is_instance.testacc_instance", "network_attachments.0.primary_ip.#"),
3617+
resource.TestCheckResourceAttrSet(
3618+
"ibm_is_instance.testacc_instance", "network_attachments.0.primary_ip.0.address"),
3619+
),
3620+
},
3621+
},
3622+
})
3623+
}
3624+
3625+
func testAccCheckIBMISInstancePrimaryIpConsistencyConfig(vpcname, subnetname, sshname, publicKey, name, userData string) string {
3626+
return fmt.Sprintf(`
3627+
resource "ibm_is_vpc" "testacc_vpc" {
3628+
name = "%s"
3629+
}
3630+
3631+
resource "ibm_is_subnet" "testacc_subnet" {
3632+
name = "%s"
3633+
vpc = ibm_is_vpc.testacc_vpc.id
3634+
zone = "%s"
3635+
ipv4_cidr_block = "%s"
3636+
}
3637+
3638+
resource "ibm_is_ssh_key" "testacc_sshkey" {
3639+
name = "%s"
3640+
public_key = "%s"
3641+
}
3642+
3643+
resource "ibm_is_instance" "testacc_instance" {
3644+
name = "%s"
3645+
image = "%s"
3646+
profile = "%s"
3647+
primary_network_attachment {
3648+
name = "example-primarynetwork-att"
3649+
virtual_network_interface {
3650+
auto_delete = true
3651+
subnet = ibm_is_subnet.testacc_subnet.id
3652+
}
3653+
}
3654+
user_data = "%s"
3655+
vpc = ibm_is_vpc.testacc_vpc.id
3656+
zone = "%s"
3657+
keys = [ibm_is_ssh_key.testacc_sshkey.id]
3658+
network_attachments {
3659+
name = "example-network-att"
3660+
virtual_network_interface {
3661+
auto_delete = true
3662+
subnet = ibm_is_subnet.testacc_subnet.id
3663+
}
3664+
}
3665+
}`, vpcname, subnetname, acc.ISZoneName, acc.ISCIDR, sshname, publicKey, name, acc.IsImage, acc.InstanceProfileName, userData, acc.ISZoneName)
3666+
}

website/docs/r/is_instance.html.markdown

+20
Original file line numberDiff line numberDiff line change
@@ -945,6 +945,16 @@ In addition to all argument reference list, you can access the following attribu
945945
- `id` - (String) The ID of the instance.
946946
- `memory`- (Integer) The amount of memory that is allocated to the instance in gigabytes.
947947
- `numa_count` - (Integer) The number of NUMA nodes this instance is provisioned on. This property may be absent if the instance's status is not running.
948+
- `network_attachments` - (List) The network attachments list for this virtual server instance.
949+
Nested schema for **network_attachments**:
950+
951+
- `primary_ip` - (List) The primary IP address to bind to the network interface. This can be specified using an existing reserved IP, or a prototype object for a new reserved IP.
952+
953+
Nested scheme for `primary_ip`:
954+
- `auto_delete` - (Bool) Indicates whether this reserved IP member will be automatically deleted when either target is deleted, or the reserved IP is unbound.
955+
- `address` - (String) The IP address of the reserved IP.
956+
- `name`- (String) The user-defined or system-provided name for this reserved IP
957+
- `id`- (String) The unique identifier for this reserved IP.
948958
- `network_interfaces`- (List of Strings) A list of more network interfaces that are attached to the instance.
949959

950960
Nested scheme for `network_interfaces`:
@@ -961,6 +971,16 @@ In addition to all argument reference list, you can access the following attribu
961971
- `name`- (String) The user-defined or system-provided name for this reserved IP
962972
- `reserved_ip`- (String) The unique identifier for this reserved IP
963973
- `primary_ipv4_address` - (String, Deprecated) The primary IPv4 address. Same as `primary_ip.[0].address`
974+
- `primary_network_attachment` - (List) The primary network attachment for this virtual server instance.
975+
Nested schema for **primary_network_attachment**:
976+
977+
- `primary_ip` - (List) The primary IP address to bind to the network interface. This can be specified using an existing reserved IP, or a prototype object for a new reserved IP.
978+
979+
Nested scheme for `primary_ip`:
980+
- `auto_delete` - (Bool) Indicates whether this reserved IP member will be automatically deleted when either target is deleted, or the reserved IP is unbound.
981+
- `address` - (String) The IP address of the reserved IP.
982+
- `name`- (String) The user-defined or system-provided name for this reserved IP
983+
- `id`- (String) The unique identifier for this reserved IP.
964984
- `primary_network_interface`- (List of Strings) A list of primary network interfaces that are attached to the instance.
965985

966986
Nested scheme for `primary_network_interface`:

0 commit comments

Comments
 (0)