Skip to content

Commit aeb55d6

Browse files
committed
feat(specs): Create spec, tests and examples for panos_syslog_profile
1 parent 66c028d commit aeb55d6

File tree

4 files changed

+795
-0
lines changed

4 files changed

+795
-0
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# A syslog profile 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-syslog-profile"
11+
# }
12+
terraform import panos_syslog_profile.example $(echo '{"location":{"template":{"name":"example-template","panorama_device":"localhost.localdomain"}},"name":"example-syslog-profile"}' | base64)
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
resource "panos_template" "example" {
2+
location = { panorama = {} }
3+
name = "example-template"
4+
}
5+
6+
resource "panos_syslog_profile" "example" {
7+
location = {
8+
template = {
9+
name = panos_template.example.name
10+
}
11+
}
12+
13+
name = "example-syslog-profile"
14+
15+
servers = [
16+
{
17+
name = "server1"
18+
server = "10.0.0.1"
19+
transport = "UDP"
20+
port = 514
21+
facility = "LOG_USER"
22+
format = "IETF"
23+
},
24+
{
25+
name = "server2"
26+
server = "syslog.example.com"
27+
transport = "SSL"
28+
port = 6514
29+
facility = "LOG_LOCAL1"
30+
format = "BSD"
31+
}
32+
]
33+
34+
format = {
35+
auth = "auth-format"
36+
traffic = "traffic-format"
37+
escaping = {
38+
escape_character = "\\"
39+
escaped_characters = "'"
40+
}
41+
}
42+
}
Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
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 TestAccSyslogProfile(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: syslogProfileTmpl,
27+
ConfigVariables: map[string]config.Variable{
28+
"prefix": config.StringVariable(prefix),
29+
"servers": config.ListVariable(
30+
config.ObjectVariable(map[string]config.Variable{
31+
"name": config.StringVariable("server1"),
32+
"server": config.StringVariable("10.0.0.1"),
33+
"transport": config.StringVariable("UDP"),
34+
"port": config.IntegerVariable(514),
35+
"facility": config.StringVariable("LOG_USER"),
36+
"format": config.StringVariable("IETF"),
37+
}),
38+
),
39+
"format": config.ObjectVariable(map[string]config.Variable{
40+
"traffic": config.StringVariable("traffic-fmt"),
41+
}),
42+
},
43+
ConfigStateChecks: []statecheck.StateCheck{
44+
statecheck.ExpectKnownValue(
45+
"panos_syslog_profile.profile",
46+
tfjsonpath.New("name"),
47+
knownvalue.StringExact(prefix),
48+
),
49+
statecheck.ExpectKnownValue(
50+
"panos_syslog_profile.profile",
51+
tfjsonpath.New("servers").AtSliceIndex(0).AtMapKey("name"),
52+
knownvalue.StringExact("server1"),
53+
),
54+
statecheck.ExpectKnownValue(
55+
"panos_syslog_profile.profile",
56+
tfjsonpath.New("format").AtMapKey("traffic"),
57+
knownvalue.StringExact("traffic-fmt"),
58+
),
59+
},
60+
},
61+
{
62+
Config: syslogProfileTmpl,
63+
ConfigVariables: map[string]config.Variable{
64+
"prefix": config.StringVariable(prefix),
65+
"servers": config.ListVariable(
66+
config.ObjectVariable(map[string]config.Variable{
67+
"name": config.StringVariable("server1-upd"),
68+
"server": config.StringVariable("10.0.0.1"),
69+
"transport": config.StringVariable("TCP"),
70+
"port": config.IntegerVariable(514),
71+
"facility": config.StringVariable("LOG_LOCAL0"),
72+
"format": config.StringVariable("BSD"),
73+
}),
74+
config.ObjectVariable(map[string]config.Variable{
75+
"name": config.StringVariable("server2"),
76+
"server": config.StringVariable("10.0.0.2"),
77+
"transport": config.StringVariable("SSL"),
78+
"port": config.IntegerVariable(6514),
79+
"facility": config.StringVariable("LOG_LOCAL1"),
80+
"format": config.StringVariable("IETF"),
81+
}),
82+
),
83+
"format": config.ObjectVariable(map[string]config.Variable{
84+
"traffic": config.StringVariable("traffic-fmt-upd"),
85+
"system": config.StringVariable("system-fmt"),
86+
"escaping": config.ObjectVariable(map[string]config.Variable{
87+
"escape_character": config.StringVariable("\\"),
88+
"escaped_characters": config.StringVariable(`'"`),
89+
}),
90+
}),
91+
},
92+
ConfigStateChecks: []statecheck.StateCheck{
93+
statecheck.ExpectKnownValue(
94+
"panos_syslog_profile.profile",
95+
tfjsonpath.New("servers").AtSliceIndex(0).AtMapKey("name"),
96+
knownvalue.StringExact("server1-upd"),
97+
),
98+
statecheck.ExpectKnownValue(
99+
"panos_syslog_profile.profile",
100+
tfjsonpath.New("servers").AtSliceIndex(0).AtMapKey("transport"),
101+
knownvalue.StringExact("TCP"),
102+
),
103+
statecheck.ExpectKnownValue(
104+
"panos_syslog_profile.profile",
105+
tfjsonpath.New("servers").AtSliceIndex(1).AtMapKey("name"),
106+
knownvalue.StringExact("server2"),
107+
),
108+
statecheck.ExpectKnownValue(
109+
"panos_syslog_profile.profile",
110+
tfjsonpath.New("format").AtMapKey("traffic"),
111+
knownvalue.StringExact("traffic-fmt-upd"),
112+
),
113+
statecheck.ExpectKnownValue(
114+
"panos_syslog_profile.profile",
115+
tfjsonpath.New("format").AtMapKey("system"),
116+
knownvalue.StringExact("system-fmt"),
117+
),
118+
statecheck.ExpectKnownValue(
119+
"panos_syslog_profile.profile",
120+
tfjsonpath.New("format").AtMapKey("escaping").AtMapKey("escape_character"),
121+
knownvalue.StringExact("\\"),
122+
),
123+
},
124+
},
125+
},
126+
})
127+
}
128+
129+
const syslogProfileTmpl = `
130+
variable "prefix" { type = string }
131+
variable "servers" { type = any }
132+
variable "format" { type = any }
133+
134+
resource "panos_template" "tmpl" {
135+
location = { panorama = {} }
136+
137+
name = var.prefix
138+
}
139+
140+
resource "panos_syslog_profile" "profile" {
141+
location = { template = { name = panos_template.tmpl.name } }
142+
143+
name = var.prefix
144+
servers = var.servers
145+
format = var.format
146+
}
147+
`

0 commit comments

Comments
 (0)