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