cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
376
Views
0
Helpful
1
Replies

Meraki Terraform CiscoDevNet Provider Vlan Configuration

wick
Level 1
Level 1

I have the following Terraform code:

 

# Enable VLAN configurations on appliances in the Meraki Network "terraform1"
resource "meraki_appliance_vlans_settings" "terraform1" {
network_id = meraki_network.terraform1.id
vlans_enabled = true
}

# Configure VLAN interface with DHCP
resource "meraki_appliance_vlan" "VLAN_20" {
network_id = meraki_network.terraform1.id
appliance_ip = "192.168.20.1"
dhcp_boot_options_enabled = false
dhcp_handling = "Run a DHCP server"
dhcp_lease_time = "12 hours"
vlan_id = 20
name = "Data VLAN 20"
subnet = "192.168.20.0/24"
ipv6_enabled = false
mandatory_dhcp_enabled = false
}

# HOW DO I MODIFY THE EXISTING VLAN 1?
resource "meraki_appliance_vlan" "vlan_1" {
network_id = meraki_network.terraform1.id # Replace with your actual network ID
vlan_id = 1 # VLAN 1, already exists
appliance_ip = "192.168.1.1" # Existing or updated appliance IP
name = "Updated VLAN 1" # Update the VLAN name
subnet = "192.168.1.0/24" # Update subnet as needed
dhcp_handling = "Run a DHCP server" # Set the DHCP handling option
dhcp_lease_time = "12 hours" # Update DHCP lease time
ipv6_enabled = false # Enable or disable IPv6
mandatory_dhcp_enabled = false # Update this as needed
}

When I run terraform apply the Vlan 20 gets created but I get the following error:


Terraform will perform the following actions:

# meraki_appliance_vlan.vlan_1 will be created
+ resource "meraki_appliance_vlan" "vlan_1" {
+ appliance_ip = "192.168.1.1"
+ dhcp_handling = "Run a DHCP server"
+ dhcp_lease_time = "12 hours"
+ id = (known after apply)
+ ipv6_enabled = false
+ mandatory_dhcp_enabled = false
+ name = "Updated VLAN 1"
+ network_id = "<REDACTED>"
+ subnet = "192.168.1.0/24"
+ vlan_id = "1"
}

Plan: 1 to add, 0 to change, 0 to destroy.

Do you want to perform these actions?
Terraform will perform the actions described above.
Only 'yes' will be accepted to approve.

Enter a value: yes

meraki_appliance_vlan.vlan_1: Creating...

│ Error: Client Error

│ with meraki_appliance_vlan.vlan_1,
│ on resource.tf line 82, in resource "meraki_appliance_vlan" "vlan_1":
│ 82: resource "meraki_appliance_vlan" "vlan_1" {

│ Failed to configure object (POST/PUT), got error: HTTP Request failed:
│ StatusCode 400, JSON error: ["Vlan has already been taken"],
│ {"errors":["Vlan has already been taken"]}


I see that this is due to the Terraform trying to create the vlan when it has already been taken.  I want to know how to modify the Default Vlan one after I have enabled vlans for the meraki device.

1 Reply 1

mfr-6
Spotlight
Spotlight

hi @wick 

From the Terraform perspective - you want to create a new VLAN and of course this fails because it exists. If you want to modify what already exists using Terraform, first you need to import that resource (vlan 1) so Terraform will start tracking this resource. This is important, because when VLAN is created, then HTTP POST method is used most likely on a provider side, which fails because you cannot create resource that exists with POST method.

Instructions how to import the resource can be found here: https://registry.terraform.io/providers/CiscoDevNet/meraki/latest/docs/resources/appliance_vlan#import

Please let me know if further support is needed.

Mateusz Frak NetDevOps | DevNet | Automation DevNet Expert #20240068
Please mark this post as helpful if it solves your issue, to make this visible for other users, thank you!