Skip to content

Commit c732f35

Browse files
committed
feat(specs): Add spec, tests and examples for panos_virtual_system
1 parent 6dd358e commit c732f35

3 files changed

Lines changed: 224 additions & 1 deletion

File tree

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
package provider_test
2+
3+
import (
4+
"fmt"
5+
"regexp"
6+
"testing"
7+
8+
"github.com/hashicorp/terraform-plugin-testing/config"
9+
"github.com/hashicorp/terraform-plugin-testing/helper/acctest"
10+
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
11+
"github.com/hashicorp/terraform-plugin-testing/knownvalue"
12+
"github.com/hashicorp/terraform-plugin-testing/statecheck"
13+
"github.com/hashicorp/terraform-plugin-testing/tfjsonpath"
14+
)
15+
16+
// TestAccPanosVsys_ConflictWithTemplateDefaultVsys verifies that creating a
17+
// panos_vsys resource for "vsys1" fails when the template already has
18+
// default_vsys = "vsys1" (because the template's PostCreate hook already
19+
// created that vsys entry).
20+
func TestAccPanosVsys_ConflictWithTemplateDefaultVsys(t *testing.T) {
21+
t.Parallel()
22+
23+
nameSuffix := acctest.RandStringFromCharSet(6, acctest.CharSetAlphaNum)
24+
prefix := fmt.Sprintf("test-acc-%s", nameSuffix)
25+
26+
location := config.ObjectVariable(map[string]config.Variable{
27+
"panorama": config.ObjectVariable(map[string]config.Variable{}),
28+
})
29+
30+
configVars := map[string]config.Variable{
31+
"prefix": config.StringVariable(prefix),
32+
"location": location,
33+
}
34+
35+
resource.Test(t, resource.TestCase{
36+
PreCheck: func() { testAccPreCheck(t) },
37+
ProtoV6ProviderFactories: testAccProviders,
38+
Steps: []resource.TestStep{
39+
{
40+
Config: vsys_ConflictWithTemplateDefaultVsys_Tmpl,
41+
ConfigVariables: configVars,
42+
ExpectError: regexp.MustCompile(`.`),
43+
},
44+
},
45+
})
46+
}
47+
48+
const vsys_ConflictWithTemplateDefaultVsys_Tmpl = `
49+
variable "prefix" { type = string }
50+
variable "location" { type = any }
51+
52+
resource "panos_template" "test" {
53+
location = var.location
54+
name = "${var.prefix}-template"
55+
default_vsys = "vsys1"
56+
}
57+
58+
resource "panos_vsys" "vsys1" {
59+
location = {
60+
template = {
61+
name = panos_template.test.name
62+
}
63+
}
64+
name = "vsys1"
65+
}
66+
`
67+
68+
// TestAccPanosVsys_WithTemplate verifies that creating a panos_vsys resource
69+
// for "vsys2" succeeds when the template has default_vsys = "vsys1" (a
70+
// different vsys name, so no conflict).
71+
func TestAccPanosVsys_WithTemplate(t *testing.T) {
72+
t.Parallel()
73+
74+
nameSuffix := acctest.RandStringFromCharSet(6, acctest.CharSetAlphaNum)
75+
prefix := fmt.Sprintf("test-acc-%s", nameSuffix)
76+
77+
location := config.ObjectVariable(map[string]config.Variable{
78+
"panorama": config.ObjectVariable(map[string]config.Variable{}),
79+
})
80+
81+
configVars := map[string]config.Variable{
82+
"prefix": config.StringVariable(prefix),
83+
"location": location,
84+
}
85+
86+
resource.Test(t, resource.TestCase{
87+
PreCheck: func() { testAccPreCheck(t) },
88+
ProtoV6ProviderFactories: testAccProviders,
89+
Steps: []resource.TestStep{
90+
{
91+
Config: vsys_WithTemplate_Tmpl,
92+
ConfigVariables: configVars,
93+
ConfigStateChecks: []statecheck.StateCheck{
94+
statecheck.ExpectKnownValue(
95+
"panos_vsys.vsys2",
96+
tfjsonpath.New("name"),
97+
knownvalue.StringExact("vsys2"),
98+
),
99+
},
100+
},
101+
},
102+
})
103+
}
104+
105+
const vsys_WithTemplate_Tmpl = `
106+
variable "prefix" { type = string }
107+
variable "location" { type = any }
108+
109+
resource "panos_template" "test" {
110+
location = var.location
111+
name = "${var.prefix}-template"
112+
default_vsys = "vsys1"
113+
}
114+
115+
resource "panos_vsys" "vsys2" {
116+
location = {
117+
template = {
118+
name = panos_template.test.name
119+
}
120+
}
121+
name = "vsys2"
122+
}
123+
`

pkg/translate/imports.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,10 @@ func RenderImports(spec *properties.Normalization, templateTypes ...string) (str
2424
manager.AddStandardImport("fmt", "")
2525
manager.AddSdkImport("github.com/PaloAltoNetworks/pango/filtering", "")
2626
manager.AddSdkImport("github.com/PaloAltoNetworks/pango/generic", "")
27-
manager.AddSdkImport("github.com/PaloAltoNetworks/pango/util", "")
2827
manager.AddSdkImport("github.com/PaloAltoNetworks/pango/version", "")
28+
if len(spec.Spec.Params) > 0 || len(spec.Spec.OneOf) > 0 {
29+
manager.AddSdkImport("github.com/PaloAltoNetworks/pango/util", "")
30+
}
2931

3032
if spec.HasParametersWithStrconv() {
3133
manager.AddStandardImport("errors", "")

specs/device/vsys.yaml

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
name: vsys
2+
terraform_provider_config:
3+
description: Proxy configuration
4+
skip_resource: false
5+
skip_datasource: false
6+
resource_type: entry
7+
resource_variants: []
8+
suffix: vsys
9+
plural_suffix: ''
10+
plural_name: ''
11+
plural_description: ''
12+
go_sdk_config:
13+
skip: false
14+
package:
15+
- device
16+
- vsys
17+
panos_xpath:
18+
path:
19+
- vsys
20+
vars: []
21+
locations:
22+
- name: template
23+
xpath:
24+
path:
25+
- config
26+
- devices
27+
- $panorama_device
28+
- template
29+
- $template
30+
- config
31+
- devices
32+
- $ngfw_device
33+
vars:
34+
- name: panorama_device
35+
description: Specific Panorama device
36+
required: false
37+
default: localhost.localdomain
38+
validators: []
39+
type: entry
40+
- name: template
41+
description: Specific Panorama template
42+
required: true
43+
validators: []
44+
type: entry
45+
- name: ngfw_device
46+
description: The NGFW device
47+
required: false
48+
default: localhost.localdomain
49+
validators: []
50+
type: entry
51+
description: Located in a specific template
52+
devices:
53+
- panorama
54+
validators: []
55+
required: false
56+
read_only: false
57+
- name: template-stack
58+
xpath:
59+
path:
60+
- config
61+
- devices
62+
- $panorama_device
63+
- template-stack
64+
- $template_stack
65+
- config
66+
- devices
67+
- $ngfw_device
68+
vars:
69+
- name: panorama_device
70+
description: Specific Panorama device
71+
required: false
72+
default: localhost.localdomain
73+
validators: []
74+
type: entry
75+
- name: template_stack
76+
description: Specific Panorama template stack
77+
required: true
78+
validators: []
79+
type: entry
80+
- name: ngfw_device
81+
description: The NGFW device
82+
required: false
83+
default: localhost.localdomain
84+
validators: []
85+
type: entry
86+
description: Located in a specific template stack
87+
devices:
88+
- panorama
89+
validators: []
90+
required: false
91+
read_only: false
92+
entries:
93+
- name: name
94+
description: ''
95+
validators: []
96+
spec:
97+
params: []
98+
variants: []

0 commit comments

Comments
 (0)