Skip to content

Commit b1ca939

Browse files
committed
feat(specs): Create spec, tests and examples for panos_iptag_log_settings
1 parent 6b3338c commit b1ca939

File tree

4 files changed

+658
-0
lines changed

4 files changed

+658
-0
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# An iptag 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-iptag-settings"
11+
# }
12+
terraform import panos_iptag_log_settings.example $(echo '{"location":{"template":{"name":"example-template","panorama_device":"localhost.localdomain"}},"name":"example-iptag-settings"}' | base64)
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
resource "panos_template" "example" {
2+
location = { panorama = {} }
3+
name = "example-template"
4+
}
5+
6+
resource "panos_iptag_log_settings" "example" {
7+
location = {
8+
template = {
9+
name = panos_template.example.name
10+
}
11+
}
12+
13+
name = "example-iptag-settings"
14+
description = "iptag log settings example"
15+
filter = "(severity eq high)"
16+
send_to_panorama = true
17+
18+
actions = [
19+
{
20+
name = "tag-action"
21+
type = {
22+
tagging = {
23+
action = "add-tag"
24+
target = "source-address"
25+
tags = ["tag1", "tag2"]
26+
registration = {
27+
localhost = {}
28+
}
29+
}
30+
}
31+
}
32+
]
33+
}
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
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 TestAccIptagLogSettings(t *testing.T) {
16+
t.Parallel()
17+
18+
nameSuffix := acctest.RandStringFromCharSet(6, acctest.CharSetAlphaNum)
19+
prefix := fmt.Sprintf("test-acc-%s", nameSuffix)
20+
21+
filter1 := "(tag_name neq '')"
22+
filter2 := "(datasourcename eq test)"
23+
24+
resource.Test(t, resource.TestCase{
25+
PreCheck: func() { testAccPreCheck(t) },
26+
ProtoV6ProviderFactories: testAccProviders,
27+
Steps: []resource.TestStep{
28+
{
29+
Config: iptagLogSettingsTmpl,
30+
ConfigVariables: map[string]config.Variable{
31+
"prefix": config.StringVariable(prefix),
32+
"description": config.StringVariable("test description"),
33+
"filter": config.StringVariable(filter1),
34+
"send_to_panorama": config.BoolVariable(true),
35+
},
36+
ConfigStateChecks: []statecheck.StateCheck{
37+
statecheck.ExpectKnownValue(
38+
"panos_iptag_log_settings.settings",
39+
tfjsonpath.New("description"),
40+
knownvalue.StringExact("test description"),
41+
),
42+
statecheck.ExpectKnownValue(
43+
"panos_iptag_log_settings.settings",
44+
tfjsonpath.New("filter"),
45+
knownvalue.StringExact(filter1),
46+
),
47+
statecheck.ExpectKnownValue(
48+
"panos_iptag_log_settings.settings",
49+
tfjsonpath.New("send_to_panorama"),
50+
knownvalue.Bool(true),
51+
),
52+
},
53+
},
54+
{
55+
Config: iptagLogSettingsTmpl,
56+
ConfigVariables: map[string]config.Variable{
57+
"prefix": config.StringVariable(prefix),
58+
"description": config.StringVariable("updated description"),
59+
"filter": config.StringVariable(filter2),
60+
"send_to_panorama": config.BoolVariable(false),
61+
"actions": config.ListVariable(config.ObjectVariable(map[string]config.Variable{
62+
"name": config.StringVariable("tag-action"),
63+
"type": config.ObjectVariable(map[string]config.Variable{
64+
"tagging": config.ObjectVariable(map[string]config.Variable{
65+
"action": config.StringVariable("add-tag"),
66+
"target": config.StringVariable("source-address"),
67+
"tags": config.ListVariable(config.StringVariable("tag1"), config.StringVariable("tag2")),
68+
}),
69+
}),
70+
})),
71+
},
72+
ConfigStateChecks: []statecheck.StateCheck{
73+
statecheck.ExpectKnownValue(
74+
"panos_iptag_log_settings.settings",
75+
tfjsonpath.New("description"),
76+
knownvalue.StringExact("updated description"),
77+
),
78+
statecheck.ExpectKnownValue(
79+
"panos_iptag_log_settings.settings",
80+
tfjsonpath.New("filter"),
81+
knownvalue.StringExact(filter2),
82+
),
83+
statecheck.ExpectKnownValue(
84+
"panos_iptag_log_settings.settings",
85+
tfjsonpath.New("send_to_panorama"),
86+
knownvalue.Bool(false),
87+
),
88+
statecheck.ExpectKnownValue(
89+
"panos_iptag_log_settings.settings",
90+
tfjsonpath.New("actions").AtSliceIndex(0).AtMapKey("name"),
91+
knownvalue.StringExact("tag-action"),
92+
),
93+
},
94+
},
95+
},
96+
})
97+
}
98+
99+
const iptagLogSettingsTmpl = `
100+
variable "prefix" { type = string }
101+
variable "description" { type = string }
102+
variable "filter" { type = string }
103+
variable "send_to_panorama" { type = bool }
104+
variable "actions" {
105+
type = any
106+
default = []
107+
}
108+
109+
110+
resource "panos_template" "tmpl" {
111+
location = { panorama = {} }
112+
name = var.prefix
113+
}
114+
115+
resource "panos_iptag_log_settings" "settings" {
116+
location = { template = { name = panos_template.tmpl.name } }
117+
name = var.prefix
118+
description = var.description
119+
filter = var.filter
120+
send_to_panorama = var.send_to_panorama
121+
actions = var.actions
122+
}
123+
`

0 commit comments

Comments
 (0)