0
0
mirror of https://github.com/bpg/terraform-provider-proxmox.git synced 2025-06-30 02:31:10 +00:00
terraform-provider-proxmox/proxmoxtf/datasource/cluster/firewall.go
2023-07-15 20:35:40 -04:00

67 lines
1.9 KiB
Go

/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
package cluster
import (
"context"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
fw "github.com/bpg/proxmox-api/firewall"
"github.com/bpg/terraform-provider-proxmox/proxmoxtf"
"github.com/bpg/terraform-provider-proxmox/proxmoxtf/datasource/firewall"
)
// FirewallAlias returns a resource that represents a single firewall alias.
func FirewallAlias() *schema.Resource {
return &schema.Resource{
Schema: firewall.AliasSchema(),
ReadContext: invokeFirewallAPI(firewall.AliasRead),
}
}
// FirewallAliases returns a resource that represents firewall aliases.
func FirewallAliases() *schema.Resource {
return &schema.Resource{
Schema: firewall.AliasesSchema(),
ReadContext: invokeFirewallAPI(firewall.AliasesRead),
}
}
// FirewallIPSet returns a resource that represents a single firewall IP set.
func FirewallIPSet() *schema.Resource {
return &schema.Resource{
Schema: firewall.IPSetSchema(),
ReadContext: invokeFirewallAPI(firewall.IPSetRead),
}
}
// FirewallIPSets returns a resource that represents firewall IP sets.
func FirewallIPSets() *schema.Resource {
return &schema.Resource{
Schema: firewall.IPSetsSchema(),
ReadContext: invokeFirewallAPI(firewall.IPSetsRead),
}
}
func invokeFirewallAPI(
f func(context.Context, fw.API, *schema.ResourceData) diag.Diagnostics,
) func(context.Context, *schema.ResourceData, interface{}) diag.Diagnostics {
return func(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
config := m.(proxmoxtf.ProviderConfiguration)
api, err := config.GetClient()
if err != nil {
return diag.FromErr(err)
}
return f(ctx, api.Cluster().Firewall(), d)
}
}