Skip to content
Draft
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
19 changes: 17 additions & 2 deletions pkg/translate/terraform_provider/terraform_provider_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,17 @@ func (g *GenerateTerraformProvider) generateTerraformEntityTemplate(resourceTyp
return g.executeTemplate(template, spec, terraformProvider, resourceTyp, schemaTyp, names)
}

func locationVariablesWithDefaults(locations map[string]*properties.Location) bool {
for _, location := range locations {
for _, variable := range location.Vars {
if variable.Default != "" {
return true
}
}
}
return false
}

// GenerateTerraformResource generates a Terraform resource template.
func (g *GenerateTerraformProvider) GenerateTerraformResource(resourceTyp properties.ResourceType, spec *properties.Normalization, terraformProvider *properties.TerraformProviderFile) error {
names := NewNameProvider(spec, resourceTyp)
Expand Down Expand Up @@ -271,7 +282,9 @@ func (g *GenerateTerraformProvider) GenerateTerraformResource(resourceTyp proper

if len(spec.Locations) > 0 {
terraformProvider.ImportManager.AddHashicorpImport("github.com/hashicorp/terraform-plugin-framework/diag", "")
terraformProvider.ImportManager.AddHashicorpImport("github.com/hashicorp/terraform-plugin-framework/resource/schema/stringdefault", "")
if locationVariablesWithDefaults(spec.Locations) {
terraformProvider.ImportManager.AddHashicorpImport("github.com/hashicorp/terraform-plugin-framework/resource/schema/stringdefault", "")
}
terraformProvider.ImportManager.AddHashicorpImport("github.com/hashicorp/terraform-plugin-log/tflog", "")
}

Expand Down Expand Up @@ -343,7 +356,9 @@ func (g *GenerateTerraformProvider) GenerateTerraformDataSource(resourceTyp prop
conditionallyAddModifiers(terraformProvider.ImportManager, spec)

terraformProvider.ImportManager.AddHashicorpImport("github.com/hashicorp/terraform-plugin-framework/resource/schema", "rsschema")
terraformProvider.ImportManager.AddHashicorpImport("github.com/hashicorp/terraform-plugin-framework/resource/schema/stringdefault", "")
if locationVariablesWithDefaults(spec.Locations) {
terraformProvider.ImportManager.AddHashicorpImport("github.com/hashicorp/terraform-plugin-framework/resource/schema/stringdefault", "")
}

names := NewNameProvider(spec, resourceTyp)
funcMap := template.FuncMap{
Expand Down
114 changes: 114 additions & 0 deletions specs/panorama/devices.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
name: mgt-config-devices
terraform_provider_config:
description: Firewall Devices
skip_resource: false
skip_datasource: false
resource_type: entry
resource_variants:
- singular
suffix: firewall_device
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's call it managed_device

plural_description: ""
go_sdk_config:
skip: false
package:
- panorama
- devices
xpath_suffix:
- mgt-config
- devices
locations:
- name: panorama
xpath:
path:
- config
vars: []
description: Located in a panorama.
validators: []
required: false
read_only: false
entries:
- name: name
description: ""
validators: []
imports: []
spec:
params:
- name: auto-push
type: bool
profiles:
- xpath:
- auto-push
validators: []
spec: {}
description: ""
required: false
- name: disable-config-backup
type: bool
profiles:
- xpath:
- disable-config-backup
validators: []
spec: {}
description: Enable config back up for this device
required: false
- name: hostname
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be read only I think

type: string
profiles:
- xpath:
- hostname
validators: []
spec: {}
description: ip address
required: false
- name: ip
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Read only

type: string
profiles:
- xpath:
- ip
validators: []
spec: {}
description: ip address
required: false
- name: to-sw-version
type: string
profiles:
- xpath:
- to-sw-version
validators:
- type: length
spec:
max: 64
spec: {}
description: Automatically upgrade software to this version for new deployments
required: false
- name: vsys
type: list
profiles:
- xpath:
- vsys
- entry
type: entry
validators: []
spec:
type: object
items:
type: object
spec:
params:
- name: tags
type: list
profiles:
- xpath:
- tags
type: member
validators: []
spec:
type: string
items:
type: string
description: ""
required: false
variants: []
description: ""
required: false
variants: []
Loading