browningluke / terraform-provider-opnsense

OPNsense Terraform Provider
https://registry.terraform.io/providers/browningluke/opnsense/latest
MIT License
52 stars 12 forks source link

Resource creation map[] error #50

Open aglasson opened 3 hours ago

aglasson commented 3 hours ago

I've basically tried to create every type of resource in OPNsense with Terraform and I keep getting the same error. I can read data from existing configuration in OPNsense and outputting it in Terraform no problem at all. Its basically like the API keys are read only. I've created a key on root and also created a new user, granted all access and created a key on that user to no avail. Has something perhaps changed in the OPNSense or Terraform latest version and stopping this provider from working perhaps?

This is my first time using OPNSense and this Terraform provider. I have years of experience with PFSense, I'm trying to move to OPNSense purely for the benefit of configuring my router with desired state IaC.

Unable to create vlan, got error: resource not changed. result: failed. errors: map[]

I've looked at the terraform debug logs and I seem to get no more helpful information than that. If I remove any resource elements from my .tf file and only have data and output elements, terraform outputs the data to console perfectly with no errors.

Version info: OPNsense: 24.7 Terraform: 1.9.5 Provider: 0.10.1

For example I get this error with the most basic of resource config, nothing else in my main.tf, terraform.tf has just my provider config:


resource "opnsense_route" "one_route" {
  description = "test route"
  gateway = "WAN_GW"
  network = "192.168.31.0/24"
}
browningluke commented 2 hours ago

Hey there @aglasson

Sorry it's not working for you, thanks for flagging this. It sounds like it might be an OPNsense 24.7 issue.

I can confirm everything works for me on: OPNsense: 24.1 Terraform: 1.9.5 Provider: 0.10.1

I'm installing OPNsense 24.7 on a test VM now to try and troubleshoot this. I'll get back to you.

Just checking, you created API keys like this (v) here? (under System > Access > Users)

image

I haven't played around too much with the OPNsense RBAC, but for my setup the provider works with API keys created under the default root user in the admins group, although you said you tested this.

browningluke commented 2 hours ago

Just got OPNsense 24.7 installed and it seems to work correctly for me.

Here is my setup verbatim:

TF CODE

```tf # versions.tf terraform { required_version = "~> 1.9.5" required_providers { opnsense = { source = "browningluke/opnsense" version = "~> 0.10.1" } } } ``` ```tf # main.tf provider "opnsense" { uri = "https://" api_key = "" api_secret = "" } resource "opnsense_route" "one_route" { description = "test route" gateway = "WAN-STATIC" network = "192.168.31.0/24" } ```

With this code I get the expected: Apply complete! Resources: 1 added, 0 changed, 0 destroyed.

This provider actually echos the requests it makes to/from OPNsense in the TF debug log. Try run:

TF_LOG=DEBUG terraform apply

If you spot the bug, great! If not, redact out your private values (URL / Auth Header) and post the output here and I'll take a look.