Skip to content

Commit

Permalink
Update integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
outscale-toa committed Feb 1, 2024
1 parent 9974614 commit a68bf8c
Show file tree
Hide file tree
Showing 88 changed files with 2,197 additions and 972 deletions.
61 changes: 40 additions & 21 deletions outscale/data_source_outscale_nic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,33 +131,42 @@ func testAccCheckOutscaleOAPINICDestroy(s *terraform.State) error {

func testAccOutscaleOAPIENIDataSourceConfig(subregion string) string {
return fmt.Sprintf(`
resource "outscale_net" "outscale_net" {
ip_range = "10.0.0.0/16"
tags {
key = "Name"
value = "testacc-nic-ds"
}
resource "outscale_net" "outscale_net" {
ip_range = "10.0.0.0/16"
tags {
key = "Name"
value = "testacc-nic-ds"
}
}
resource "outscale_subnet" "outscale_subnet" {
subregion_name = "%sa"
ip_range = "10.0.0.0/24"
net_id = outscale_net.outscale_net.id
resource "outscale_subnet" "outscale_subnet" {
subregion_name = "%sa"
ip_range = "10.0.0.0/24"
net_id = outscale_net.outscale_net.id
}
resource "outscale_security_group" "sgdatNic" {
security_group_name = "test_sgNic"
description = "Used in the terraform acceptance tests"
tags {
key = "Name"
value = "tf-acc-test"
}
net_id = outscale_net.outscale_net.net_id
}
resource "outscale_nic" "outscale_nic" {
subnet_id = outscale_subnet.outscale_subnet.id
tags {
value = "tf-value"
key = "tf-key"
}
resource "outscale_nic" "outscale_nic" {
subnet_id = outscale_subnet.outscale_subnet.id
security_group_ids = [outscale_security_group.sgdatNic.security_group_id]
tags {
value = "tf-value"
key = "tf-key"
}
}
data "outscale_nic" "outscale_nic" {
nic_id = outscale_nic.outscale_nic.id
}
`, subregion)
data "outscale_nic" "outscale_nic" {
nic_id = outscale_nic.outscale_nic.id
}
`, subregion)
}

func testAccOutscaleOAPIENIDataSourceConfigFilter(subregion string) string {
Expand All @@ -176,9 +185,19 @@ func testAccOutscaleOAPIENIDataSourceConfigFilter(subregion string) string {
ip_range = "10.0.0.0/24"
net_id = outscale_net.outscale_net.id
}
resource "outscale_security_group" "sgdatNic" {
security_group_name = "test_sgNic"
description = "Used in the terraform acceptance tests"
tags {
key = "Name"
value = "tf-acc-test"
}
net_id = outscale_net.outscale_net.net_id
}
resource "outscale_nic" "outscale_nic" {
subnet_id = outscale_subnet.outscale_subnet.id
security_group_ids = [outscale_security_group.sgdatNic.security_group_id]
tags {
value = "tf-value"
key = "tf-key"
Expand Down
10 changes: 9 additions & 1 deletion outscale/data_source_outscale_nics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,17 @@ func testAccCheckOutscaleOAPINicsDataSourceConfig(subregion string) string {
ip_range = "10.0.0.0/24"
net_id = outscale_net.outscale_net.net_id
}
resource "outscale_security_group" "sg_dataNic" {
description = "sg for terraform tests"
security_group_name = "terraform-sg"
net_id = outscale_net.outscale_net.net_id
}
resource "outscale_nic" "outscale_nic" {
subnet_id = outscale_subnet.outscale_subnet.subnet_id
security_group_ids = [outscale_security_group.sg_dataNic.security_group_id]
}
data "outscale_nics" "outscale_nics" {
Expand Down
8 changes: 8 additions & 0 deletions outscale/data_source_outscale_subnet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,14 @@ func testAccDataSourceOutscaleOAPISubnetWithAvailableIpsCountsFilter(region stri
name = "available_ips_counts"
values = [outscale_subnet.outscale_subnet.available_ips_count]
}
filter {
name = "ip_ranges"
values = ["10.0.0.0/24"]
}
filter {
name = "net_ids"
values = [outscale_net.outscale_net.net_id]
}
}
`, region)
}
7 changes: 7 additions & 0 deletions outscale/data_source_outscale_vm_states_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,17 @@ func TestAccVM_StatesDataSource(t *testing.T) {

func testAccDataSourceOutscaleOAPIVMStatesConfig(omi, vmType string) string {
return fmt.Sprintf(`
resource "outscale_security_group" "sg_vStates" {
description = "testAcc Terraform security group"
security_group_name = "sg_volumes_link"
}
resource "outscale_vm" "basic" {
image_id = "%s"
vm_type = "%s"
keypair_name = "terraform-basic"
security_group_ids = [outscale_security_group.sg_vStates.security_group_id]
}
data "outscale_vm_states" "state" {
Expand Down
53 changes: 26 additions & 27 deletions outscale/resource_outscale_image_launch_permission_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,29 +33,29 @@ func TestAccVM_WithImageLaunchPermission_Basic(t *testing.T) {
Steps: []r.TestStep{
// Scaffold everything
{
Config: testAccOutscaleOAPIImageLaunchPermissionConfig(omi, "tinav4.c2r2p2", region, accountID, true, rInt, keypair),
Config: testAccOutscaleOAPIImageLaunchPermissionConfig(omi, "tinav4.c2r2p2", region, accountID, keypair, true, rInt),
Check: r.ComposeTestCheckFunc(
testCheckResourceOAPILPIGetAttr("outscale_image.outscale_image", "id", &imageID),
),
},
// Drop just launch permission to test destruction
{
Config: testAccOutscaleOAPIImageLaunchPermissionConfig(omi, "tinav4.c2r2p2", region, accountID, false, rInt, keypair),
Config: testAccOutscaleOAPIImageLaunchPermissionConfig(omi, "tinav4.c2r2p2", region, accountID, keypair, false, rInt),
Check: r.ComposeTestCheckFunc(
testAccOutscaleOAPIImageLaunchPermissionDestroyed(accountID, &imageID),
),
},
// Re-add everything so we can test when AMI disappears
{
Config: testAccOutscaleOAPIImageLaunchPermissionConfig(omi, "tinav4.c2r2p2", region, accountID, true, rInt, keypair),
Config: testAccOutscaleOAPIImageLaunchPermissionConfig(omi, "tinav4.c2r2p2", region, accountID, keypair, true, rInt),
Check: r.ComposeTestCheckFunc(
testCheckResourceOAPILPIGetAttr("outscale_image.outscale_image", "id", &imageID),
),
},
// Here we delete the AMI to verify the follow-on refresh after this step
// should not error.
{
Config: testAccOutscaleOAPIImageLaunchPermissionConfig(omi, "tinav4.c2r2p2", region, accountID, true, rInt, keypair),
Config: testAccOutscaleOAPIImageLaunchPermissionConfig(omi, "tinav4.c2r2p2", region, accountID, keypair, true, rInt),
Check: r.ComposeTestCheckFunc(
testAccOutscaleOAPIImageDisappears(&imageID),
),
Expand All @@ -80,14 +80,14 @@ func TestAccVM_ImageLaunchPermissionDestruction_Basic(t *testing.T) {
Steps: []r.TestStep{
// Scaffold everything
{
Config: testAccOutscaleOAPIImageLaunchPermissionCreateConfig(omi, "tinav4.c2r2p2", region, rInt, true, false, keypair),
Config: testAccOutscaleOAPIImageLaunchPermissionCreateConfig(omi, "tinav4.c2r2p2", region, keypair, rInt, true, false),
Check: r.ComposeTestCheckFunc(
testCheckResourceOAPILPIGetAttr("outscale_image.outscale_image", "id", &imageID),
testAccOutscaleOAPIImageLaunchPermissionExists(accountID, &imageID),
),
},
{
Config: testAccOutscaleOAPIImageLaunchPermissionCreateConfig(omi, "tinav4.c2r2p2", region, rInt, true, true, keypair),
Config: testAccOutscaleOAPIImageLaunchPermissionCreateConfig(omi, "tinav4.c2r2p2", region, keypair, rInt, true, true),
Check: r.ComposeTestCheckFunc(
testCheckResourceOAPILPIGetAttr("outscale_image.outscale_image", "id", &imageID),
),
Expand Down Expand Up @@ -182,10 +182,10 @@ func testCheckResourceGetAttr(name, key string, value *string) r.TestCheckFunc {
}
}

func testAccOutscaleOAPIImageLaunchPermissionConfig(omi, vmType, region, accountID string, includeLaunchPermission bool, r int, keypair string) string {
func testAccOutscaleOAPIImageLaunchPermissionConfig(omi, vmType, region, accountID, keypair string, includeLaunchPermission bool, r int) string {
base := fmt.Sprintf(`
resource "outscale_security_group" "sg_perm" {
security_group_name = "%[5]s"
security_group_name = "sgLPerm"
description = "Used in the terraform acceptance tests"
tags {
Expand Down Expand Up @@ -223,18 +223,17 @@ func testAccOutscaleOAPIImageLaunchPermissionConfig(omi, vmType, region, account
`, accountID)
}

func testAccOutscaleOAPIImageLaunchPermissionCreateConfig(omi, vmType, region string, r int, includeAddtion, includeRemoval bool, keypair string) string {
func testAccOutscaleOAPIImageLaunchPermissionCreateConfig(omi, vmType, region, keypair string, r int, includeAddtion, includeRemoval bool) string {
base := fmt.Sprintf(`
resource "outscale_security_group" "sg_prem" {
security_group_name = "%[5]s"
resource "outscale_security_group" "sg_perm" {
security_group_name = "sgLPerm"
description = "Used in the terraform acceptance tests"
tags {
key = "Name"
value = "tf-acc-test"
}
}
resource "outscale_vm" "outscale_instance" {
image_id = "%[1]s"
vm_type = "%[2]s"
Expand All @@ -252,26 +251,26 @@ func testAccOutscaleOAPIImageLaunchPermissionCreateConfig(omi, vmType, region st

if includeAddtion {
return base + `
resource "outscale_image_launch_permission" "outscale_image_launch_permission" {
image_id = outscale_image.outscale_image.image_id
permission_additions {
account_ids = ["520679080430"]
resource "outscale_image_launch_permission" "outscale_image_launch_permission" {
image_id = outscale_image.outscale_image.image_id
permission_additions {
account_ids = ["520679080430"]
}
}
}
`
`
}

if includeRemoval {
return base + `
resource "outscale_image_launch_permission" "outscale_image_launch_permission_two" {
image_id = outscale_image_launch_permission.outscale_image_launch_permission.image_id
permission_removals {
account_ids = ["520679080430"]
}
}
`
resource "outscale_image_launch_permission" "outscale_image_launch_permission_two" {
image_id = outscale_image_launch_permission.outscale_image_launch_permission.image_id
permission_removals {
account_ids = ["520679080430"]
}
}
`
}
return base
}
17 changes: 12 additions & 5 deletions outscale/resource_outscale_nic_private_ip_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,22 @@ func testAccOutscaleOAPINetworkInterfacePrivateIPConfigBasic(region string) stri
resource "outscale_subnet" "outscale_subnet" {
subregion_name = "%sa"
ip_range = "10.0.0.0/16"
net_id = "${outscale_net.outscale_net.net_id}"
net_id = outscale_net.outscale_net.net_id
}
resource "outscale_security_group" "sg_PrNic" {
description = "sg for terraform tests"
security_group_name = "terraform-sg"
net_id = outscale_net.outscale_net.net_id
}
resource "outscale_nic" "outscale_nic" {
subnet_id = "${outscale_subnet.outscale_subnet.subnet_id}"
subnet_id = outscale_subnet.outscale_subnet.subnet_id
security_group_ids = [outscale_security_group.sg_PrNic.security_group_id]
}
resource "outscale_nic_private_ip" "outscale_nic_private_ip" {
nic_id = "${outscale_nic.outscale_nic.nic_id}"
nic_id = outscale_nic.outscale_nic.nic_id
private_ips = ["10.0.45.67"]
}
`, region)
Expand Down
Loading

0 comments on commit a68bf8c

Please sign in to comment.