diff --git a/docs/data-sources/access_control_policy.md b/docs/data-sources/access_control_policy.md index 17692041..6af83fcc 100644 --- a/docs/data-sources/access_control_policy.md +++ b/docs/data-sources/access_control_policy.md @@ -23,6 +23,7 @@ data "fmc_access_control_policy" "example" { ### Optional +- `domain` (String) The name of the FMC domain - `id` (String) The id of the object - `name` (String) The name of the access control policy. diff --git a/docs/data-sources/access_control_policy_category.md b/docs/data-sources/access_control_policy_category.md index 1b431ea8..2574a6f3 100644 --- a/docs/data-sources/access_control_policy_category.md +++ b/docs/data-sources/access_control_policy_category.md @@ -28,5 +28,6 @@ data "fmc_access_control_policy_category" "example" { ### Optional +- `domain` (String) The name of the FMC domain - `id` (String) The id of the object - `name` (String) The name of the category. diff --git a/docs/data-sources/host.md b/docs/data-sources/host.md index 4855137c..a90eafb0 100644 --- a/docs/data-sources/host.md +++ b/docs/data-sources/host.md @@ -23,6 +23,7 @@ data "fmc_host" "example" { ### Optional +- `domain` (String) The name of the FMC domain - `id` (String) The id of the object - `name` (String) The name of the host object. diff --git a/docs/data-sources/network.md b/docs/data-sources/network.md index b17d7abd..985822f0 100644 --- a/docs/data-sources/network.md +++ b/docs/data-sources/network.md @@ -23,6 +23,7 @@ data "fmc_network" "example" { ### Optional +- `domain` (String) The name of the FMC domain - `id` (String) The id of the object - `name` (String) The name of the network object. diff --git a/docs/resources/access_control_policy.md b/docs/resources/access_control_policy.md index e9478d5e..a66bc317 100644 --- a/docs/resources/access_control_policy.md +++ b/docs/resources/access_control_policy.md @@ -44,6 +44,7 @@ resource "fmc_access_control_policy" "example" { - `default_action_send_syslog` (Boolean) Indicating whether the device will send events to a syslog server. - Default value: `false` - `description` (String) Description +- `domain` (String) The name of the FMC domain ### Read-Only diff --git a/docs/resources/access_control_policy_category.md b/docs/resources/access_control_policy_category.md index d97443ef..af6d4bd6 100644 --- a/docs/resources/access_control_policy_category.md +++ b/docs/resources/access_control_policy_category.md @@ -27,6 +27,10 @@ resource "fmc_access_control_policy_category" "example" { - `access_control_policy_id` (String) The ID of the access control policy. - `name` (String) The name of the category. +### Optional + +- `domain` (String) The name of the FMC domain + ### Read-Only - `id` (String) The id of the object diff --git a/docs/resources/host.md b/docs/resources/host.md index 1e743963..fb4eaaf3 100644 --- a/docs/resources/host.md +++ b/docs/resources/host.md @@ -32,6 +32,7 @@ resource "fmc_host" "example" { ### Optional - `description` (String) Description +- `domain` (String) The name of the FMC domain - `overridable` (Boolean) Whether the object values can be overridden. ### Read-Only diff --git a/docs/resources/network.md b/docs/resources/network.md index 6110e727..b1eb27f2 100644 --- a/docs/resources/network.md +++ b/docs/resources/network.md @@ -32,6 +32,7 @@ resource "fmc_network" "example" { ### Optional - `description` (String) Description +- `domain` (String) The name of the FMC domain - `overridable` (Boolean) Whether the object values can be overridden. ### Read-Only diff --git a/gen/templates/data_source.go b/gen/templates/data_source.go index 38e8fa1e..703dedbb 100644 --- a/gen/templates/data_source.go +++ b/gen/templates/data_source.go @@ -73,6 +73,10 @@ func (d *{{camelCase .Name}}DataSource) Schema(ctx context.Context, req datasour Computed: true, {{- end}} }, + "domain": schema.StringAttribute{ + MarkdownDescription: "The name of the FMC domain", + Optional: true, + }, {{- range .Attributes}} {{- if not .Value}} "{{.TfName}}": schema.{{if or (eq .Type "List") (eq .Type "Set")}}{{.Type}}Nested{{else if eq .Type "StringList"}}List{{else}}{{.Type}}{{end}}Attribute{ @@ -177,6 +181,12 @@ func (d *{{camelCase .Name}}DataSource) Read(ctx context.Context, req datasource return } + // Set request domain if provided + reqMods := [](func(*fmc.Req)){} + if !config.Domain.IsNull() && config.Domain.ValueString() != "" { + reqMods = append(reqMods, fmc.DomainName(config.Domain.ValueString())) + } + tflog.Debug(ctx, fmt.Sprintf("%s: Beginning Read", config.Id.String())) {{- if .DataSourceNameQuery}} @@ -185,7 +195,7 @@ func (d *{{camelCase .Name}}DataSource) Read(ctx context.Context, req datasource limit := 1000 for page := 1; ; page++ { queryString := fmt.Sprintf("?limit=%d&offset=%d", limit, offset) - res, err := d.client.Get(config.getPath() + queryString) + res, err := d.client.Get(config.getPath() + queryString, reqMods...) if err != nil { resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Failed to retrieve objects, got error: %s", err)) return @@ -213,7 +223,7 @@ func (d *{{camelCase .Name}}DataSource) Read(ctx context.Context, req datasource } {{- end}} - res, err := d.client.Get(config.getPath() + "/" + config.Id.ValueString()) + res, err := d.client.Get(config.getPath() + "/" + config.Id.ValueString(), reqMods...) if err != nil { resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Failed to retrieve object, got error: %s", err)) return diff --git a/gen/templates/model.go b/gen/templates/model.go index 82e47911..5de24f8d 100644 --- a/gen/templates/model.go +++ b/gen/templates/model.go @@ -38,6 +38,7 @@ import ( {{- $name := camelCase .Name}} type {{camelCase .Name}} struct { Id types.String `tfsdk:"id"` + Domain types.String `tfsdk:"domain"` {{- range .Attributes}} {{- if not .Value}} {{- if or (eq .Type "List") (eq .Type "Set")}} diff --git a/gen/templates/resource.go b/gen/templates/resource.go index 308923ed..49867273 100644 --- a/gen/templates/resource.go +++ b/gen/templates/resource.go @@ -76,6 +76,10 @@ func (r *{{camelCase .Name}}Resource) Schema(ctx context.Context, req resource.S stringplanmodifier.UseStateForUnknown(), }, }, + "domain": schema.StringAttribute{ + MarkdownDescription: "The name of the FMC domain", + Optional: true, + }, {{- range .Attributes}} {{- if not .Value}} "{{.TfName}}": schema.{{if or (eq .Type "List") (eq .Type "Set")}}{{.Type}}Nested{{else if eq .Type "StringList"}}List{{else}}{{.Type}}{{end}}Attribute{ @@ -393,12 +397,18 @@ func (r *{{camelCase .Name}}Resource) Create(ctx context.Context, req resource.C return } + // Set request domain if provided + reqMods := [](func(*fmc.Req)){} + if !plan.Domain.IsNull() && plan.Domain.ValueString() != "" { + reqMods = append(reqMods, fmc.DomainName(plan.Domain.ValueString())) + } + tflog.Debug(ctx, fmt.Sprintf("%s: Beginning Create", plan.Id.ValueString())) // Create object body := plan.toBody(ctx, {{camelCase .Name}}{}) - res, err := r.client.Post(plan.getPath(), body) + res, err := r.client.Post(plan.getPath(), body, reqMods...) if err != nil { resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Failed to configure object (POST), got error: %s, %s", err, res.String())) return @@ -406,7 +416,7 @@ func (r *{{camelCase .Name}}Resource) Create(ctx context.Context, req resource.C plan.Id = types.StringValue(res.Get("id").String()) {{- if hasResourceId .Attributes}} - res, err = r.client.Get(plan.getPath() + "/" + plan.Id.ValueString()) + res, err = r.client.Get(plan.getPath() + "/" + plan.Id.ValueString(), reqMods...) if err != nil { resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Failed to retrieve object (GET), got error: %s, %s", err, res.String())) return @@ -432,9 +442,15 @@ func (r *{{camelCase .Name}}Resource) Read(ctx context.Context, req resource.Rea return } + // Set request domain if provided + reqMods := [](func(*fmc.Req)){} + if !state.Domain.IsNull() && state.Domain.ValueString() != "" { + reqMods = append(reqMods, fmc.DomainName(state.Domain.ValueString())) + } + tflog.Debug(ctx, fmt.Sprintf("%s: Beginning Read", state.Id.String())) - res, err := r.client.Get(state.getPath() + "/" + state.Id.ValueString()) + res, err := r.client.Get(state.getPath() + "/" + state.Id.ValueString(), reqMods...) if err != nil && strings.Contains(err.Error(), "StatusCode 404") { resp.State.RemoveResource(ctx) return @@ -469,17 +485,23 @@ func (r *{{camelCase .Name}}Resource) Update(ctx context.Context, req resource.U return } + // Set request domain if provided + reqMods := [](func(*fmc.Req)){} + if !plan.Domain.IsNull() && plan.Domain.ValueString() != "" { + reqMods = append(reqMods, fmc.DomainName(plan.Domain.ValueString())) + } + tflog.Debug(ctx, fmt.Sprintf("%s: Beginning Update", plan.Id.ValueString())) body := plan.toBody(ctx, state) - res, err := r.client.Put(plan.getPath() + "/" + plan.Id.ValueString(), body) + res, err := r.client.Put(plan.getPath() + "/" + plan.Id.ValueString(), body, reqMods...) if err != nil { resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Failed to configure object (PUT), got error: %s, %s", err, res.String())) return } {{- if hasResourceId .Attributes}} - res, err = r.client.Get(plan.getPath() + "/" + plan.Id.ValueString()) + res, err = r.client.Get(plan.getPath() + "/" + plan.Id.ValueString(), reqMods...) if err != nil { resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Failed to retrieve object (GET), got error: %s, %s", err, res.String())) return @@ -505,10 +527,16 @@ func (r *{{camelCase .Name}}Resource) Delete(ctx context.Context, req resource.D return } + // Set request domain if provided + reqMods := [](func(*fmc.Req)){} + if !state.Domain.IsNull() && state.Domain.ValueString() != "" { + reqMods = append(reqMods, fmc.DomainName(state.Domain.ValueString())) + } + tflog.Debug(ctx, fmt.Sprintf("%s: Beginning Delete", state.Id.ValueString())) {{- if not .NoDelete}} - res, err := r.client.Delete(state.getPath() + "/" + state.Id.ValueString()) + res, err := r.client.Delete(state.getPath() + "/" + state.Id.ValueString(), reqMods...) if err != nil { resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Failed to delete object (DELETE), got error: %s, %s", err, res.String())) return diff --git a/go.mod b/go.mod index 4bef891f..ba6c4931 100644 --- a/go.mod +++ b/go.mod @@ -9,7 +9,7 @@ require ( github.com/hashicorp/terraform-plugin-go v0.20.0 github.com/hashicorp/terraform-plugin-log v0.9.0 github.com/hashicorp/terraform-plugin-testing v1.6.0 - github.com/netascode/go-fmc v0.0.0-20240106161358-8e9cace9ca41 + github.com/netascode/go-fmc v0.0.0-20240110105445-5686e76f19f8 github.com/tidwall/gjson v1.17.0 github.com/tidwall/sjson v1.2.5 golang.org/x/tools v0.16.1 diff --git a/go.sum b/go.sum index 37a2b70d..9328176f 100644 --- a/go.sum +++ b/go.sum @@ -149,6 +149,10 @@ github.com/mitchellh/reflectwalk v1.0.2 h1:G2LzWKi524PWgd3mLHV8Y5k7s6XUvT0Gef6zx github.com/mitchellh/reflectwalk v1.0.2/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw= github.com/netascode/go-fmc v0.0.0-20240106161358-8e9cace9ca41 h1:jQpa3YToxQe475mSfkfXonuPYIP1HA2EZpjJtI3frZg= github.com/netascode/go-fmc v0.0.0-20240106161358-8e9cace9ca41/go.mod h1:+6Nd5swsQA7T+xnOVhvA44AKPT6ZRuHOoF8XfU5/ygI= +github.com/netascode/go-fmc v0.0.0-20240110092436-864815862f60 h1:nHVxwZC/OYQVuHXskfEiSl6LvDMdZBOhzFlpAxlLbqA= +github.com/netascode/go-fmc v0.0.0-20240110092436-864815862f60/go.mod h1:+6Nd5swsQA7T+xnOVhvA44AKPT6ZRuHOoF8XfU5/ygI= +github.com/netascode/go-fmc v0.0.0-20240110105445-5686e76f19f8 h1:WqGpWK2ZKWzUOGNRbEg/Ub+tkWZAEocwvpodwjp4AyM= +github.com/netascode/go-fmc v0.0.0-20240110105445-5686e76f19f8/go.mod h1:+6Nd5swsQA7T+xnOVhvA44AKPT6ZRuHOoF8XfU5/ygI= github.com/oklog/run v1.1.0 h1:GEenZ1cK0+q0+wsJew9qUg/DyD8k3JzYsZAi5gYi2mA= github.com/oklog/run v1.1.0/go.mod h1:sVPdnTZT1zYwAJeCMu2Th4T21pA3FPOQRfWjQlk7DVU= github.com/pjbgf/sha1cd v0.3.0 h1:4D5XXmUUBUl/xQ6IjCkEAbqXskkq/4O7LmGn0AqMDs4= diff --git a/internal/provider/data_source_fmc_access_control_policy.go b/internal/provider/data_source_fmc_access_control_policy.go index e00ed980..ef0ce911 100644 --- a/internal/provider/data_source_fmc_access_control_policy.go +++ b/internal/provider/data_source_fmc_access_control_policy.go @@ -67,6 +67,10 @@ func (d *AccessControlPolicyDataSource) Schema(ctx context.Context, req datasour Optional: true, Computed: true, }, + "domain": schema.StringAttribute{ + MarkdownDescription: "The name of the FMC domain", + Optional: true, + }, "name": schema.StringAttribute{ MarkdownDescription: "The name of the access control policy.", Optional: true, @@ -133,13 +137,19 @@ func (d *AccessControlPolicyDataSource) Read(ctx context.Context, req datasource return } + // Set request domain if provided + reqMods := [](func(*fmc.Req)){} + if !config.Domain.IsNull() && config.Domain.ValueString() != "" { + reqMods = append(reqMods, fmc.DomainName(config.Domain.ValueString())) + } + tflog.Debug(ctx, fmt.Sprintf("%s: Beginning Read", config.Id.String())) if config.Id.IsNull() && !config.Name.IsNull() { offset := 0 limit := 1000 for page := 1; ; page++ { queryString := fmt.Sprintf("?limit=%d&offset=%d", limit, offset) - res, err := d.client.Get(config.getPath() + queryString) + res, err := d.client.Get(config.getPath()+queryString, reqMods...) if err != nil { resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Failed to retrieve objects, got error: %s", err)) return @@ -166,7 +176,7 @@ func (d *AccessControlPolicyDataSource) Read(ctx context.Context, req datasource } } - res, err := d.client.Get(config.getPath() + "/" + config.Id.ValueString()) + res, err := d.client.Get(config.getPath()+"/"+config.Id.ValueString(), reqMods...) if err != nil { resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Failed to retrieve object, got error: %s", err)) return diff --git a/internal/provider/data_source_fmc_access_control_policy_category.go b/internal/provider/data_source_fmc_access_control_policy_category.go index e9e18f12..3363659b 100644 --- a/internal/provider/data_source_fmc_access_control_policy_category.go +++ b/internal/provider/data_source_fmc_access_control_policy_category.go @@ -67,6 +67,10 @@ func (d *AccessControlPolicyCategoryDataSource) Schema(ctx context.Context, req Optional: true, Computed: true, }, + "domain": schema.StringAttribute{ + MarkdownDescription: "The name of the FMC domain", + Optional: true, + }, "access_control_policy_id": schema.StringAttribute{ MarkdownDescription: "The ID of the access control policy.", Required: true, @@ -109,13 +113,19 @@ func (d *AccessControlPolicyCategoryDataSource) Read(ctx context.Context, req da return } + // Set request domain if provided + reqMods := [](func(*fmc.Req)){} + if !config.Domain.IsNull() && config.Domain.ValueString() != "" { + reqMods = append(reqMods, fmc.DomainName(config.Domain.ValueString())) + } + tflog.Debug(ctx, fmt.Sprintf("%s: Beginning Read", config.Id.String())) if config.Id.IsNull() && !config.Name.IsNull() { offset := 0 limit := 1000 for page := 1; ; page++ { queryString := fmt.Sprintf("?limit=%d&offset=%d", limit, offset) - res, err := d.client.Get(config.getPath() + queryString) + res, err := d.client.Get(config.getPath()+queryString, reqMods...) if err != nil { resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Failed to retrieve objects, got error: %s", err)) return @@ -142,7 +152,7 @@ func (d *AccessControlPolicyCategoryDataSource) Read(ctx context.Context, req da } } - res, err := d.client.Get(config.getPath() + "/" + config.Id.ValueString()) + res, err := d.client.Get(config.getPath()+"/"+config.Id.ValueString(), reqMods...) if err != nil { resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Failed to retrieve object, got error: %s", err)) return diff --git a/internal/provider/data_source_fmc_host.go b/internal/provider/data_source_fmc_host.go index f328ffb3..db6c6f52 100644 --- a/internal/provider/data_source_fmc_host.go +++ b/internal/provider/data_source_fmc_host.go @@ -67,6 +67,10 @@ func (d *HostDataSource) Schema(ctx context.Context, req datasource.SchemaReques Optional: true, Computed: true, }, + "domain": schema.StringAttribute{ + MarkdownDescription: "The name of the FMC domain", + Optional: true, + }, "name": schema.StringAttribute{ MarkdownDescription: "The name of the host object.", Optional: true, @@ -117,13 +121,19 @@ func (d *HostDataSource) Read(ctx context.Context, req datasource.ReadRequest, r return } + // Set request domain if provided + reqMods := [](func(*fmc.Req)){} + if !config.Domain.IsNull() && config.Domain.ValueString() != "" { + reqMods = append(reqMods, fmc.DomainName(config.Domain.ValueString())) + } + tflog.Debug(ctx, fmt.Sprintf("%s: Beginning Read", config.Id.String())) if config.Id.IsNull() && !config.Name.IsNull() { offset := 0 limit := 1000 for page := 1; ; page++ { queryString := fmt.Sprintf("?limit=%d&offset=%d", limit, offset) - res, err := d.client.Get(config.getPath() + queryString) + res, err := d.client.Get(config.getPath()+queryString, reqMods...) if err != nil { resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Failed to retrieve objects, got error: %s", err)) return @@ -150,7 +160,7 @@ func (d *HostDataSource) Read(ctx context.Context, req datasource.ReadRequest, r } } - res, err := d.client.Get(config.getPath() + "/" + config.Id.ValueString()) + res, err := d.client.Get(config.getPath()+"/"+config.Id.ValueString(), reqMods...) if err != nil { resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Failed to retrieve object, got error: %s", err)) return diff --git a/internal/provider/data_source_fmc_network.go b/internal/provider/data_source_fmc_network.go index a1b911f6..ff70cc90 100644 --- a/internal/provider/data_source_fmc_network.go +++ b/internal/provider/data_source_fmc_network.go @@ -67,6 +67,10 @@ func (d *NetworkDataSource) Schema(ctx context.Context, req datasource.SchemaReq Optional: true, Computed: true, }, + "domain": schema.StringAttribute{ + MarkdownDescription: "The name of the FMC domain", + Optional: true, + }, "name": schema.StringAttribute{ MarkdownDescription: "The name of the network object.", Optional: true, @@ -117,13 +121,19 @@ func (d *NetworkDataSource) Read(ctx context.Context, req datasource.ReadRequest return } + // Set request domain if provided + reqMods := [](func(*fmc.Req)){} + if !config.Domain.IsNull() && config.Domain.ValueString() != "" { + reqMods = append(reqMods, fmc.DomainName(config.Domain.ValueString())) + } + tflog.Debug(ctx, fmt.Sprintf("%s: Beginning Read", config.Id.String())) if config.Id.IsNull() && !config.Name.IsNull() { offset := 0 limit := 1000 for page := 1; ; page++ { queryString := fmt.Sprintf("?limit=%d&offset=%d", limit, offset) - res, err := d.client.Get(config.getPath() + queryString) + res, err := d.client.Get(config.getPath()+queryString, reqMods...) if err != nil { resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Failed to retrieve objects, got error: %s", err)) return @@ -150,7 +160,7 @@ func (d *NetworkDataSource) Read(ctx context.Context, req datasource.ReadRequest } } - res, err := d.client.Get(config.getPath() + "/" + config.Id.ValueString()) + res, err := d.client.Get(config.getPath()+"/"+config.Id.ValueString(), reqMods...) if err != nil { resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Failed to retrieve object, got error: %s", err)) return diff --git a/internal/provider/model_fmc_access_control_policy.go b/internal/provider/model_fmc_access_control_policy.go index 7b62d3e1..8e688673 100644 --- a/internal/provider/model_fmc_access_control_policy.go +++ b/internal/provider/model_fmc_access_control_policy.go @@ -33,6 +33,7 @@ import ( //template:begin types type AccessControlPolicy struct { Id types.String `tfsdk:"id"` + Domain types.String `tfsdk:"domain"` Name types.String `tfsdk:"name"` Description types.String `tfsdk:"description"` DefaultAction types.String `tfsdk:"default_action"` diff --git a/internal/provider/model_fmc_access_control_policy_category.go b/internal/provider/model_fmc_access_control_policy_category.go index 66520edf..19b16b45 100644 --- a/internal/provider/model_fmc_access_control_policy_category.go +++ b/internal/provider/model_fmc_access_control_policy_category.go @@ -34,6 +34,7 @@ import ( //template:begin types type AccessControlPolicyCategory struct { Id types.String `tfsdk:"id"` + Domain types.String `tfsdk:"domain"` AccessControlPolicyId types.String `tfsdk:"access_control_policy_id"` Name types.String `tfsdk:"name"` } diff --git a/internal/provider/model_fmc_host.go b/internal/provider/model_fmc_host.go index 45107ce6..c58575d3 100644 --- a/internal/provider/model_fmc_host.go +++ b/internal/provider/model_fmc_host.go @@ -33,6 +33,7 @@ import ( //template:begin types type Host struct { Id types.String `tfsdk:"id"` + Domain types.String `tfsdk:"domain"` Name types.String `tfsdk:"name"` Description types.String `tfsdk:"description"` Ip types.String `tfsdk:"ip"` diff --git a/internal/provider/model_fmc_network.go b/internal/provider/model_fmc_network.go index 0a06a6eb..9d8fa5ad 100644 --- a/internal/provider/model_fmc_network.go +++ b/internal/provider/model_fmc_network.go @@ -33,6 +33,7 @@ import ( //template:begin types type Network struct { Id types.String `tfsdk:"id"` + Domain types.String `tfsdk:"domain"` Name types.String `tfsdk:"name"` Description types.String `tfsdk:"description"` Prefix types.String `tfsdk:"prefix"` diff --git a/internal/provider/resource_fmc_access_control_policy.go b/internal/provider/resource_fmc_access_control_policy.go index f40b8ab3..e7cdba46 100644 --- a/internal/provider/resource_fmc_access_control_policy.go +++ b/internal/provider/resource_fmc_access_control_policy.go @@ -72,6 +72,10 @@ func (r *AccessControlPolicyResource) Schema(ctx context.Context, req resource.S stringplanmodifier.UseStateForUnknown(), }, }, + "domain": schema.StringAttribute{ + MarkdownDescription: "The name of the FMC domain", + Optional: true, + }, "name": schema.StringAttribute{ MarkdownDescription: helpers.NewAttributeDescription("The name of the access control policy.").String, Required: true, @@ -140,18 +144,24 @@ func (r *AccessControlPolicyResource) Create(ctx context.Context, req resource.C return } + // Set request domain if provided + reqMods := [](func(*fmc.Req)){} + if !plan.Domain.IsNull() && plan.Domain.ValueString() != "" { + reqMods = append(reqMods, fmc.DomainName(plan.Domain.ValueString())) + } + tflog.Debug(ctx, fmt.Sprintf("%s: Beginning Create", plan.Id.ValueString())) // Create object body := plan.toBody(ctx, AccessControlPolicy{}) - res, err := r.client.Post(plan.getPath(), body) + res, err := r.client.Post(plan.getPath(), body, reqMods...) if err != nil { resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Failed to configure object (POST), got error: %s, %s", err, res.String())) return } plan.Id = types.StringValue(res.Get("id").String()) - res, err = r.client.Get(plan.getPath() + "/" + plan.Id.ValueString()) + res, err = r.client.Get(plan.getPath()+"/"+plan.Id.ValueString(), reqMods...) if err != nil { resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Failed to retrieve object (GET), got error: %s, %s", err, res.String())) return @@ -177,9 +187,15 @@ func (r *AccessControlPolicyResource) Read(ctx context.Context, req resource.Rea return } + // Set request domain if provided + reqMods := [](func(*fmc.Req)){} + if !state.Domain.IsNull() && state.Domain.ValueString() != "" { + reqMods = append(reqMods, fmc.DomainName(state.Domain.ValueString())) + } + tflog.Debug(ctx, fmt.Sprintf("%s: Beginning Read", state.Id.String())) - res, err := r.client.Get(state.getPath() + "/" + state.Id.ValueString()) + res, err := r.client.Get(state.getPath()+"/"+state.Id.ValueString(), reqMods...) if err != nil && strings.Contains(err.Error(), "StatusCode 404") { resp.State.RemoveResource(ctx) return @@ -215,15 +231,21 @@ func (r *AccessControlPolicyResource) Update(ctx context.Context, req resource.U return } + // Set request domain if provided + reqMods := [](func(*fmc.Req)){} + if !plan.Domain.IsNull() && plan.Domain.ValueString() != "" { + reqMods = append(reqMods, fmc.DomainName(plan.Domain.ValueString())) + } + tflog.Debug(ctx, fmt.Sprintf("%s: Beginning Update", plan.Id.ValueString())) body := plan.toBody(ctx, state) - res, err := r.client.Put(plan.getPath()+"/"+plan.Id.ValueString(), body) + res, err := r.client.Put(plan.getPath()+"/"+plan.Id.ValueString(), body, reqMods...) if err != nil { resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Failed to configure object (PUT), got error: %s, %s", err, res.String())) return } - res, err = r.client.Get(plan.getPath() + "/" + plan.Id.ValueString()) + res, err = r.client.Get(plan.getPath()+"/"+plan.Id.ValueString(), reqMods...) if err != nil { resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Failed to retrieve object (GET), got error: %s, %s", err, res.String())) return @@ -249,8 +271,14 @@ func (r *AccessControlPolicyResource) Delete(ctx context.Context, req resource.D return } + // Set request domain if provided + reqMods := [](func(*fmc.Req)){} + if !state.Domain.IsNull() && state.Domain.ValueString() != "" { + reqMods = append(reqMods, fmc.DomainName(state.Domain.ValueString())) + } + tflog.Debug(ctx, fmt.Sprintf("%s: Beginning Delete", state.Id.ValueString())) - res, err := r.client.Delete(state.getPath() + "/" + state.Id.ValueString()) + res, err := r.client.Delete(state.getPath()+"/"+state.Id.ValueString(), reqMods...) if err != nil { resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Failed to delete object (DELETE), got error: %s, %s", err, res.String())) return diff --git a/internal/provider/resource_fmc_access_control_policy_category.go b/internal/provider/resource_fmc_access_control_policy_category.go index 88bc323a..fabc159c 100644 --- a/internal/provider/resource_fmc_access_control_policy_category.go +++ b/internal/provider/resource_fmc_access_control_policy_category.go @@ -69,6 +69,10 @@ func (r *AccessControlPolicyCategoryResource) Schema(ctx context.Context, req re stringplanmodifier.UseStateForUnknown(), }, }, + "domain": schema.StringAttribute{ + MarkdownDescription: "The name of the FMC domain", + Optional: true, + }, "access_control_policy_id": schema.StringAttribute{ MarkdownDescription: helpers.NewAttributeDescription("The ID of the access control policy.").String, Required: true, @@ -105,12 +109,18 @@ func (r *AccessControlPolicyCategoryResource) Create(ctx context.Context, req re return } + // Set request domain if provided + reqMods := [](func(*fmc.Req)){} + if !plan.Domain.IsNull() && plan.Domain.ValueString() != "" { + reqMods = append(reqMods, fmc.DomainName(plan.Domain.ValueString())) + } + tflog.Debug(ctx, fmt.Sprintf("%s: Beginning Create", plan.Id.ValueString())) // Create object body := plan.toBody(ctx, AccessControlPolicyCategory{}) - res, err := r.client.Post(plan.getPath(), body) + res, err := r.client.Post(plan.getPath(), body, reqMods...) if err != nil { resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Failed to configure object (POST), got error: %s, %s", err, res.String())) return @@ -136,9 +146,15 @@ func (r *AccessControlPolicyCategoryResource) Read(ctx context.Context, req reso return } + // Set request domain if provided + reqMods := [](func(*fmc.Req)){} + if !state.Domain.IsNull() && state.Domain.ValueString() != "" { + reqMods = append(reqMods, fmc.DomainName(state.Domain.ValueString())) + } + tflog.Debug(ctx, fmt.Sprintf("%s: Beginning Read", state.Id.String())) - res, err := r.client.Get(state.getPath() + "/" + state.Id.ValueString()) + res, err := r.client.Get(state.getPath()+"/"+state.Id.ValueString(), reqMods...) if err != nil && strings.Contains(err.Error(), "StatusCode 404") { resp.State.RemoveResource(ctx) return @@ -174,10 +190,16 @@ func (r *AccessControlPolicyCategoryResource) Update(ctx context.Context, req re return } + // Set request domain if provided + reqMods := [](func(*fmc.Req)){} + if !plan.Domain.IsNull() && plan.Domain.ValueString() != "" { + reqMods = append(reqMods, fmc.DomainName(plan.Domain.ValueString())) + } + tflog.Debug(ctx, fmt.Sprintf("%s: Beginning Update", plan.Id.ValueString())) body := plan.toBody(ctx, state) - res, err := r.client.Put(plan.getPath()+"/"+plan.Id.ValueString(), body) + res, err := r.client.Put(plan.getPath()+"/"+plan.Id.ValueString(), body, reqMods...) if err != nil { resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Failed to configure object (PUT), got error: %s, %s", err, res.String())) return @@ -202,8 +224,14 @@ func (r *AccessControlPolicyCategoryResource) Delete(ctx context.Context, req re return } + // Set request domain if provided + reqMods := [](func(*fmc.Req)){} + if !state.Domain.IsNull() && state.Domain.ValueString() != "" { + reqMods = append(reqMods, fmc.DomainName(state.Domain.ValueString())) + } + tflog.Debug(ctx, fmt.Sprintf("%s: Beginning Delete", state.Id.ValueString())) - res, err := r.client.Delete(state.getPath() + "/" + state.Id.ValueString()) + res, err := r.client.Delete(state.getPath()+"/"+state.Id.ValueString(), reqMods...) if err != nil { resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Failed to delete object (DELETE), got error: %s, %s", err, res.String())) return diff --git a/internal/provider/resource_fmc_host.go b/internal/provider/resource_fmc_host.go index 8caee642..56b76e28 100644 --- a/internal/provider/resource_fmc_host.go +++ b/internal/provider/resource_fmc_host.go @@ -69,6 +69,10 @@ func (r *HostResource) Schema(ctx context.Context, req resource.SchemaRequest, r stringplanmodifier.UseStateForUnknown(), }, }, + "domain": schema.StringAttribute{ + MarkdownDescription: "The name of the FMC domain", + Optional: true, + }, "name": schema.StringAttribute{ MarkdownDescription: helpers.NewAttributeDescription("The name of the host object.").String, Required: true, @@ -110,12 +114,18 @@ func (r *HostResource) Create(ctx context.Context, req resource.CreateRequest, r return } + // Set request domain if provided + reqMods := [](func(*fmc.Req)){} + if !plan.Domain.IsNull() && plan.Domain.ValueString() != "" { + reqMods = append(reqMods, fmc.DomainName(plan.Domain.ValueString())) + } + tflog.Debug(ctx, fmt.Sprintf("%s: Beginning Create", plan.Id.ValueString())) // Create object body := plan.toBody(ctx, Host{}) - res, err := r.client.Post(plan.getPath(), body) + res, err := r.client.Post(plan.getPath(), body, reqMods...) if err != nil { resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Failed to configure object (POST), got error: %s, %s", err, res.String())) return @@ -141,9 +151,15 @@ func (r *HostResource) Read(ctx context.Context, req resource.ReadRequest, resp return } + // Set request domain if provided + reqMods := [](func(*fmc.Req)){} + if !state.Domain.IsNull() && state.Domain.ValueString() != "" { + reqMods = append(reqMods, fmc.DomainName(state.Domain.ValueString())) + } + tflog.Debug(ctx, fmt.Sprintf("%s: Beginning Read", state.Id.String())) - res, err := r.client.Get(state.getPath() + "/" + state.Id.ValueString()) + res, err := r.client.Get(state.getPath()+"/"+state.Id.ValueString(), reqMods...) if err != nil && strings.Contains(err.Error(), "StatusCode 404") { resp.State.RemoveResource(ctx) return @@ -179,10 +195,16 @@ func (r *HostResource) Update(ctx context.Context, req resource.UpdateRequest, r return } + // Set request domain if provided + reqMods := [](func(*fmc.Req)){} + if !plan.Domain.IsNull() && plan.Domain.ValueString() != "" { + reqMods = append(reqMods, fmc.DomainName(plan.Domain.ValueString())) + } + tflog.Debug(ctx, fmt.Sprintf("%s: Beginning Update", plan.Id.ValueString())) body := plan.toBody(ctx, state) - res, err := r.client.Put(plan.getPath()+"/"+plan.Id.ValueString(), body) + res, err := r.client.Put(plan.getPath()+"/"+plan.Id.ValueString(), body, reqMods...) if err != nil { resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Failed to configure object (PUT), got error: %s, %s", err, res.String())) return @@ -207,8 +229,14 @@ func (r *HostResource) Delete(ctx context.Context, req resource.DeleteRequest, r return } + // Set request domain if provided + reqMods := [](func(*fmc.Req)){} + if !state.Domain.IsNull() && state.Domain.ValueString() != "" { + reqMods = append(reqMods, fmc.DomainName(state.Domain.ValueString())) + } + tflog.Debug(ctx, fmt.Sprintf("%s: Beginning Delete", state.Id.ValueString())) - res, err := r.client.Delete(state.getPath() + "/" + state.Id.ValueString()) + res, err := r.client.Delete(state.getPath()+"/"+state.Id.ValueString(), reqMods...) if err != nil { resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Failed to delete object (DELETE), got error: %s, %s", err, res.String())) return diff --git a/internal/provider/resource_fmc_network.go b/internal/provider/resource_fmc_network.go index cd3103a6..c6cc0a43 100644 --- a/internal/provider/resource_fmc_network.go +++ b/internal/provider/resource_fmc_network.go @@ -69,6 +69,10 @@ func (r *NetworkResource) Schema(ctx context.Context, req resource.SchemaRequest stringplanmodifier.UseStateForUnknown(), }, }, + "domain": schema.StringAttribute{ + MarkdownDescription: "The name of the FMC domain", + Optional: true, + }, "name": schema.StringAttribute{ MarkdownDescription: helpers.NewAttributeDescription("The name of the network object.").String, Required: true, @@ -110,12 +114,18 @@ func (r *NetworkResource) Create(ctx context.Context, req resource.CreateRequest return } + // Set request domain if provided + reqMods := [](func(*fmc.Req)){} + if !plan.Domain.IsNull() && plan.Domain.ValueString() != "" { + reqMods = append(reqMods, fmc.DomainName(plan.Domain.ValueString())) + } + tflog.Debug(ctx, fmt.Sprintf("%s: Beginning Create", plan.Id.ValueString())) // Create object body := plan.toBody(ctx, Network{}) - res, err := r.client.Post(plan.getPath(), body) + res, err := r.client.Post(plan.getPath(), body, reqMods...) if err != nil { resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Failed to configure object (POST), got error: %s, %s", err, res.String())) return @@ -141,9 +151,15 @@ func (r *NetworkResource) Read(ctx context.Context, req resource.ReadRequest, re return } + // Set request domain if provided + reqMods := [](func(*fmc.Req)){} + if !state.Domain.IsNull() && state.Domain.ValueString() != "" { + reqMods = append(reqMods, fmc.DomainName(state.Domain.ValueString())) + } + tflog.Debug(ctx, fmt.Sprintf("%s: Beginning Read", state.Id.String())) - res, err := r.client.Get(state.getPath() + "/" + state.Id.ValueString()) + res, err := r.client.Get(state.getPath()+"/"+state.Id.ValueString(), reqMods...) if err != nil && strings.Contains(err.Error(), "StatusCode 404") { resp.State.RemoveResource(ctx) return @@ -179,10 +195,16 @@ func (r *NetworkResource) Update(ctx context.Context, req resource.UpdateRequest return } + // Set request domain if provided + reqMods := [](func(*fmc.Req)){} + if !plan.Domain.IsNull() && plan.Domain.ValueString() != "" { + reqMods = append(reqMods, fmc.DomainName(plan.Domain.ValueString())) + } + tflog.Debug(ctx, fmt.Sprintf("%s: Beginning Update", plan.Id.ValueString())) body := plan.toBody(ctx, state) - res, err := r.client.Put(plan.getPath()+"/"+plan.Id.ValueString(), body) + res, err := r.client.Put(plan.getPath()+"/"+plan.Id.ValueString(), body, reqMods...) if err != nil { resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Failed to configure object (PUT), got error: %s, %s", err, res.String())) return @@ -207,8 +229,14 @@ func (r *NetworkResource) Delete(ctx context.Context, req resource.DeleteRequest return } + // Set request domain if provided + reqMods := [](func(*fmc.Req)){} + if !state.Domain.IsNull() && state.Domain.ValueString() != "" { + reqMods = append(reqMods, fmc.DomainName(state.Domain.ValueString())) + } + tflog.Debug(ctx, fmt.Sprintf("%s: Beginning Delete", state.Id.ValueString())) - res, err := r.client.Delete(state.getPath() + "/" + state.Id.ValueString()) + res, err := r.client.Delete(state.getPath()+"/"+state.Id.ValueString(), reqMods...) if err != nil { resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Failed to delete object (DELETE), got error: %s, %s", err, res.String())) return