Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
123 changes: 123 additions & 0 deletions assets/terraform/test/resource_vsys_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
package provider_test

import (
"fmt"
"regexp"
"testing"

"github.com/hashicorp/terraform-plugin-testing/config"
"github.com/hashicorp/terraform-plugin-testing/helper/acctest"
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
"github.com/hashicorp/terraform-plugin-testing/knownvalue"
"github.com/hashicorp/terraform-plugin-testing/statecheck"
"github.com/hashicorp/terraform-plugin-testing/tfjsonpath"
)

// TestAccPanosVsys_ConflictWithTemplateDefaultVsys verifies that creating a
// panos_vsys resource for "vsys1" fails when the template already has
// default_vsys = "vsys1" (because the template's PostCreate hook already
// created that vsys entry).
func TestAccPanosVsys_ConflictWithTemplateDefaultVsys(t *testing.T) {
t.Parallel()

nameSuffix := acctest.RandStringFromCharSet(6, acctest.CharSetAlphaNum)
prefix := fmt.Sprintf("test-acc-%s", nameSuffix)

location := config.ObjectVariable(map[string]config.Variable{
"panorama": config.ObjectVariable(map[string]config.Variable{}),
})

configVars := map[string]config.Variable{
"prefix": config.StringVariable(prefix),
"location": location,
}

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProtoV6ProviderFactories: testAccProviders,
Steps: []resource.TestStep{
{
Config: vsys_ConflictWithTemplateDefaultVsys_Tmpl,
ConfigVariables: configVars,
ExpectError: regexp.MustCompile(`.`),
},
},
})
}

const vsys_ConflictWithTemplateDefaultVsys_Tmpl = `
variable "prefix" { type = string }
variable "location" { type = any }

resource "panos_template" "test" {
location = var.location
name = "${var.prefix}-template"
default_vsys = "vsys1"
}

resource "panos_vsys" "vsys1" {
location = {
template = {
name = panos_template.test.name
}
}
name = "vsys1"
}
`

// TestAccPanosVsys_WithTemplate verifies that creating a panos_vsys resource
// for "vsys2" succeeds when the template has default_vsys = "vsys1" (a
// different vsys name, so no conflict).
func TestAccPanosVsys_WithTemplate(t *testing.T) {
t.Parallel()

nameSuffix := acctest.RandStringFromCharSet(6, acctest.CharSetAlphaNum)
prefix := fmt.Sprintf("test-acc-%s", nameSuffix)

location := config.ObjectVariable(map[string]config.Variable{
"panorama": config.ObjectVariable(map[string]config.Variable{}),
})

configVars := map[string]config.Variable{
"prefix": config.StringVariable(prefix),
"location": location,
}

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProtoV6ProviderFactories: testAccProviders,
Steps: []resource.TestStep{
{
Config: vsys_WithTemplate_Tmpl,
ConfigVariables: configVars,
ConfigStateChecks: []statecheck.StateCheck{
statecheck.ExpectKnownValue(
"panos_vsys.vsys2",
tfjsonpath.New("name"),
knownvalue.StringExact("vsys2"),
),
},
},
},
})
}

const vsys_WithTemplate_Tmpl = `
variable "prefix" { type = string }
variable "location" { type = any }

resource "panos_template" "test" {
location = var.location
name = "${var.prefix}-template"
default_vsys = "vsys1"
}

resource "panos_vsys" "vsys2" {
location = {
template = {
name = panos_template.test.name
}
}
name = "vsys2"
}
`
4 changes: 3 additions & 1 deletion pkg/translate/imports.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ func RenderImports(spec *properties.Normalization, templateTypes ...string) (str
manager.AddStandardImport("fmt", "")
manager.AddSdkImport("github.com/PaloAltoNetworks/pango/filtering", "")
manager.AddSdkImport("github.com/PaloAltoNetworks/pango/generic", "")
manager.AddSdkImport("github.com/PaloAltoNetworks/pango/util", "")
manager.AddSdkImport("github.com/PaloAltoNetworks/pango/version", "")
if len(spec.Spec.Params) > 0 || len(spec.Spec.OneOf) > 0 {
manager.AddSdkImport("github.com/PaloAltoNetworks/pango/util", "")
}

if spec.HasParametersWithStrconv() {
manager.AddStandardImport("errors", "")
Expand Down
98 changes: 98 additions & 0 deletions specs/device/vsys.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
name: vsys
terraform_provider_config:
description: Proxy configuration
skip_resource: false
skip_datasource: false
resource_type: entry
resource_variants: []
suffix: vsys
plural_suffix: ''
plural_name: ''
plural_description: ''
go_sdk_config:
skip: false
package:
- device
- vsys
panos_xpath:
path:
- vsys
vars: []
locations:
- name: template
xpath:
path:
- config
- devices
- $panorama_device
- template
- $template
- config
- devices
- $ngfw_device
vars:
- name: panorama_device
description: Specific Panorama device
required: false
default: localhost.localdomain
validators: []
type: entry
- name: template
description: Specific Panorama template
required: true
validators: []
type: entry
- name: ngfw_device
description: The NGFW device
required: false
default: localhost.localdomain
validators: []
type: entry
description: Located in a specific template
devices:
- panorama
validators: []
required: false
read_only: false
- name: template-stack
xpath:
path:
- config
- devices
- $panorama_device
- template-stack
- $template_stack
- config
- devices
- $ngfw_device
vars:
- name: panorama_device
description: Specific Panorama device
required: false
default: localhost.localdomain
validators: []
type: entry
- name: template_stack
description: Specific Panorama template stack
required: true
validators: []
type: entry
- name: ngfw_device
description: The NGFW device
required: false
default: localhost.localdomain
validators: []
type: entry
description: Located in a specific template stack
devices:
- panorama
validators: []
required: false
read_only: false
entries:
- name: name
description: ''
validators: []
spec:
params: []
variants: []
Loading