Skip to content

Commit 145b064

Browse files
committed
feat(specs): Create spec, tests and examples for panos_userid_log_settings
1 parent 7d192af commit 145b064

File tree

4 files changed

+712
-0
lines changed

4 files changed

+712
-0
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# A userid log setting can be imported by providing the following base64 encoded object as the ID
2+
# {
3+
# location = {
4+
# template = {
5+
# name = "example-template"
6+
# panorama_device = "localhost.localdomain"
7+
# }
8+
# }
9+
#
10+
# name = "example-userid-settings"
11+
# }
12+
terraform import panos_userid_log_settings.example $(echo '{"location":{"template":{"name":"example-template","panorama_device":"localhost.localdomain"}},"name":"example-userid-settings"}' | base64)
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
resource "panos_template" "example" {
2+
location = { panorama = {} }
3+
name = "example-template"
4+
}
5+
6+
resource "panos_userid_log_settings" "example" {
7+
location = {
8+
template = {
9+
name = panos_template.example.name
10+
}
11+
}
12+
13+
name = "example-userid-settings"
14+
description = "userid log settings example"
15+
filter = "(severity eq high)"
16+
send_to_panorama = true
17+
quarantine = false
18+
19+
actions = [
20+
{
21+
name = "tag-action"
22+
type = {
23+
tagging = {
24+
action = "add-tag"
25+
target = "source-address"
26+
tags = ["tag1", "tag2"]
27+
}
28+
}
29+
}
30+
]
31+
}
Lines changed: 179 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,179 @@
1+
package provider_test
2+
3+
import (
4+
"fmt"
5+
"testing"
6+
7+
"github.com/hashicorp/terraform-plugin-testing/config"
8+
"github.com/hashicorp/terraform-plugin-testing/helper/acctest"
9+
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
10+
"github.com/hashicorp/terraform-plugin-testing/knownvalue"
11+
"github.com/hashicorp/terraform-plugin-testing/statecheck"
12+
"github.com/hashicorp/terraform-plugin-testing/tfjsonpath"
13+
)
14+
15+
func TestAccUserIdLogSettings(t *testing.T) {
16+
t.Parallel()
17+
18+
nameSuffix := acctest.RandStringFromCharSet(6, acctest.CharSetAlphaNum)
19+
prefix := fmt.Sprintf("test-acc-%s", nameSuffix)
20+
21+
resource.Test(t, resource.TestCase{
22+
PreCheck: func() { testAccPreCheck(t) },
23+
ProtoV6ProviderFactories: testAccProviders,
24+
Steps: []resource.TestStep{
25+
{
26+
Config: userIdLogSettingsTmpl,
27+
ConfigVariables: map[string]config.Variable{
28+
"prefix": config.StringVariable(prefix),
29+
"description": config.StringVariable("test description"),
30+
"filter": config.StringVariable("(datasourcename eq test)"),
31+
"send_to_panorama": config.BoolVariable(true),
32+
"quarantine": config.BoolVariable(false),
33+
},
34+
ConfigStateChecks: []statecheck.StateCheck{
35+
statecheck.ExpectKnownValue(
36+
"panos_userid_log_settings.settings",
37+
tfjsonpath.New("description"),
38+
knownvalue.StringExact("test description"),
39+
),
40+
statecheck.ExpectKnownValue(
41+
"panos_userid_log_settings.settings",
42+
tfjsonpath.New("filter"),
43+
knownvalue.StringExact("(datasourcename eq test)"),
44+
),
45+
statecheck.ExpectKnownValue(
46+
"panos_userid_log_settings.settings",
47+
tfjsonpath.New("send_to_panorama"),
48+
knownvalue.Bool(true),
49+
),
50+
statecheck.ExpectKnownValue(
51+
"panos_userid_log_settings.settings",
52+
tfjsonpath.New("quarantine"),
53+
knownvalue.Bool(false),
54+
),
55+
},
56+
},
57+
{
58+
Config: userIdLogSettingsTmpl,
59+
ConfigVariables: map[string]config.Variable{
60+
"prefix": config.StringVariable(prefix),
61+
"description": config.StringVariable("updated description"),
62+
"send_to_panorama": config.BoolVariable(false),
63+
"quarantine": config.BoolVariable(true),
64+
"actions": config.ListVariable(config.ObjectVariable(map[string]config.Variable{
65+
"name": config.StringVariable("tag-action"),
66+
"type": config.ObjectVariable(map[string]config.Variable{
67+
"tagging": config.ObjectVariable(map[string]config.Variable{
68+
"action": config.StringVariable("add-tag"),
69+
"target": config.StringVariable("source-address"),
70+
"tags": config.ListVariable(config.StringVariable("tag1"), config.StringVariable("tag2")),
71+
}),
72+
}),
73+
})),
74+
},
75+
ConfigStateChecks: []statecheck.StateCheck{
76+
statecheck.ExpectKnownValue(
77+
"panos_userid_log_settings.settings",
78+
tfjsonpath.New("description"),
79+
knownvalue.StringExact("updated description"),
80+
),
81+
statecheck.ExpectKnownValue(
82+
"panos_userid_log_settings.settings",
83+
tfjsonpath.New("filter"),
84+
knownvalue.Null(),
85+
),
86+
statecheck.ExpectKnownValue(
87+
"panos_userid_log_settings.settings",
88+
tfjsonpath.New("send_to_panorama"),
89+
knownvalue.Bool(false),
90+
),
91+
statecheck.ExpectKnownValue(
92+
"panos_userid_log_settings.settings",
93+
tfjsonpath.New("quarantine"),
94+
knownvalue.Bool(true),
95+
),
96+
statecheck.ExpectKnownValue(
97+
"panos_userid_log_settings.settings",
98+
tfjsonpath.New("actions").AtSliceIndex(0).AtMapKey("name"),
99+
knownvalue.StringExact("tag-action"),
100+
),
101+
statecheck.ExpectKnownValue(
102+
"panos_userid_log_settings.settings",
103+
tfjsonpath.New("actions").AtSliceIndex(0).AtMapKey("type").AtMapKey("tagging").AtMapKey("action"),
104+
knownvalue.StringExact("add-tag"),
105+
),
106+
statecheck.ExpectKnownValue(
107+
"panos_userid_log_settings.settings",
108+
tfjsonpath.New("actions").AtSliceIndex(0).AtMapKey("type").AtMapKey("tagging").AtMapKey("target"),
109+
knownvalue.StringExact("source-address"),
110+
),
111+
statecheck.ExpectKnownValue(
112+
"panos_userid_log_settings.settings",
113+
tfjsonpath.New("actions").AtSliceIndex(0).AtMapKey("type").AtMapKey("tagging").AtMapKey("tags").AtSliceIndex(0),
114+
knownvalue.StringExact("tag1"),
115+
),
116+
statecheck.ExpectKnownValue(
117+
"panos_userid_log_settings.settings",
118+
tfjsonpath.New("actions").AtSliceIndex(0).AtMapKey("type").AtMapKey("tagging").AtMapKey("tags").AtSliceIndex(1),
119+
knownvalue.StringExact("tag2"),
120+
),
121+
},
122+
},
123+
},
124+
})
125+
}
126+
127+
const userIdLogSettingsTmpl = `
128+
variable "prefix" { type = string }
129+
variable "description" { type = string }
130+
variable "filter" {
131+
type = string
132+
default = null
133+
}
134+
variable "send_to_panorama" { type = bool }
135+
variable "quarantine" { type = bool }
136+
variable "actions" {
137+
type = any
138+
default = []
139+
}
140+
141+
142+
resource "panos_template" "tmpl" {
143+
location = { panorama = {} }
144+
name = var.prefix
145+
}
146+
147+
resource "panos_syslog_profile" "syslog1" {
148+
location = { template = { name = panos_template.tmpl.name } }
149+
150+
name = "${var.prefix}1"
151+
152+
servers = [{
153+
name = "server2"
154+
server = "10.0.0.2"
155+
}]
156+
}
157+
158+
resource "panos_syslog_profile" "syslog2" {
159+
location = { template = { name = panos_template.tmpl.name } }
160+
161+
name = "${var.prefix}2"
162+
163+
servers = [{
164+
name = "server2"
165+
server = "10.0.0.2"
166+
}]
167+
}
168+
169+
resource "panos_userid_log_settings" "settings" {
170+
location = { template = { name = panos_template.tmpl.name } }
171+
name = var.prefix
172+
description = var.description
173+
filter = var.filter
174+
send_to_panorama = var.send_to_panorama
175+
syslog_profiles = [panos_syslog_profile.syslog1.name, panos_syslog_profile.syslog2.name]
176+
quarantine = var.quarantine
177+
actions = var.actions
178+
}
179+
`

0 commit comments

Comments
 (0)