@@ -15,48 +15,42 @@ import (
15
15
func TestAccCSMThreatsPoliciesList_CreateAndUpdate (t * testing.T ) {
16
16
_ , providers , accProviders := testAccFrameworkMuxProviders (context .Background (), t )
17
17
18
- resourceName := "datadog_csm_threats_policies_list.all "
18
+ resourceName := "datadog_csm_threats_policies.all_policies "
19
19
20
20
resource .Test (t , resource.TestCase {
21
21
PreCheck : func () { testAccPreCheck (t ) },
22
22
ProtoV5ProviderFactories : accProviders ,
23
- CheckDestroy : testAccCheckCSMThreatsPoliciesListDestroy (providers .frameworkProvider ),
23
+ CheckDestroy : testAccCheckCSMThreatsPoliciesDestroy (providers .frameworkProvider ),
24
24
Steps : []resource.TestStep {
25
25
{
26
- Config : testAccCSMThreatsPoliciesListConfigBasic (),
26
+ Config : testAccCSMThreatsPoliciesConfig (),
27
27
Check : resource .ComposeTestCheckFunc (
28
- testAccCheckCSMThreatsPoliciesListExists (providers .frameworkProvider , resourceName ),
29
- resource .TestCheckResourceAttr (resourceName , "entries.#" , "2" ),
30
- resource .TestCheckResourceAttr (resourceName , "entries.0.name" , "TERRAFORM_POLICY1" ),
31
- resource .TestCheckResourceAttr (resourceName , "entries.0.priority" , "2" ),
32
- resource .TestCheckResourceAttr (resourceName , "entries.1.name" , "TERRAFORM_POLICY2" ),
33
- resource .TestCheckResourceAttr (resourceName , "entries.1.priority" , "3" ),
28
+ testAccCheckCSMThreatsPoliciesExists (providers .frameworkProvider , resourceName ),
29
+ resource .TestCheckResourceAttr (resourceName , "policies.0.name" , "terraform_policy" ),
30
+ resource .TestCheckResourceAttr (resourceName , "policies.0.enabled" , "false" ),
34
31
),
35
32
},
36
33
{
37
- Config : testAccCSMThreatsPoliciesListConfigUpdate (),
34
+ Config : testAccCSMThreatsPoliciesConfigUpdate (),
38
35
Check : resource .ComposeTestCheckFunc (
39
- testAccCheckCSMThreatsPoliciesListExists (providers .frameworkProvider , resourceName ),
40
- resource .TestCheckResourceAttr (resourceName , "entries.#" , "2" ),
41
- resource .TestCheckResourceAttr (resourceName , "entries.0.name" , "TERRAFORM_POLICY1" ),
42
- resource .TestCheckResourceAttr (resourceName , "entries.0.priority" , "2" ),
43
- resource .TestCheckResourceAttr (resourceName , "entries.1.name" , "TERRAFORM_POLICY2 UPDATED" ),
44
- resource .TestCheckResourceAttr (resourceName , "entries.1.priority" , "5" ),
36
+ testAccCheckCSMThreatsPoliciesExists (providers .frameworkProvider , resourceName ),
37
+ resource .TestCheckResourceAttr (resourceName , "policies.0.name" , "terraform_policy updated" ),
38
+ resource .TestCheckResourceAttr (resourceName , "policies.0.enabled" , "true" ),
45
39
),
46
40
},
47
41
},
48
42
})
49
43
}
50
44
51
- func testAccCheckCSMThreatsPoliciesListExists (accProvider * fwprovider.FrameworkProvider , resourceName string ) resource.TestCheckFunc {
45
+ func testAccCheckCSMThreatsPoliciesExists (accProvider * fwprovider.FrameworkProvider , resourceName string ) resource.TestCheckFunc {
52
46
return func (s * terraform.State ) error {
53
47
rs , ok := s .RootModule ().Resources [resourceName ]
54
48
if ! ok {
55
49
return fmt .Errorf ("resource '%s' not found in state" , resourceName )
56
50
}
57
- if rs .Type != "datadog_csm_threats_policies_list " {
51
+ if rs .Type != "datadog_csm_threats_policies " {
58
52
return fmt .Errorf (
59
- "resource %s is not a datadog_csm_threats_policies_list , got: %s" ,
53
+ "resource %s is not a datadog_csm_threats_policies , got: %s" ,
60
54
resourceName ,
61
55
rs .Type ,
62
56
)
@@ -70,85 +64,44 @@ func testAccCheckCSMThreatsPoliciesListExists(accProvider *fwprovider.FrameworkP
70
64
}
71
65
}
72
66
73
- func testAccCheckCSMThreatsPoliciesListDestroy (accProvider * fwprovider.FrameworkProvider ) resource.TestCheckFunc {
67
+ func testAccCheckCSMThreatsPoliciesDestroy (accProvider * fwprovider.FrameworkProvider ) resource.TestCheckFunc {
74
68
return func (s * terraform.State ) error {
75
- apiInstances := accProvider .DatadogApiInstances
76
- auth := accProvider .Auth
77
-
78
69
for _ , r := range s .RootModule ().Resources {
79
- if r .Type != "datadog_csm_threats_policies_list " {
70
+ if r .Type != "datadog_csm_threats_policies " {
80
71
continue
81
72
}
82
73
83
- resp , httpResponse , err := apiInstances .GetCSMThreatsApiV2 ().ListCSMThreatsAgentPolicies (auth )
84
- if err != nil {
85
- if httpResponse != nil && httpResponse .StatusCode == 404 {
86
- return nil
87
- }
88
- return fmt .Errorf ("Received an error while listing the policies: %s" , err )
89
- }
90
-
91
- if len (resp .GetData ()) > 1 { // CWS_DD is always present
92
- return fmt .Errorf ("Policies list not empty, some policies are still present" )
74
+ if _ , ok := s .RootModule ().Resources [r .Primary .ID ]; ok {
75
+ return fmt .Errorf ("Resource %s still exists in state" , r .Primary .ID )
93
76
}
94
77
}
95
78
return nil
96
79
}
97
80
}
98
81
99
- func testAccCSMThreatsPoliciesListConfigBasic () string {
82
+ func testAccCSMThreatsPoliciesConfig () string {
100
83
return `
101
- resource "datadog_csm_threats_policy" "policy1" {
102
- description = "created with terraform"
103
- enabled = false
104
- tags = []
105
- }
106
-
107
- resource "datadog_csm_threats_policy" "policy2" {
108
- description = "created with terraform 2"
109
- enabled = true
110
- tags = ["env:staging"]
111
- }
112
-
113
- resource "datadog_csm_threats_policies_list" "all" {
114
- entries {
115
- policy_id = datadog_csm_threats_policy.policy1.id
116
- name = "TERRAFORM_POLICY1"
117
- priority = 2
118
- }
119
- entries {
120
- policy_id = datadog_csm_threats_policy.policy2.id
121
- name = "TERRAFORM_POLICY2"
122
- priority = 3
84
+ resource "datadog_csm_threats_policies" "all_policies" {
85
+ policies {
86
+ policy_label = "policy1"
87
+ name = "terraform_policy"
88
+ description = "description"
89
+ enabled = false
90
+ tags = ["env:staging"]
123
91
}
124
92
}
125
93
`
126
94
}
127
95
128
- func testAccCSMThreatsPoliciesListConfigUpdate () string {
96
+ func testAccCSMThreatsPoliciesConfigUpdate () string {
129
97
return `
130
- resource "datadog_csm_threats_policy" "policy1" {
131
- description = "created with terraform"
132
- enabled = false
133
- tags = []
134
- }
135
-
136
- resource "datadog_csm_threats_policy" "policy2" {
137
- description = "created with terraform 2"
138
- enabled = true
139
- tags = ["env:staging"]
140
- }
141
-
142
- resource "datadog_csm_threats_policies_list" "all" {
143
- entries {
144
- policy_id = datadog_csm_threats_policy.policy1.id
145
- name = "TERRAFORM_POLICY1"
146
- priority = 2
147
- }
148
- entries {
149
- policy_id = datadog_csm_threats_policy.policy2.id
150
- name = "TERRAFORM_POLICY2 UPDATED"
151
- priority = 5
98
+ resource "datadog_csm_threats_policies" "all_policies" {
99
+ policies {
100
+ policy_label = "policy"
101
+ name = "terraform_policy updated"
102
+ description = "new description"
103
+ enabled = true
104
+ tags = ["foo:bar"]
152
105
}
153
106
}
154
107
`
0 commit comments