mirror of
https://github.com/opentofu/opentofu.git
synced 2025-01-16 03:32:54 -06:00
815c8840a7
We have a curtesy function in place allowing you to specify both a `name` of `ID`. But in order for the graph to be build correctly when you recreate or taint stuff that other resources depend on, we need to reference the `ID` and *not* the `name`. So in order to enforce this and by that help people to not make this mistake unknowingly, I deprecated all the parameters this allies to and changed the logic, docs and tests accordingly.
112 lines
2.6 KiB
Go
112 lines
2.6 KiB
Go
package cloudstack
|
|
|
|
import (
|
|
"fmt"
|
|
"testing"
|
|
|
|
"github.com/hashicorp/terraform/helper/resource"
|
|
"github.com/hashicorp/terraform/terraform"
|
|
"github.com/xanzy/go-cloudstack/cloudstack"
|
|
)
|
|
|
|
func TestAccCloudStackNetworkACL_basic(t *testing.T) {
|
|
var acl cloudstack.NetworkACLList
|
|
resource.Test(t, resource.TestCase{
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
Providers: testAccProviders,
|
|
CheckDestroy: testAccCheckCloudStackNetworkACLDestroy,
|
|
Steps: []resource.TestStep{
|
|
resource.TestStep{
|
|
Config: testAccCloudStackNetworkACL_basic,
|
|
Check: resource.ComposeTestCheckFunc(
|
|
testAccCheckCloudStackNetworkACLExists(
|
|
"cloudstack_network_acl.foo", &acl),
|
|
testAccCheckCloudStackNetworkACLBasicAttributes(&acl),
|
|
),
|
|
},
|
|
},
|
|
})
|
|
}
|
|
|
|
func testAccCheckCloudStackNetworkACLExists(
|
|
n string, acl *cloudstack.NetworkACLList) resource.TestCheckFunc {
|
|
return func(s *terraform.State) error {
|
|
rs, ok := s.RootModule().Resources[n]
|
|
if !ok {
|
|
return fmt.Errorf("Not found: %s", n)
|
|
}
|
|
|
|
if rs.Primary.ID == "" {
|
|
return fmt.Errorf("No network ACL ID is set")
|
|
}
|
|
|
|
cs := testAccProvider.Meta().(*cloudstack.CloudStackClient)
|
|
acllist, _, err := cs.NetworkACL.GetNetworkACLListByID(rs.Primary.ID)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
if acllist.Id != rs.Primary.ID {
|
|
return fmt.Errorf("Network ACL not found")
|
|
}
|
|
|
|
*acl = *acllist
|
|
|
|
return nil
|
|
}
|
|
}
|
|
|
|
func testAccCheckCloudStackNetworkACLBasicAttributes(
|
|
acl *cloudstack.NetworkACLList) resource.TestCheckFunc {
|
|
return func(s *terraform.State) error {
|
|
|
|
if acl.Name != "terraform-acl" {
|
|
return fmt.Errorf("Bad name: %s", acl.Name)
|
|
}
|
|
|
|
if acl.Description != "terraform-acl-text" {
|
|
return fmt.Errorf("Bad description: %s", acl.Description)
|
|
}
|
|
|
|
return nil
|
|
}
|
|
}
|
|
|
|
func testAccCheckCloudStackNetworkACLDestroy(s *terraform.State) error {
|
|
cs := testAccProvider.Meta().(*cloudstack.CloudStackClient)
|
|
|
|
for _, rs := range s.RootModule().Resources {
|
|
if rs.Type != "cloudstack_network_acl" {
|
|
continue
|
|
}
|
|
|
|
if rs.Primary.ID == "" {
|
|
return fmt.Errorf("No network ACL ID is set")
|
|
}
|
|
|
|
_, _, err := cs.NetworkACL.GetNetworkACLListByID(rs.Primary.ID)
|
|
if err == nil {
|
|
return fmt.Errorf("Network ACl list %s still exists", rs.Primary.ID)
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
var testAccCloudStackNetworkACL_basic = fmt.Sprintf(`
|
|
resource "cloudstack_vpc" "foobar" {
|
|
name = "terraform-vpc"
|
|
cidr = "%s"
|
|
vpc_offering = "%s"
|
|
zone = "%s"
|
|
}
|
|
|
|
resource "cloudstack_network_acl" "foo" {
|
|
name = "terraform-acl"
|
|
description = "terraform-acl-text"
|
|
vpc_id = "${cloudstack_vpc.foobar.id}"
|
|
}`,
|
|
CLOUDSTACK_VPC_CIDR_1,
|
|
CLOUDSTACK_VPC_OFFERING,
|
|
CLOUDSTACK_ZONE)
|