-
Notifications
You must be signed in to change notification settings - Fork 9.2k
/
data_source_aws_vpc_dhcp_options_test.go
149 lines (132 loc) · 5.95 KB
/
data_source_aws_vpc_dhcp_options_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
package aws
import (
"fmt"
"regexp"
"testing"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
)
func TestAccDataSourceAwsVpcDhcpOptions_basic(t *testing.T) {
resourceName := "aws_vpc_dhcp_options.test"
datasourceName := "data.aws_vpc_dhcp_options.test"
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccDataSourceAwsVpcDhcpOptionsConfig_Missing,
ExpectError: regexp.MustCompile(`No matching EC2 DHCP Options found`),
},
{
Config: testAccDataSourceAwsVpcDhcpOptionsConfig_DhcpOptionsID,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrPair(datasourceName, "dhcp_options_id", resourceName, "id"),
resource.TestCheckResourceAttrPair(datasourceName, "domain_name", resourceName, "domain_name"),
resource.TestCheckResourceAttrPair(datasourceName, "domain_name_servers.#", resourceName, "domain_name_servers.#"),
resource.TestCheckResourceAttrPair(datasourceName, "domain_name_servers.0", resourceName, "domain_name_servers.0"),
resource.TestCheckResourceAttrPair(datasourceName, "domain_name_servers.1", resourceName, "domain_name_servers.1"),
resource.TestCheckResourceAttrPair(datasourceName, "netbios_name_servers.#", resourceName, "netbios_name_servers.#"),
resource.TestCheckResourceAttrPair(datasourceName, "netbios_name_servers.0", resourceName, "netbios_name_servers.0"),
resource.TestCheckResourceAttrPair(datasourceName, "netbios_node_type", resourceName, "netbios_node_type"),
resource.TestCheckResourceAttrPair(datasourceName, "ntp_servers.#", resourceName, "ntp_servers.#"),
resource.TestCheckResourceAttrPair(datasourceName, "ntp_servers.0", resourceName, "ntp_servers.0"),
resource.TestCheckResourceAttrPair(datasourceName, "tags.%", resourceName, "tags.%"),
resource.TestCheckResourceAttrPair(datasourceName, "tags.Name", resourceName, "tags.Name"),
resource.TestCheckResourceAttrPair(datasourceName, "owner_id", resourceName, "owner_id"),
resource.TestCheckResourceAttrPair(datasourceName, "arn", resourceName, "arn"),
),
},
},
})
}
func TestAccDataSourceAwsVpcDhcpOptions_Filter(t *testing.T) {
rInt := acctest.RandInt()
resourceName := "aws_vpc_dhcp_options.test"
datasourceName := "data.aws_vpc_dhcp_options.test"
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccDataSourceAwsVpcDhcpOptionsConfig_Filter(rInt, 1),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrPair(datasourceName, "dhcp_options_id", resourceName, "id"),
resource.TestCheckResourceAttrPair(datasourceName, "domain_name", resourceName, "domain_name"),
resource.TestCheckResourceAttrPair(datasourceName, "domain_name_servers.#", resourceName, "domain_name_servers.#"),
resource.TestCheckResourceAttrPair(datasourceName, "domain_name_servers.0", resourceName, "domain_name_servers.0"),
resource.TestCheckResourceAttrPair(datasourceName, "domain_name_servers.1", resourceName, "domain_name_servers.1"),
resource.TestCheckResourceAttrPair(datasourceName, "netbios_name_servers.#", resourceName, "netbios_name_servers.#"),
resource.TestCheckResourceAttrPair(datasourceName, "netbios_name_servers.0", resourceName, "netbios_name_servers.0"),
resource.TestCheckResourceAttrPair(datasourceName, "netbios_node_type", resourceName, "netbios_node_type"),
resource.TestCheckResourceAttrPair(datasourceName, "ntp_servers.#", resourceName, "ntp_servers.#"),
resource.TestCheckResourceAttrPair(datasourceName, "ntp_servers.0", resourceName, "ntp_servers.0"),
resource.TestCheckResourceAttrPair(datasourceName, "tags.%", resourceName, "tags.%"),
resource.TestCheckResourceAttrPair(datasourceName, "tags.Name", resourceName, "tags.Name"),
resource.TestCheckResourceAttrPair(datasourceName, "owner_id", resourceName, "owner_id"),
),
},
{
Config: testAccDataSourceAwsVpcDhcpOptionsConfig_Filter(rInt, 2),
ExpectError: regexp.MustCompile(`Multiple matching EC2 DHCP Options found`),
},
{
// We have one last empty step here because otherwise we'll leave the
// test case with resources in the state and an erroneous config, and
// thus the automatic destroy step will fail. This ensures we end with
// both an empty state and a valid config.
Config: `/* this config intentionally left blank */`,
},
},
})
}
const testAccDataSourceAwsVpcDhcpOptionsConfig_Missing = `
data "aws_vpc_dhcp_options" "test" {
dhcp_options_id = "does-not-exist"
}
`
const testAccDataSourceAwsVpcDhcpOptionsConfig_DhcpOptionsID = `
resource "aws_vpc_dhcp_options" "incorrect" {
domain_name = "tf-acc-test-incorrect.example.com"
}
resource "aws_vpc_dhcp_options" "test" {
domain_name = "service.consul"
domain_name_servers = ["127.0.0.1", "10.0.0.2"]
netbios_name_servers = ["127.0.0.1"]
netbios_node_type = 2
ntp_servers = ["127.0.0.1"]
tags = {
Name = "tf-acc-test"
}
}
data "aws_vpc_dhcp_options" "test" {
dhcp_options_id = aws_vpc_dhcp_options.test.id
}
`
func testAccDataSourceAwsVpcDhcpOptionsConfig_Filter(rInt, count int) string {
return fmt.Sprintf(`
resource "aws_vpc_dhcp_options" "incorrect" {
domain_name = "tf-acc-test-incorrect.example.com"
}
resource "aws_vpc_dhcp_options" "test" {
count = %d
domain_name = "tf-acc-test-%d.example.com"
domain_name_servers = ["127.0.0.1", "10.0.0.2"]
netbios_name_servers = ["127.0.0.1"]
netbios_node_type = 2
ntp_servers = ["127.0.0.1"]
tags = {
Name = "tf-acc-test-%d"
}
}
data "aws_vpc_dhcp_options" "test" {
filter {
name = "key"
values = ["domain-name"]
}
filter {
name = "value"
values = [aws_vpc_dhcp_options.test.0.domain_name]
}
}
`, count, rInt, rInt)
}