Files
terraform-provider-tomswallapi/internal/provider/provider.go
T
benvin 08fc9b209b
ci/woodpecker/pr/build Pipeline was successful
ci/woodpecker/pr/pre-commit Pipeline was successful
ci/woodpecker/pr/test Pipeline was successful
Add snat/netmap/nat provider resources
Add tomswallapi_snat, tomswallapi_netmap, and tomswallapi_nat resources for the
NAT tier, following the id-keyed rule-resource pattern (POST create, GET/DELETE
by id, update via delete+recreate since the API is create/delete only, import by
id). Register them, document them in the README, and add examples.
2026-07-24 22:37:54 +10:00

87 lines
2.6 KiB
Go

package provider
import (
"context"
"os"
"github.com/hashicorp/terraform-plugin-framework/datasource"
"github.com/hashicorp/terraform-plugin-framework/provider"
"github.com/hashicorp/terraform-plugin-framework/provider/schema"
"github.com/hashicorp/terraform-plugin-framework/resource"
"github.com/hashicorp/terraform-plugin-framework/types"
)
var _ provider.Provider = &tomswallProvider{}
type tomswallProvider struct {
version string
}
type tomswallProviderModel struct {
Endpoint types.String `tfsdk:"endpoint"`
Token types.String `tfsdk:"token"`
}
// New returns the provider constructor.
func New(version string) func() provider.Provider {
return func() provider.Provider { return &tomswallProvider{version: version} }
}
func (p *tomswallProvider) Metadata(_ context.Context, _ provider.MetadataRequest, resp *provider.MetadataResponse) {
resp.TypeName = "tomswallapi"
resp.Version = p.version
}
func (p *tomswallProvider) Schema(_ context.Context, _ provider.SchemaRequest, resp *provider.SchemaResponse) {
resp.Schema = schema.Schema{
Description: "Manage the tomswall fleet control plane: fleet-global zones, address groups, portgroups, rules, policies, and fabrics, plus per-device zone->interface bindings.",
Attributes: map[string]schema.Attribute{
"endpoint": schema.StringAttribute{
Description: "The tomswallapi base URL (e.g. https://tomswallapi.k8s.syd1.au.unkin.net).",
Required: true,
},
"token": schema.StringAttribute{
Description: "Write token (bearer) for mutating operations. Defaults to the TOMSWALLAPI_WRITE_TOKEN environment variable.",
Optional: true,
Sensitive: true,
},
},
}
}
func (p *tomswallProvider) Configure(ctx context.Context, req provider.ConfigureRequest, resp *provider.ConfigureResponse) {
var config tomswallProviderModel
resp.Diagnostics.Append(req.Config.Get(ctx, &config)...)
if resp.Diagnostics.HasError() {
return
}
token := config.Token.ValueString()
if token == "" {
token = os.Getenv("TOMSWALLAPI_WRITE_TOKEN")
}
client := newAPIClient(config.Endpoint.ValueString(), token)
resp.DataSourceData = client
resp.ResourceData = client
}
func (p *tomswallProvider) Resources(_ context.Context) []func() resource.Resource {
return []func() resource.Resource{
NewZoneResource,
NewFabricResource,
NewPortGroupResource,
NewAddressGroupResource,
NewDeviceResource,
NewBindingResource,
NewRuleResource,
NewSNATResource,
NewNetmapResource,
NewNATResource,
}
}
func (p *tomswallProvider) DataSources(_ context.Context) []func() datasource.DataSource {
return nil
}