Skip to content

Commit

Permalink
Update test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
SaiDadireddy committed Sep 24, 2024
1 parent c57f88f commit 69b2cce
Showing 1 changed file with 25 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,34 +22,34 @@ func TestAccCloudflareInfraAccessTarget_DataSource(t *testing.T) {
Config: testCloudflareInfrastructureTargetsMatchNoIpv6(rnd1),
Check: resource.ComposeTestCheckFunc(
// We should expect this data source to have 1 resource
resource.TestCheckResourceAttr("data.cloudflare_zero_trust_infrastructure_targets."+rnd1, "resources.#", "1"),
resource.TestCheckResourceAttr("data.cloudflare_infrastructure_access_targets."+rnd1, "resources.#", "1"),
// Check that there is no ipv6 object in this resource
resource.TestCheckNoResourceAttr("data.cloudflare_zero_trust_infrastructure_targets."+rnd1, "ip.ipv6"),
resource.TestCheckNoResourceAttr("data.cloudflare_infrastructure_access_targets."+rnd1, "ip.ipv6"),
// Check the existing attributes of this resource
resource.TestCheckTypeSetElemNestedAttrs("data.cloudflare_zero_trust_infrastructure_targets."+rnd1, "resources.*", map[string]string{
resource.TestCheckTypeSetElemNestedAttrs("cloudflare_infrastructure_access_targets."+rnd1, "resources.*", map[string]string{
"hostname": rnd1,
"ip.ipv4.ip_addr": "187.26.29.249",
"ip.ipv4.virtual_network_id": "c77b744e-acc8-428f-9257-6878c046ed55",
"ip.ipv4.virtual_network_id": "b9c90134-52de-4903-81e8-004a3a06b435",
}),
),
},
{
Config: testCloudflareInfrastructureTargetsMatchAll(rnd1, rnd2),
Check: resource.ComposeTestCheckFunc(
// Expect this data source to have 2 resources
resource.TestCheckResourceAttr("data.cloudflare_zero_trust_infrastructure_targets.all", "resources.#", "2"),
resource.TestCheckResourceAttr("data.cloudflare_infrastructure_access_targets.all", "resources.#", "2"),
// Check the attributes of the first resource
resource.TestCheckTypeSetElemNestedAttrs("data.cloudflare_zero_trust_infrastructure_targets.all", "resources.*", map[string]string{
resource.TestCheckTypeSetElemNestedAttrs("data.cloudflare_infrastructure_access_targets.all", "resources.*", map[string]string{
"hostname": rnd1,
"ip.ipv4.ip_addr": "187.26.29.249",
"ip.ipv4.virtual_network_id": "c77b744e-acc8-428f-9257-6878c046ed55",
"ip.ipv4.ip_addr": "187.26.29.233",
"ip.ipv4.virtual_network_id": "b9c90134-52de-4903-81e8-004a3a06b435",
}),
// Check the attributes of the second resource
resource.TestCheckTypeSetElemNestedAttrs("data.cloudflare_zero_trust_infrastructure_targets.all", "resources.*", map[string]string{
resource.TestCheckTypeSetElemNestedAttrs("data.cloudflare_infrastructure_access_targets.all", "resources.*", map[string]string{
"hostname": rnd2,
"ip.ipv4.ip_addr": "250.26.29.250",
"ip.ipv6.ip_addr": "64c0:64e8:f0b4:8dbf:7104:72b0:ec8f:f5e0",
"ip.ipv6.virtual_network_id": "01920a8c-dc14-7bb2-b67b-14c858494a54",
"ip.ipv6.virtual_network_id": "b9c90134-52de-4903-81e8-004a3a06b435",
}),
),
},
Expand All @@ -60,57 +60,59 @@ func TestAccCloudflareInfraAccessTarget_DataSource(t *testing.T) {
func testCloudflareInfrastructureTargetsMatchNoIpv6(hostname string) string {
accountID := os.Getenv("CLOUDFLARE_ACCOUNT_ID")
return fmt.Sprintf(`
resource "cloudflare_zero_trust_infrastructure_target" "%[2]s" {
resource "cloudflare_infrastructure_access_target" "%[2]s" {
account_id = "%[1]s"
hostname = "%[2]s"
ip = {
ipv4 = {
ip_addr = "187.26.29.249",
virtual_network_id = "c77b744e-acc8-428f-9257-6878c046ed55"
ip_addr = "187.26.29.233",
virtual_network_id = "b9c90134-52de-4903-81e8-004a3a06b435"
}
}
}
data "cloudflare_zero_trust_infrastructure_targets" "%[2]s" {
depends_on = [cloudflare_zero_trust_infrastructure_target.%[2]s]
data "cloudflare_infrastructure_access_targets" "%[2]s" {
depends_on = [cloudflare_infrastructure_access_target.%[2]s]
account_id = "%[1]s"
}
`, accountID, hostname)
}

func testCloudflareInfrastructureTargetsMatchAll(hostname1 string, hostname2 string) string {
accountID := os.Getenv("CLOUDFLARE_ACCOUNT_ID")
return fmt.Sprintf(`
resource "cloudflare_zero_trust_infrastructure_target" "%[2]s" {
resource "cloudflare_infrastructure_access_target" "%[2]s" {
account_id = "%[1]s"
hostname = "%[2]s"
ip = {
ipv4 = {
ip_addr = "187.26.29.249",
virtual_network_id = "c77b744e-acc8-428f-9257-6878c046ed55"
virtual_network_id = "b9c90134-52de-4903-81e8-004a3a06b435"
}
}
}
resource "cloudflare_zero_trust_infrastructure_target" "%[3]s" {
resource "cloudflare_infrastructure_access_target" "%[3]s" {
account_id = "%[1]s"
hostname = "%[3]s"
ip = {
ipv4 = {
ip_addr = "250.26.29.250",
virtual_network_id = "01920a8c-dc14-7bb2-b67b-14c858494a54"
virtual_network_id = "b9c90134-52de-4903-81e8-004a3a06b435"
},
ipv6 = {
ip_addr = "64c0:64e8:f0b4:8dbf:7104:72b0:ec8f:f5e0",
virtual_network_id = "01920a8c-dc14-7bb2-b67b-14c858494a54"
virtual_network_id = "b9c90134-52de-4903-81e8-004a3a06b435"
}
}
}
data "cloudflare_zero_trust_infrastructure_targets" "all" {
data "cloudflare_infrastructure_access_targets" "all" {
depends_on = [
cloudflare_zero_trust_infrastructure_target.%[2]s,
cloudflare_zero_trust_infrastructure_target.%[3]s
cloudflare_infrastructure_access_target.%[2]s,
cloudflare_infrastructure_access_target.%[3]s
]
account_id = "%[1]s"
}
`, accountID, hostname1, hostname2)
}

0 comments on commit 69b2cce

Please sign in to comment.