|
| 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