@@ -206,6 +206,85 @@ func TestAccTencentCloudGaapHttpRule_domainRealserver(t *testing.T) {
206206 })
207207}
208208
209+ func TestAccTencentCloudGaapHttpRule_noRealserver (t * testing.T ) {
210+ id := new (string )
211+
212+ resource .Test (t , resource.TestCase {
213+ PreCheck : func () { testAccPreCheck (t ) },
214+ Providers : testAccProviders ,
215+ CheckDestroy : testAccCheckGaapHttpRuleDestroy (id ),
216+ Steps : []resource.TestStep {
217+ {
218+ Config : testAccGaapHttpRuleNoRealserver ,
219+ Check : resource .ComposeTestCheckFunc (
220+ testAccCheckGaapHttpRuleExists ("tencentcloud_gaap_http_rule.foo" , id ),
221+ resource .TestCheckResourceAttr ("tencentcloud_gaap_http_rule.foo" , "domain" , "www.qq.com" ),
222+ resource .TestCheckResourceAttr ("tencentcloud_gaap_http_rule.foo" , "path" , "/" ),
223+ resource .TestCheckResourceAttr ("tencentcloud_gaap_http_rule.foo" , "scheduler" , "rr" ),
224+ resource .TestCheckResourceAttr ("tencentcloud_gaap_http_rule.foo" , "realserver_type" , "IP" ),
225+ resource .TestCheckResourceAttr ("tencentcloud_gaap_http_rule.foo" , "health_check" , "true" ),
226+ resource .TestCheckResourceAttr ("tencentcloud_gaap_http_rule.foo" , "interval" , "5" ),
227+ resource .TestCheckResourceAttr ("tencentcloud_gaap_http_rule.foo" , "connect_timeout" , "2" ),
228+ resource .TestCheckResourceAttr ("tencentcloud_gaap_http_rule.foo" , "health_check_path" , "/" ),
229+ resource .TestCheckResourceAttr ("tencentcloud_gaap_http_rule.foo" , "health_check_method" , "GET" ),
230+ resource .TestCheckResourceAttr ("tencentcloud_gaap_http_rule.foo" , "health_check_status_codes.#" , "1" ),
231+ resource .TestCheckResourceAttr ("tencentcloud_gaap_http_rule.foo" , "health_check_status_codes." + strconv .Itoa (schema .HashInt (200 )), "200" ),
232+ resource .TestCheckResourceAttr ("tencentcloud_gaap_http_rule.foo" , "realservers.#" , "0" ),
233+ resource .TestCheckResourceAttr ("tencentcloud_gaap_http_rule.foo" , "forward_host" , "default" ),
234+ ),
235+ },
236+ {
237+ ResourceName : "tencentcloud_gaap_http_rule.foo" ,
238+ ImportState : true ,
239+ ImportStateVerify : true ,
240+ },
241+ },
242+ })
243+ }
244+
245+ func TestAccTencentCloudGaapHttpRule_deleteRealserver (t * testing.T ) {
246+ id := new (string )
247+
248+ resource .Test (t , resource.TestCase {
249+ PreCheck : func () { testAccPreCheck (t ) },
250+ Providers : testAccProviders ,
251+ CheckDestroy : testAccCheckGaapHttpRuleDestroy (id ),
252+ Steps : []resource.TestStep {
253+ {
254+ Config : testAccGaapHttpRuleBasic ,
255+ Check : resource .ComposeTestCheckFunc (
256+ testAccCheckGaapHttpRuleExists ("tencentcloud_gaap_http_rule.foo" , id ),
257+ resource .TestCheckResourceAttr ("tencentcloud_gaap_http_rule.foo" , "domain" , "www.qq.com" ),
258+ resource .TestCheckResourceAttr ("tencentcloud_gaap_http_rule.foo" , "path" , "/" ),
259+ resource .TestCheckResourceAttr ("tencentcloud_gaap_http_rule.foo" , "scheduler" , "rr" ),
260+ resource .TestCheckResourceAttr ("tencentcloud_gaap_http_rule.foo" , "realserver_type" , "IP" ),
261+ resource .TestCheckResourceAttr ("tencentcloud_gaap_http_rule.foo" , "health_check" , "true" ),
262+ resource .TestCheckResourceAttr ("tencentcloud_gaap_http_rule.foo" , "interval" , "5" ),
263+ resource .TestCheckResourceAttr ("tencentcloud_gaap_http_rule.foo" , "connect_timeout" , "2" ),
264+ resource .TestCheckResourceAttr ("tencentcloud_gaap_http_rule.foo" , "health_check_path" , "/" ),
265+ resource .TestCheckResourceAttr ("tencentcloud_gaap_http_rule.foo" , "health_check_method" , "GET" ),
266+ resource .TestCheckResourceAttr ("tencentcloud_gaap_http_rule.foo" , "health_check_status_codes.#" , "1" ),
267+ resource .TestCheckResourceAttr ("tencentcloud_gaap_http_rule.foo" , "health_check_status_codes." + strconv .Itoa (schema .HashInt (200 )), "200" ),
268+ resource .TestCheckResourceAttr ("tencentcloud_gaap_http_rule.foo" , "realservers.#" , "2" ),
269+ resource .TestCheckResourceAttr ("tencentcloud_gaap_http_rule.foo" , "forward_host" , "default" ),
270+ ),
271+ },
272+ {
273+ Config : testAccGaapHttpRuleNoRealserver ,
274+ Check : resource .ComposeTestCheckFunc (
275+ testAccCheckGaapHttpRuleExists ("tencentcloud_gaap_http_rule.foo" , id ),
276+ resource .TestCheckResourceAttr ("tencentcloud_gaap_http_rule.foo" , "realservers.#" , "0" ),
277+ ),
278+ },
279+ {
280+ ResourceName : "tencentcloud_gaap_http_rule.foo" ,
281+ ImportState : true ,
282+ ImportStateVerify : true ,
283+ },
284+ },
285+ })
286+ }
287+
209288func testAccCheckGaapHttpRuleExists (n string , id * string ) resource.TestCheckFunc {
210289 return func (s * terraform.State ) error {
211290 rs , ok := s .RootModule ().Resources [n ]
@@ -578,3 +657,28 @@ resource tencentcloud_gaap_http_rule "foo" {
578657 }
579658}
580659` , defaultGaapProxyId )
660+
661+ var testAccGaapHttpRuleNoRealserver = fmt .Sprintf (`
662+ resource tencentcloud_gaap_layer7_listener "foo" {
663+ protocol = "HTTP"
664+ name = "ci-test-gaap-l7-listener"
665+ port = 80
666+ proxy_id = "%s"
667+ }
668+
669+ resource tencentcloud_gaap_http_domain "foo" {
670+ listener_id = tencentcloud_gaap_layer7_listener.foo.id
671+ domain = "www.qq.com"
672+ }
673+
674+ resource tencentcloud_gaap_http_rule "foo" {
675+ listener_id = tencentcloud_gaap_layer7_listener.foo.id
676+ domain = tencentcloud_gaap_http_domain.foo.domain
677+ path = "/"
678+ realserver_type = "IP"
679+ health_check = true
680+ health_check_path = "/"
681+ health_check_method = "GET"
682+ health_check_status_codes = [200]
683+ }
684+ ` , defaultGaapProxyId )
0 commit comments