Skip to content

Commit 7d192af

Browse files
committed
Create spec, tests and examples for panos_system_log_settings
1 parent 712b00c commit 7d192af

File tree

3 files changed

+635
-0
lines changed

3 files changed

+635
-0
lines changed
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
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 TestAccConfigLogSettings(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: configLogSettingsTmpl,
27+
ConfigVariables: map[string]config.Variable{
28+
"prefix": config.StringVariable(prefix),
29+
"description": config.StringVariable("test description"),
30+
"filter": config.StringVariable("(dgname eq default)"),
31+
"send_to_panorama": config.BoolVariable(true),
32+
},
33+
ConfigStateChecks: []statecheck.StateCheck{
34+
statecheck.ExpectKnownValue(
35+
"panos_config_log_settings.settings",
36+
tfjsonpath.New("description"),
37+
knownvalue.StringExact("test description"),
38+
),
39+
statecheck.ExpectKnownValue(
40+
"panos_config_log_settings.settings",
41+
tfjsonpath.New("filter"),
42+
knownvalue.StringExact("(dgname eq default)"),
43+
),
44+
statecheck.ExpectKnownValue(
45+
"panos_config_log_settings.settings",
46+
tfjsonpath.New("send_to_panorama"),
47+
knownvalue.Bool(true),
48+
),
49+
},
50+
},
51+
{
52+
Config: configLogSettingsTmpl,
53+
ConfigVariables: map[string]config.Variable{
54+
"prefix": config.StringVariable(prefix),
55+
"description": config.StringVariable("updated description"),
56+
"filter": config.StringVariable("(dgname eq default)"),
57+
"send_to_panorama": config.BoolVariable(false),
58+
},
59+
ConfigStateChecks: []statecheck.StateCheck{
60+
statecheck.ExpectKnownValue(
61+
"panos_config_log_settings.settings",
62+
tfjsonpath.New("description"),
63+
knownvalue.StringExact("updated description"),
64+
),
65+
statecheck.ExpectKnownValue(
66+
"panos_config_log_settings.settings",
67+
tfjsonpath.New("filter"),
68+
knownvalue.StringExact("(dgname eq default)"),
69+
),
70+
statecheck.ExpectKnownValue(
71+
"panos_config_log_settings.settings",
72+
tfjsonpath.New("send_to_panorama"),
73+
knownvalue.Bool(false),
74+
),
75+
statecheck.ExpectKnownValue(
76+
"panos_config_log_settings.settings",
77+
tfjsonpath.New("syslog_profiles").AtSliceIndex(0),
78+
knownvalue.StringExact(fmt.Sprintf("%s1", prefix)),
79+
),
80+
},
81+
},
82+
},
83+
})
84+
}
85+
86+
const configLogSettingsTmpl = `
87+
variable "prefix" { type = string }
88+
variable "description" { type = string }
89+
variable "filter" { type = string }
90+
variable "send_to_panorama" { type = bool }
91+
variable "send_syslog" {
92+
type = list(string)
93+
default = []
94+
}
95+
96+
97+
resource "panos_template" "tmpl" {
98+
location = { panorama = {} }
99+
name = var.prefix
100+
}
101+
102+
resource "panos_syslog_profile" "syslog1" {
103+
location = { template = { name = panos_template.tmpl.name } }
104+
105+
name = "${var.prefix}1"
106+
107+
servers = [{
108+
name = "server2"
109+
server = "10.0.0.2"
110+
}]
111+
}
112+
113+
resource "panos_syslog_profile" "syslog2" {
114+
location = { template = { name = panos_template.tmpl.name } }
115+
116+
name = "${var.prefix}2"
117+
118+
servers = [{
119+
name = "server2"
120+
server = "10.0.0.2"
121+
}]
122+
}
123+
124+
resource "panos_config_log_settings" "settings" {
125+
location = { template = { name = panos_template.tmpl.name } }
126+
name = var.prefix
127+
description = var.description
128+
filter = var.filter
129+
send_to_panorama = var.send_to_panorama
130+
syslog_profiles = [panos_syslog_profile.syslog1.name, panos_syslog_profile.syslog2.name]
131+
}
132+
`
Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
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 TestAccSystemLogSettings(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: systemLogSettingsTmpl,
27+
ConfigVariables: map[string]config.Variable{
28+
"prefix": config.StringVariable(prefix),
29+
"description": config.StringVariable("test description"),
30+
"filter": config.StringVariable("(severity eq high)"),
31+
"send_to_panorama": config.BoolVariable(true),
32+
},
33+
ConfigStateChecks: []statecheck.StateCheck{
34+
statecheck.ExpectKnownValue(
35+
"panos_system_log_settings.settings",
36+
tfjsonpath.New("description"),
37+
knownvalue.StringExact("test description"),
38+
),
39+
statecheck.ExpectKnownValue(
40+
"panos_system_log_settings.settings",
41+
tfjsonpath.New("filter"),
42+
knownvalue.StringExact("(severity eq high)"),
43+
),
44+
statecheck.ExpectKnownValue(
45+
"panos_system_log_settings.settings",
46+
tfjsonpath.New("send_to_panorama"),
47+
knownvalue.Bool(true),
48+
),
49+
},
50+
},
51+
{
52+
Config: systemLogSettingsTmpl,
53+
ConfigVariables: map[string]config.Variable{
54+
"prefix": config.StringVariable(prefix),
55+
"description": config.StringVariable("updated description"),
56+
"filter": config.StringVariable("(severity eq critical)"),
57+
"send_to_panorama": config.BoolVariable(false),
58+
"actions": config.ListVariable(config.ObjectVariable(map[string]config.Variable{
59+
"name": config.StringVariable("azure-action"),
60+
"type": config.ObjectVariable(map[string]config.Variable{
61+
"integration": config.ObjectVariable(map[string]config.Variable{
62+
"action": config.StringVariable("Azure-Security-Center-Integration"),
63+
}),
64+
}),
65+
})),
66+
},
67+
ConfigStateChecks: []statecheck.StateCheck{
68+
statecheck.ExpectKnownValue(
69+
"panos_system_log_settings.settings",
70+
tfjsonpath.New("description"),
71+
knownvalue.StringExact("updated description"),
72+
),
73+
statecheck.ExpectKnownValue(
74+
"panos_system_log_settings.settings",
75+
tfjsonpath.New("filter"),
76+
knownvalue.StringExact("(severity eq critical)"),
77+
),
78+
statecheck.ExpectKnownValue(
79+
"panos_system_log_settings.settings",
80+
tfjsonpath.New("send_to_panorama"),
81+
knownvalue.Bool(false),
82+
),
83+
statecheck.ExpectKnownValue(
84+
"panos_system_log_settings.settings",
85+
tfjsonpath.New("actions").AtSliceIndex(0).AtMapKey("name"),
86+
knownvalue.StringExact("azure-action"),
87+
),
88+
statecheck.ExpectKnownValue(
89+
"panos_system_log_settings.settings",
90+
tfjsonpath.New("actions").AtSliceIndex(0).AtMapKey("type").AtMapKey("integration").AtMapKey("action"),
91+
knownvalue.StringExact("Azure-Security-Center-Integration"),
92+
),
93+
},
94+
},
95+
},
96+
})
97+
}
98+
99+
const systemLogSettingsTmpl = `
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 = list(object({
106+
name = string
107+
type = object({
108+
integration = object({
109+
action = string
110+
})
111+
})
112+
}))
113+
default = []
114+
}
115+
116+
117+
resource "panos_template" "tmpl" {
118+
location = { panorama = {} }
119+
name = var.prefix
120+
}
121+
122+
resource "panos_syslog_profile" "syslog1" {
123+
location = { template = { name = panos_template.tmpl.name } }
124+
125+
name = "${var.prefix}1"
126+
127+
servers = [{
128+
name = "server2"
129+
server = "10.0.0.2"
130+
}]
131+
}
132+
133+
resource "panos_syslog_profile" "syslog2" {
134+
location = { template = { name = panos_template.tmpl.name } }
135+
136+
name = "${var.prefix}2"
137+
138+
servers = [{
139+
name = "server2"
140+
server = "10.0.0.2"
141+
}]
142+
}
143+
144+
resource "panos_system_log_settings" "settings" {
145+
location = { template = { name = panos_template.tmpl.name } }
146+
name = var.prefix
147+
description = var.description
148+
filter = var.filter
149+
send_to_panorama = var.send_to_panorama
150+
syslog_profiles = [panos_syslog_profile.syslog1.name, panos_syslog_profile.syslog2.name]
151+
actions = var.actions
152+
}
153+
`

0 commit comments

Comments
 (0)