Skip to content

Commit

Permalink
Add bulk port groups resource and data source (#183)
Browse files Browse the repository at this point in the history
  • Loading branch information
rchrabas authored Nov 18, 2024
1 parent 648ed76 commit 2470317
Show file tree
Hide file tree
Showing 14 changed files with 1,484 additions and 2 deletions.
53 changes: 53 additions & 0 deletions docs/data-sources/port_groups.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "fmc_port_groups Data Source - terraform-provider-fmc"
subcategory: "Objects"
description: |-
This data source can read the Port Groups.
---

# fmc_port_groups (Data Source)

This data source can read the Port Groups.

## Example Usage

```terraform
data "fmc_port_groups" "example" {
items = {
"port_group_1" = {
}
}
}
```

<!-- schema generated by tfplugindocs -->
## Schema

### Optional

- `domain` (String) The name of the FMC domain
- `items` (Attributes Map) Map of port groups. The key of the map is the name of the individual Port Group. (see [below for nested schema](#nestedatt--items))

### Read-Only

- `id` (String) The id of the object

<a id="nestedatt--items"></a>
### Nested Schema for `items`

Read-Only:

- `description` (String) Optional user-created description.
- `id` (String) UUID of the managed Port Groups.
- `overridable` (Boolean) Indicates whether object values can be overridden.
- `ports` (Attributes Set) (see [below for nested schema](#nestedatt--items--ports))
- `type` (String)

<a id="nestedatt--items--ports"></a>
### Nested Schema for `items.ports`

Read-Only:

- `id` (String) UUID of the port (such as fmc_port.test.id, etc.).
- `type` (String)
81 changes: 81 additions & 0 deletions docs/resources/port_groups.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "fmc_port_groups Resource - terraform-provider-fmc"
subcategory: "Objects"
description: |-
This plural resource manages a bulk of Port Groups. The FMC API supports quick bulk creation for this resource, but the deletion/modification is done one-by-one. Updating and deleting fmc_port_groups can thus take much more time than creating it (even >500 times more time, i.e. >50000%, depending on the change size).
---

# fmc_port_groups (Resource)

This plural resource manages a bulk of Port Groups. The FMC API supports quick bulk creation for this resource, but the deletion/modification is done one-by-one. Updating and deleting `fmc_port_groups` can thus take much more time than creating it (even >500 times more time, i.e. >50000%, depending on the change size).

## Example Usage

```terraform
resource "fmc_port_groups" "example" {
items = {
port_group_1 = {
type = "PortObjectGroup"
description = "My port group description"
ports = [
{
id = "0050568A-232D-0ed3-0000-004294971602"
type = "ProtocolPortObject"
}
]
}
}
}
```

<!-- schema generated by tfplugindocs -->
## Schema

### Required

- `items` (Attributes Map) Map of port groups. The key of the map is the name of the individual Port Group. (see [below for nested schema](#nestedatt--items))

### Optional

- `domain` (String) The name of the FMC domain

### Read-Only

- `id` (String) The id of the object

<a id="nestedatt--items"></a>
### Nested Schema for `items`

Required:

- `ports` (Attributes Set) (see [below for nested schema](#nestedatt--items--ports))
- `type` (String)

Optional:

- `description` (String) Optional user-created description.
- `overridable` (Boolean) Indicates whether object values can be overridden.

Read-Only:

- `id` (String) UUID of the managed Port Groups.

<a id="nestedatt--items--ports"></a>
### Nested Schema for `items.ports`

Required:

- `type` (String) - Choices: `ProtocolPortObject`, `ICMPV6Object`, `ICMPV4Object`

Optional:

- `id` (String) UUID of the port (such as fmc_port.test.id, etc.).

## Import

Import is supported using the following syntax:

```shell
terraform import fmc_port_groups.example "<domain>,[<port_groups_name>]"
```
6 changes: 6 additions & 0 deletions examples/data-sources/fmc_port_groups/data-source.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
data "fmc_port_groups" "example" {
items = {
"port_group_1" = {
}
}
}
1 change: 1 addition & 0 deletions examples/resources/fmc_port_groups/import.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
terraform import fmc_port_groups.example "<domain>,[<port_groups_name>]"
14 changes: 14 additions & 0 deletions examples/resources/fmc_port_groups/resource.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
resource "fmc_port_groups" "example" {
items = {
port_group_1 = {
type = "PortObjectGroup"
description = "My port group description"
ports = [
{
id = "0050568A-232D-0ed3-0000-004294971602"
type = "ProtocolPortObject"
}
]
}
}
}
63 changes: 63 additions & 0 deletions gen/definitions/port_groups.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
---
name: Port Groups
rest_endpoint: /api/fmc_config/v1/domain/{DOMAIN_UUID}/object/portobjectgroups
res_description: >-
This plural resource manages a bulk of Port Groups.
The FMC API supports quick bulk creation for this resource, but the deletion/modification is done one-by-one.
Updating and deleting `fmc_port_groups` can thus take much more time than creating it (even >500 times more time,
i.e. >50000%, depending on the change size).
data_source_name_query: true
import_name_query: yes
is_bulk: true
doc_category: Objects
attributes:
- model_name: items
type: Map
description: >-
Map of port groups. The key of the map is the name of the individual Port Group.
mandatory: true
map_key_example: port_group_1
attributes:
- model_name: id
type: String
resource_id: true
description: UUID of the managed Port Groups.
exclude_example: true
exclude_test: true
- model_name: type
type: String
mandatory: true
example: "PortObjectGroup"
- model_name: description
type: String
description: Optional user-created description.
example: "My port group description"
- model_name: overridable
type: Bool
description: Indicates whether object values can be overridden.
exclude_example: true
test_value: "true"
- model_name: objects
tf_name: ports
type: Set
mandatory: true
attributes:
- model_name: id
type: String
description: UUID of the port (such as fmc_port.test.id, etc.).
id: true
example: 0050568A-232D-0ed3-0000-004294971602
test_value: fmc_port.test.id
- model_name: type
type: String
mandatory: true
enum_values: [ProtocolPortObject,ICMPV6Object,ICMPV4Object]
example: ProtocolPortObject

test_prerequisites: |-
resource "fmc_port" "test" {
name = "port_1"
description = "My PORT id"
protocol = "TCP"
port = "443"
}
2 changes: 1 addition & 1 deletion gen/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ func IsList(attribute YamlConfigAttribute) bool {

// Templating helper function to return true if type is a set without nested elements
func IsSet(attribute YamlConfigAttribute) bool {
if attribute.Type == "Set" && attribute.ElementType != "" {
if attribute.Type == "Set" && (attribute.ElementType != "" || len(attribute.Attributes) > 0) {
return true
}
return false
Expand Down
13 changes: 12 additions & 1 deletion gen/templates/data_source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,20 @@ func TestAccDataSourceFmc{{camelCase .Name}}(t *testing.T) {
{{- if eq .TfName "id" }}
checks = append(checks, resource.TestCheckResourceAttrSet("data.fmc_{{snakeCase $name}}.test", "{{$list}}.{{$map}}.{{.TfName}}"))
{{- end}}
{{- if and (not .WriteOnly) (not .ExcludeTest) (not .Value) (not .TestValue) (not (isSet .))}}
{{- if and (not .WriteOnly) (not .ExcludeTest) (not .Value) (not .TestValue) (not (isSet .)) }}
checks = append(checks, resource.TestCheckResourceAttr("data.fmc_{{snakeCase $name}}.test", "{{$list}}.{{$map}}.{{.TfName}}", "{{.Example}}"))
{{- end}}
{{- if and (not .WriteOnly) (not .ExcludeTest) (not .Value) (not .TestValue) ( isSet . ) }}
{{- $clist := .TfName }}
{{- range .Attributes}}
{{- if eq .TfName "id" }}
checks = append(checks, resource.TestCheckResourceAttrSet("data.fmc_{{snakeCase $name}}.test", "{{$list}}.{{$map}}.{{$clist}}.0.{{.TfName}}"))
{{- end}}
{{- if and (not .WriteOnly) (not .ExcludeTest) (not .Value) (not .TestValue) (not (isSet .)) }}
checks = append(checks, resource.TestCheckResourceAttr("data.fmc_{{snakeCase $name}}.test", "{{$list}}.{{$map}}.{{$clist}}.0.{{.TfName}}", "{{.Example}}"))
{{- end}}
{{- end}}
{{- end}}
{{- end}}
{{- end}}
{{- if isNestedListSet .}}
Expand Down
Loading

0 comments on commit 2470317

Please sign in to comment.