|
| 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 TestAccGlobalprotectLogSettings(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: globalprotectLogSettingsTmpl, |
| 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_globalprotect_log_settings.settings", |
| 36 | + tfjsonpath.New("description"), |
| 37 | + knownvalue.StringExact("test description"), |
| 38 | + ), |
| 39 | + // statecheck.ExpectKnownValue( |
| 40 | + // "panos_globalprotect_log_settings.settings", |
| 41 | + // tfjsonpath.New("filter"), |
| 42 | + // knownvalue.StringExact("(severity eq high)"), |
| 43 | + // ), |
| 44 | + statecheck.ExpectKnownValue( |
| 45 | + "panos_globalprotect_log_settings.settings", |
| 46 | + tfjsonpath.New("send_to_panorama"), |
| 47 | + knownvalue.Bool(true), |
| 48 | + ), |
| 49 | + }, |
| 50 | + }, |
| 51 | + { |
| 52 | + Config: globalprotectLogSettingsTmpl, |
| 53 | + ConfigVariables: map[string]config.Variable{ |
| 54 | + "prefix": config.StringVariable(prefix), |
| 55 | + "description": config.StringVariable("updated description"), |
| 56 | + "filter": config.StringVariable("(status eq 200)"), |
| 57 | + "send_to_panorama": config.BoolVariable(false), |
| 58 | + "actions": config.ListVariable(config.ObjectVariable(map[string]config.Variable{ |
| 59 | + "name": config.StringVariable("tag-action"), |
| 60 | + "type": config.ObjectVariable(map[string]config.Variable{ |
| 61 | + "tagging": config.ObjectVariable(map[string]config.Variable{ |
| 62 | + "action": config.StringVariable("add-tag"), |
| 63 | + "target": config.StringVariable("source-address"), |
| 64 | + "tags": config.ListVariable(config.StringVariable("tag1"), config.StringVariable("tag2")), |
| 65 | + }), |
| 66 | + }), |
| 67 | + })), |
| 68 | + }, |
| 69 | + ConfigStateChecks: []statecheck.StateCheck{ |
| 70 | + statecheck.ExpectKnownValue( |
| 71 | + "panos_globalprotect_log_settings.settings", |
| 72 | + tfjsonpath.New("description"), |
| 73 | + knownvalue.StringExact("updated description"), |
| 74 | + ), |
| 75 | + // statecheck.ExpectKnownValue( |
| 76 | + // "panos_globalprotect_log_settings.settings", |
| 77 | + // tfjsonpath.New("filter"), |
| 78 | + // knownvalue.StringExact("(severity eq critical)"), |
| 79 | + // ), |
| 80 | + statecheck.ExpectKnownValue( |
| 81 | + "panos_globalprotect_log_settings.settings", |
| 82 | + tfjsonpath.New("send_to_panorama"), |
| 83 | + knownvalue.Bool(false), |
| 84 | + ), |
| 85 | + statecheck.ExpectKnownValue( |
| 86 | + "panos_globalprotect_log_settings.settings", |
| 87 | + tfjsonpath.New("actions").AtSliceIndex(0).AtMapKey("name"), |
| 88 | + knownvalue.StringExact("tag-action"), |
| 89 | + ), |
| 90 | + }, |
| 91 | + }, |
| 92 | + }, |
| 93 | + }) |
| 94 | +} |
| 95 | + |
| 96 | +const globalprotectLogSettingsTmpl = ` |
| 97 | +variable "prefix" { type = string } |
| 98 | +variable "description" { type = string } |
| 99 | +variable "filter" { type = string } |
| 100 | +variable "send_to_panorama" { type = bool } |
| 101 | +variable "actions" { |
| 102 | + type = any |
| 103 | + default = [] |
| 104 | +} |
| 105 | +
|
| 106 | +
|
| 107 | +resource "panos_template" "tmpl" { |
| 108 | + location = { panorama = {} } |
| 109 | + name = var.prefix |
| 110 | +} |
| 111 | +
|
| 112 | +resource "panos_globalprotect_log_settings" "settings" { |
| 113 | + location = { template = { name = panos_template.tmpl.name } } |
| 114 | + name = var.prefix |
| 115 | + description = var.description |
| 116 | + #filter = var.filter |
| 117 | + send_to_panorama = var.send_to_panorama |
| 118 | + actions = var.actions |
| 119 | +} |
| 120 | +` |
0 commit comments