Skip to content

Commit

Permalink
Added test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
uibm committed Dec 5, 2024
1 parent e965978 commit 1fa2045
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 2 deletions.
4 changes: 2 additions & 2 deletions ibm/acctest/acctest.go
Original file line number Diff line number Diff line change
Expand Up @@ -841,8 +841,8 @@ func init() {
IsImage = os.Getenv("IS_IMAGE")
if IsImage == "" {
// IsImage = "fc538f61-7dd6-4408-978c-c6b85b69fe76" // for classic infrastructure
IsImage = "r006-907911a7-0ffe-467e-8821-3cc9a0d82a39" // for next gen infrastructure ibm-centos-7-9-minimal-amd64-10 image
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'")
IsImage = "r006-587a041d-9246-44f0-980b-56a327cf5bd7" // for next gen infrastructure ibm-ubuntu-24-04-6-minimal-amd64-1 us-south
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'")
}

IsImage2 = os.Getenv("IS_IMAGE2")
Expand Down
91 changes: 91 additions & 0 deletions ibm/service/vpc/resource_ibm_is_instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3565,3 +3565,94 @@ func testAccCheckIBMISInstanceClusterNetworkAttachmentConfig(vpcname, clustersub
}
`, vpcname, acc.ISClusterNetworkProfileName, acc.ISZoneName, clustersubnetname, clustersubnetreservedipname, clusternetworkinterfacename, subnetName, acc.ISZoneName, sshKeyName, publicKey, instanceName, acc.IsImage, acc.ISInstanceGPUProfileName)
}

func TestAccIBMISInstance_primary_ip_consistency(t *testing.T) {
var instance string
vpcname := fmt.Sprintf("tf-vpc-%d", acctest.RandIntRange(10, 100))
name := fmt.Sprintf("tf-instnace-%d", acctest.RandIntRange(10, 100))
subnetname := fmt.Sprintf("tf-subnet-%d", acctest.RandIntRange(10, 100))
publicKey := strings.TrimSpace(`
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCKVmnMOlHKcZK8tpt3MP1lqOLAcqcJzhsvJcjscgVERRN7/9484SOBJ3HSKxxNG5JN8owAjy5f9yYwcUg+JaUVuytn5Pv3aeYROHGGg+5G346xaq3DAwX6Y5ykr2fvjObgncQBnuU5KHWCECO/4h8uWuwh/kfniXPVjFToc+gnkqA+3RKpAecZhFXwfalQ9mMuYGFxn+fwn8cYEApsJbsEmb0iJwPiZ5hjFC8wREuiTlhPHDgkBLOiycd20op2nXzDbHfCHInquEe/gYxEitALONxm0swBOwJZwlTDOB7C6y2dzlrtxr1L59m7pCkWI4EtTRLvleehBoj3u7jB4usR
`)
sshname := fmt.Sprintf("tf-ssh-%d", acctest.RandIntRange(10, 100))
userData1 := "a"

resource.Test(t, resource.TestCase{
PreCheck: func() { acc.TestAccPreCheck(t) },
Providers: acc.TestAccProviders,
CheckDestroy: testAccCheckIBMISInstanceDestroy,
Steps: []resource.TestStep{
{
Config: testAccCheckIBMISInstancePrimaryIpConsistencyConfig(vpcname, subnetname, sshname, publicKey, name, userData1),
Check: resource.ComposeTestCheckFunc(
testAccCheckIBMISInstanceExists("ibm_is_instance.testacc_instance", instance),
resource.TestCheckResourceAttr(
"ibm_is_instance.testacc_instance", "name", name),
resource.TestCheckResourceAttr(
"ibm_is_instance.testacc_instance", "user_data", userData1),
resource.TestCheckResourceAttr(
"ibm_is_instance.testacc_instance", "zone", acc.ISZoneName),
resource.TestCheckResourceAttrSet(
"ibm_is_instance.testacc_instance", "vcpu.#"),
resource.TestCheckResourceAttrSet(
"ibm_is_instance.testacc_instance", "vcpu.0.manufacturer"),
resource.TestCheckResourceAttrSet(
"ibm_is_instance.testacc_instance", "primary_network_attachment.#"),
resource.TestCheckResourceAttrSet(
"ibm_is_instance.testacc_instance", "primary_network_attachment.0.primary_ip.#"),
resource.TestCheckResourceAttrSet(
"ibm_is_instance.testacc_instance", "primary_network_attachment.0.primary_ip.0.address"),
resource.TestCheckResourceAttrSet(
"ibm_is_instance.testacc_instance", "network_attachments.#"),
resource.TestCheckResourceAttrSet(
"ibm_is_instance.testacc_instance", "network_attachments.0.primary_ip.#"),
resource.TestCheckResourceAttrSet(
"ibm_is_instance.testacc_instance", "network_attachments.0.primary_ip.0.address"),
),
},
},
})
}

func testAccCheckIBMISInstancePrimaryIpConsistencyConfig(vpcname, subnetname, sshname, publicKey, name, userData string) string {
return fmt.Sprintf(`
resource "ibm_is_vpc" "testacc_vpc" {
name = "%s"
}
resource "ibm_is_subnet" "testacc_subnet" {
name = "%s"
vpc = ibm_is_vpc.testacc_vpc.id
zone = "%s"
ipv4_cidr_block = "%s"
}
resource "ibm_is_ssh_key" "testacc_sshkey" {
name = "%s"
public_key = "%s"
}
resource "ibm_is_instance" "testacc_instance" {
name = "%s"
image = "%s"
profile = "%s"
primary_network_attachment {
name = "example-primarynetwork-att"
virtual_network_interface {
auto_delete = true
subnet = ibm_is_subnet.testacc_subnet.id
}
}
user_data = "%s"
vpc = ibm_is_vpc.testacc_vpc.id
zone = "%s"
keys = [ibm_is_ssh_key.testacc_sshkey.id]
network_attachments {
name = "example-network-att"
virtual_network_interface {
auto_delete = true
subnet = ibm_is_subnet.testacc_subnet.id
}
}
}`, vpcname, subnetname, acc.ISZoneName, acc.ISCIDR, sshname, publicKey, name, acc.IsImage, acc.InstanceProfileName, userData, acc.ISZoneName)
}

0 comments on commit 1fa2045

Please sign in to comment.