@@ -2,29 +2,51 @@ package iotda
2
2
3
3
import (
4
4
"fmt"
5
+ "strings"
5
6
"testing"
6
7
7
8
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
8
9
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
9
10
10
- "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/iotda/v5/model"
11
+ "github.com/chnsz/golangsdk"
12
+
11
13
"github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/config"
12
14
"github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/services/acceptance"
15
+ "github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/utils"
13
16
)
14
17
15
18
func getDataForwardingRuleResourceFunc (conf * config.Config , state * terraform.ResourceState ) (interface {}, error ) {
16
- client , err := conf .HcIoTdaV5Client (acceptance .HW_REGION_NAME , WithDerivedAuth ())
19
+ var (
20
+ region = acceptance .HW_REGION_NAME
21
+ product = "iotda"
22
+ httpUrl = "v5/iot/{project_id}/routing-rule/rules/{rule_id}"
23
+ )
24
+
25
+ isDerived := WithDerivedAuth ()
26
+ client , err := conf .NewServiceClientWithDerivedAuth (product , region , isDerived )
27
+ if err != nil {
28
+ return nil , fmt .Errorf ("error creating IoTDA client: %s" , err )
29
+ }
30
+
31
+ requestPath := client .Endpoint + httpUrl
32
+ requestPath = strings .ReplaceAll (requestPath , "{project_id}" , client .ProjectID )
33
+ requestPath = strings .ReplaceAll (requestPath , "{rule_id}" , state .Primary .ID )
34
+ requestOpt := golangsdk.RequestOpts {
35
+ KeepResponseBody : true ,
36
+ }
37
+
38
+ resp , err := client .Request ("GET" , requestPath , & requestOpt )
17
39
if err != nil {
18
- return nil , fmt . Errorf ( "error creating IoTDA v5 client: %s" , err )
40
+ return nil , err
19
41
}
20
42
21
- return client . ShowRoutingRule ( & model. ShowRoutingRuleRequest { RuleId : state . Primary . ID } )
43
+ return utils . FlattenResponse ( resp )
22
44
}
23
45
24
46
// The forwarding target of **DMS_KAFKA_FORWARDING** type requires the use of a public IP address, which may pose a
25
47
// security port risk, so it will not be tested temporarily.
26
48
func TestAccDataForwardingRule_basic (t * testing.T ) {
27
- var obj model. ShowRoutingRuleResponse
49
+ var obj interface {}
28
50
29
51
name := acceptance .RandomAccResourceNameWithDash ()
30
52
rName := "huaweicloud_iotda_dataforwarding_rule.test"
@@ -178,6 +200,15 @@ func TestAccDataForwardingRule_basic(t *testing.T) {
178
200
"huaweicloud_iotda_amqp.test.1" , "name" ),
179
201
),
180
202
},
203
+ {
204
+ Config : testDataForwardingRule_multipleTargets (name ),
205
+ Check : resource .ComposeTestCheckFunc (
206
+ resource .TestCheckResourceAttr (rName , "name" , name ),
207
+ resource .TestCheckResourceAttr (rName , "trigger" , "product:delete" ),
208
+ resource .TestCheckResourceAttr (rName , "enabled" , "true" ),
209
+ resource .TestCheckResourceAttr (rName , "targets.#" , "2" ),
210
+ ),
211
+ },
181
212
{
182
213
ResourceName : rName ,
183
214
ImportState : true ,
@@ -479,3 +510,37 @@ resource "huaweicloud_iotda_dataforwarding_rule" "test" {
479
510
}
480
511
` , buildIoTDAEndpoint (), name )
481
512
}
513
+
514
+ func testDataForwardingRule_multipleTargets (name string ) string {
515
+ return fmt .Sprintf (`
516
+ %[1]s
517
+
518
+ resource "huaweicloud_iotda_amqp" "test" {
519
+ count = 2
520
+
521
+ name = format("%[2]s_%%d", count.index)
522
+ }
523
+
524
+ resource "huaweicloud_iotda_dataforwarding_rule" "test" {
525
+ name = "%[2]s"
526
+ trigger = "product:delete"
527
+ enabled = true
528
+
529
+ targets {
530
+ type = "AMQP_FORWARDING"
531
+
532
+ amqp_forwarding {
533
+ queue_name = huaweicloud_iotda_amqp.test[1].name
534
+ }
535
+ }
536
+
537
+ targets {
538
+ type = "HTTP_FORWARDING"
539
+
540
+ http_forwarding {
541
+ url = "http://www.exampletest.com"
542
+ }
543
+ }
544
+ }
545
+ ` , buildIoTDAEndpoint (), name )
546
+ }
0 commit comments