Skip to content

Commit

Permalink
Add policy assignment resource and data source (netascode#91) applyin…
Browse files Browse the repository at this point in the history
…g review suggestions
  • Loading branch information
wojciech-bainhelixpe committed Dec 3, 2024
1 parent 0ebd25b commit 5ca48bc
Show file tree
Hide file tree
Showing 6 changed files with 0 additions and 65 deletions.
2 changes: 0 additions & 2 deletions docs/data-sources/policy_assignments.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,11 @@ data "fmc_policy_assignments" "example" {
- `name` (String) Name of the policy to be assigned.
- `policy_id` (String) ID of the policy to be assigned.
- `targets` (Attributes Set) (see [below for nested schema](#nestedatt--targets))
- `type` (String) Type of the policy to be assigned.

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

Read-Only:

- `id` (String)
- `name` (String)
- `type` (String)
5 changes: 0 additions & 5 deletions docs/resources/policy_assignments.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ resource "fmc_policy_assignments" "example" {

- `domain` (String) The name of the FMC domain
- `name` (String) Name of the policy to be assigned.
- `type` (String) Type of the policy to be assigned.

### Read-Only

Expand All @@ -50,10 +49,6 @@ Required:
- `id` (String)
- `type` (String) - Choices: `Device`, `DeviceHAPair`, `DeviceGroup`

Optional:

- `name` (String)

## Import

Import is supported using the following syntax:
Expand Down
14 changes: 0 additions & 14 deletions gen/definitions/policyassignments.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,6 @@ attributes:
data_path: ["policy"]
exclude_example: true
exclude_test: true
- model_name: type
type: String
description: Type of the policy to be assigned.
mandatory: false
example: AccessPolicy
data_path: ["policy"]
exclude_example: true
exclude_test: true
- model_name: id
tf_name: policy_id
type: String
Expand All @@ -48,12 +40,6 @@ attributes:
enum_values: [Device,DeviceHAPair,DeviceGroup]
mandatory: true
example: DeviceGroup
- model_name: name
type: String
mandatory: false
example: FTD_Device1
exclude_example: true
exclude_test: true

test_prerequisites: |-
resource "fmc_access_control_policy" "example" {
Expand Down
8 changes: 0 additions & 8 deletions internal/provider/data_source_fmc_policy_assignments.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,6 @@ func (d *PolicyAssignmentsDataSource) Schema(ctx context.Context, req datasource
MarkdownDescription: "Name of the policy to be assigned.",
Computed: true,
},
"type": schema.StringAttribute{
MarkdownDescription: "Type of the policy to be assigned.",
Computed: true,
},
"policy_id": schema.StringAttribute{
MarkdownDescription: "ID of the policy to be assigned.",
Computed: true,
Expand All @@ -90,10 +86,6 @@ func (d *PolicyAssignmentsDataSource) Schema(ctx context.Context, req datasource
MarkdownDescription: "",
Computed: true,
},
"name": schema.StringAttribute{
MarkdownDescription: "",
Computed: true,
},
},
},
},
Expand Down
28 changes: 0 additions & 28 deletions internal/provider/model_fmc_policy_assignments.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,13 @@ type PolicyAssignments struct {
Id types.String `tfsdk:"id"`
Domain types.String `tfsdk:"domain"`
Name types.String `tfsdk:"name"`
Type types.String `tfsdk:"type"`
PolicyId types.String `tfsdk:"policy_id"`
Targets []PolicyAssignmentsTargets `tfsdk:"targets"`
}

type PolicyAssignmentsTargets struct {
Id types.String `tfsdk:"id"`
Type types.String `tfsdk:"type"`
Name types.String `tfsdk:"name"`
}

// End of section. //template:end types
Expand All @@ -69,9 +67,6 @@ func (data PolicyAssignments) toBody(ctx context.Context, state PolicyAssignment
if !data.Name.IsNull() {
body, _ = sjson.Set(body, "policy.name", data.Name.ValueString())
}
if !data.Type.IsNull() {
body, _ = sjson.Set(body, "policy.type", data.Type.ValueString())
}
if !data.PolicyId.IsNull() {
body, _ = sjson.Set(body, "policy.id", data.PolicyId.ValueString())
}
Expand All @@ -85,9 +80,6 @@ func (data PolicyAssignments) toBody(ctx context.Context, state PolicyAssignment
if !item.Type.IsNull() {
itemBody, _ = sjson.Set(itemBody, "type", item.Type.ValueString())
}
if !item.Name.IsNull() {
itemBody, _ = sjson.Set(itemBody, "name", item.Name.ValueString())
}
body, _ = sjson.SetRaw(body, "targets.-1", itemBody)
}
}
Expand All @@ -104,11 +96,6 @@ func (data *PolicyAssignments) fromBody(ctx context.Context, res gjson.Result) {
} else {
data.Name = types.StringNull()
}
if value := res.Get("policy.type"); value.Exists() {
data.Type = types.StringValue(value.String())
} else {
data.Type = types.StringNull()
}
if value := res.Get("policy.id"); value.Exists() {
data.PolicyId = types.StringValue(value.String())
} else {
Expand All @@ -129,11 +116,6 @@ func (data *PolicyAssignments) fromBody(ctx context.Context, res gjson.Result) {
} else {
data.Type = types.StringNull()
}
if value := res.Get("name"); value.Exists() {
data.Name = types.StringValue(value.String())
} else {
data.Name = types.StringNull()
}
(*parent).Targets = append((*parent).Targets, data)
return true
})
Expand All @@ -154,11 +136,6 @@ func (data *PolicyAssignments) fromBodyPartial(ctx context.Context, res gjson.Re
} else {
data.Name = types.StringNull()
}
if value := res.Get("policy.type"); value.Exists() && !data.Type.IsNull() {
data.Type = types.StringValue(value.String())
} else {
data.Type = types.StringNull()
}
if value := res.Get("policy.id"); value.Exists() && !data.PolicyId.IsNull() {
data.PolicyId = types.StringValue(value.String())
} else {
Expand Down Expand Up @@ -210,11 +187,6 @@ func (data *PolicyAssignments) fromBodyPartial(ctx context.Context, res gjson.Re
} else {
data.Type = types.StringNull()
}
if value := res.Get("name"); value.Exists() && !data.Name.IsNull() {
data.Name = types.StringValue(value.String())
} else {
data.Name = types.StringNull()
}
(*parent).Targets[i] = data
}
}
Expand Down
8 changes: 0 additions & 8 deletions internal/provider/resource_fmc_policy_assignments.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,6 @@ func (r *PolicyAssignmentsResource) Schema(ctx context.Context, req resource.Sch
MarkdownDescription: helpers.NewAttributeDescription("Name of the policy to be assigned.").String,
Optional: true,
},
"type": schema.StringAttribute{
MarkdownDescription: helpers.NewAttributeDescription("Type of the policy to be assigned.").String,
Optional: true,
},
"policy_id": schema.StringAttribute{
MarkdownDescription: helpers.NewAttributeDescription("ID of the policy to be assigned.").String,
Required: true,
Expand All @@ -110,10 +106,6 @@ func (r *PolicyAssignmentsResource) Schema(ctx context.Context, req resource.Sch
stringvalidator.OneOf("Device", "DeviceHAPair", "DeviceGroup"),
},
},
"name": schema.StringAttribute{
MarkdownDescription: helpers.NewAttributeDescription("").String,
Optional: true,
},
},
},
},
Expand Down

0 comments on commit 5ca48bc

Please sign in to comment.