Skip to content

Commit

Permalink
Merge pull request #143 from CiscoDevNet/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
jeroenwittock committed Nov 7, 2023
2 parents f53b373 + f3576b2 commit 709bf52
Show file tree
Hide file tree
Showing 9 changed files with 78 additions and 51 deletions.
Binary file modified .DS_Store
Binary file not shown.
1 change: 1 addition & 0 deletions docs/resources/security_zone.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,6 @@ resource "fmc_security_zone" "test" {
### Read-Only

- `id` (String) The ID of this resource.
- `type` (String) The type of this resource


50 changes: 26 additions & 24 deletions examples/fmc_device_sub_interfaces/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@ terraform {
}

provider "fmc" {
fmc_username = var.fmc_username
fmc_password = var.fmc_password
fmc_host = var.fmc_host
fmc_username = var.fmc_username
fmc_password = var.fmc_password
fmc_host = var.fmc_host
fmc_insecure_skip_verify = var.fmc_insecure_skip_verify
}

data "fmc_devices" "device" {
name = "FTD1"
name = "FTD1"
}

resource "fmc_security_zone" "outside" {
name = "outside"
interface_mode = "ROUTED"
name = "outside"
interface_mode = "ROUTED"
}


Expand All @@ -30,28 +30,30 @@ resource "fmc_security_zone" "outside" {
# }

resource "fmc_device_subinterfaces" "sub" {
device_id = data.fmc_devices.device.id
ifname = "Testing12"
subinterface_id = 12345
vlan_id = 80
name = "GigabitEthernet0/1"
mode = "NONE"
mtu = 1600
enabled = true
priority = 69
security_zone_id = fmc_security_zone.outside.id
ipv4_dhcp_enabled = false
ipv4_dhcp_route_metric = 1

enable_ipv6 = true
ipv6_address = "2001:10:240:ac::a"
ipv6_prefix = "124"
ipv6_enforce_eui = false
device_id = data.fmc_devices.device.id
ifname = "Testing12"
subinterface_id = 12345
vlan_id = 80
name = "GigabitEthernet0/1"
mode = "NONE"
mtu = 1600
enabled = true
priority = 69
security_zone_id = fmc_security_zone.outside.id
ipv4_dhcp_enabled = false
ipv4_dhcp_route_metric = 1
ipv4_static_address = "192.168.0.10"
ipv4_static_netmask = 24

enable_ipv6 = true
ipv6_address = "2001:10:240:ac::a"
ipv6_prefix = "124"
ipv6_enforce_eui = false

}

output "new_subinterface_sub" {
value = fmc_device_subinterfaces.sub
value = fmc_device_subinterfaces.sub
}

# output "old_physical_interfaces" {
Expand Down
6 changes: 3 additions & 3 deletions fmc/fmc_device_physicalinterfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ type IPv6Address struct {
}

type IPv6 struct {
EnableIPv6 bool `json:"enableIPV6,omitempty"`
Addresses []IPv6Address `json:"addresses,omitempty"`
EnableIPv6 bool `json:"enableIPV6,omitempty"`
Addresses []IPv6Address `json:"addresses,omitempty"`
}

// IPv4 Structs
Expand All @@ -30,7 +30,7 @@ type IPv4DHCP struct {

type IPv4Static struct {
Address string `json:"address,omitempty"`
Netmask int `json:"netmask,omitempty"`
Netmask string `json:"netmask,omitempty"`
}

type IPv4 struct {
Expand Down
3 changes: 2 additions & 1 deletion fmc/resource_fmc_device_physicalinterfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package fmc
import (
"context"
"log"
"strconv"

"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
Expand Down Expand Up @@ -207,7 +208,7 @@ func resourcePhyInterfaceUpdate(ctx context.Context, d *schema.ResourceData, m i

var IPv4Static = IPv4Static{
Address: ipv4StaticAddress,
Netmask: ipv4StaticNetmask,
Netmask: strconv.Itoa(ipv4StaticNetmask),
}
var IPv4DHCP = IPv4DHCP{
Enable: ipv4DhcpEnabled,
Expand Down
32 changes: 16 additions & 16 deletions fmc/resource_fmc_device_subinterfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package fmc

import (
"context"
"strconv"

"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
Expand Down Expand Up @@ -73,10 +74,10 @@ func resourceFmcSubInterface() *schema.Resource {
Computed: true,
Description: "The type of this resource",
},
"mode": {
"mode": {
Type: schema.TypeString,
Optional: true,
Default: "NONE",
Default: "NONE",
Description: "The mode of this resource",
},
"name": {
Expand All @@ -93,7 +94,7 @@ func resourceFmcSubInterface() *schema.Resource {
"priority": {
Type: schema.TypeInt,
Optional: true,
Default: 0,
Default: 0,
Description: "The type of this resource",
},
"security_zone_id": {
Expand Down Expand Up @@ -193,14 +194,13 @@ func resourceFmcSubInterfaceCreate(ctx context.Context, d *schema.ResourceData,

var diags diag.Diagnostics


ipv4StaticAddress := d.Get("ipv4_static_address").(string)
ipv4StaticNetmask := d.Get("ipv4_static_netmask").(int)
ipv4DhcpEnabled := d.Get("ipv4_dhcp_enabled").(bool)
ipv4DhcpRouteMetric := d.Get("ipv4_dhcp_route_metric").(int)

securityZoneId := d.Get("security_zone_id").(string)

ipv6Address := d.Get("ipv6_address").(string)
ipv6Prefix := d.Get("ipv6_prefix").(int)
ipv6EnforceEUI := d.Get("ipv6_enforce_eui").(bool)
Expand All @@ -215,15 +215,15 @@ func resourceFmcSubInterfaceCreate(ctx context.Context, d *schema.ResourceData,
})
}

var IPv6 = IPv6{EnableIPv6:enable_ipv6 ,Addresses: IPv6Add}
var IPv6 = IPv6{EnableIPv6: enable_ipv6, Addresses: IPv6Add}

var SubInterfaceSecurityZone = PhysicalInterfaceSecurityZone{
ID: securityZoneId,
Type: "SecurityZone",
}
var IPv4Static = IPv4Static{
Address: ipv4StaticAddress,
Netmask: ipv4StaticNetmask,
Netmask: strconv.Itoa(ipv4StaticNetmask),
}
var IPv4DHCP = IPv4DHCP{
Enable: ipv4DhcpEnabled,
Expand All @@ -242,14 +242,14 @@ func resourceFmcSubInterfaceCreate(ctx context.Context, d *schema.ResourceData,
Mode: d.Get("mode").(string),
Name: d.Get("name").(string),
IPv4: IPv4,
VlanID: d.Get("vlan_id").(int),
VlanID: d.Get("vlan_id").(int),
SubInterfaceID: d.Get("subinterface_id").(int),
Enabled: d.Get("enabled").(bool),
SecurityZone: SubInterfaceSecurityZone,
MgmntOnly: d.Get("management_only").(bool),
Priority: d.Get("priority").(int),
MTU: d.Get("mtu").(int),
IPv6: IPv6,
IPv6: IPv6,
})
if err != nil {
diags = append(diags, diag.Diagnostic{
Expand All @@ -268,7 +268,7 @@ func resourceFmcSubInterfaceUpdate(ctx context.Context, d *schema.ResourceData,

var diags diag.Diagnostics
id := d.Id()
if d.HasChanges("ipv6_enforce_eui","ipv6_prefix","ipv6_address","vlan_id","management_only","ifname","name", "mode", "ipv4_static_address", "security_zone_id", "ipv4_dhcp_enabled","ipv4_dhcp_route_metric", "priority", "enabled") {
if d.HasChanges("ipv6_enforce_eui", "ipv6_prefix", "ipv6_address", "vlan_id", "management_only", "ifname", "name", "mode", "ipv4_static_address", "ipv4_static_netmask", "security_zone_id", "ipv4_dhcp_enabled", "ipv4_dhcp_route_metric", "priority", "enabled") {

ipv4StaticAddress := d.Get("ipv4_static_address").(string)
ipv4StaticNetmask := d.Get("ipv4_static_netmask").(int)
Expand All @@ -283,7 +283,7 @@ func resourceFmcSubInterfaceUpdate(ctx context.Context, d *schema.ResourceData,
}
var IPv4Static = IPv4Static{
Address: ipv4StaticAddress,
Netmask: ipv4StaticNetmask,
Netmask: strconv.Itoa(ipv4StaticNetmask),
}
var IPv4DHCP = IPv4DHCP{
Enable: ipv4DhcpEnabled,
Expand Down Expand Up @@ -311,22 +311,22 @@ func resourceFmcSubInterfaceUpdate(ctx context.Context, d *schema.ResourceData,
})
}

var IPv6 = IPv6{EnableIPv6:enable_ipv6 ,Addresses: IPv6Add}
var IPv6 = IPv6{EnableIPv6: enable_ipv6, Addresses: IPv6Add}

_, err := c.UpdateFmcSubInterface(ctx, d.Get("device_id").(string), id, &SubInterface{
ID: id,
Ifname: d.Get("ifname").(string),
Mode: d.Get("mode").(string),
Name: d.Get("name").(string),
IPv4: IPv4,
VlanID: d.Get("vlan_id").(int),
VlanID: d.Get("vlan_id").(int),
Enabled: d.Get("enabled").(bool),
SecurityZone: SubInterfaceSecurityZone,
SubInterfaceID: d.Get("subinterface_id").(int),
MgmntOnly: d.Get("management_only").(bool),
Priority: d.Get("priority").(int),
MTU: d.Get("mtu").(int),
IPv6: IPv6,
IPv6: IPv6,
})
if err != nil {
diags = append(diags, diag.Diagnostic{
Expand All @@ -348,7 +348,7 @@ func resourceFmcSubInterfaceDelete(ctx context.Context, d *schema.ResourceData,

id := d.Id()

err := c.DeleteFmcSubInterface(ctx, d.Get("device_id").(string) ,id)
err := c.DeleteFmcSubInterface(ctx, d.Get("device_id").(string), id)
if err != nil {
diags = append(diags, diag.Diagnostic{
Severity: diag.Error,
Expand Down
5 changes: 3 additions & 2 deletions fmc/resource_fmc_device_vni.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package fmc
import (
"context"
"log"
"strconv"

"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
Expand Down Expand Up @@ -223,7 +224,7 @@ func resourceVNICreate(ctx context.Context, d *schema.ResourceData, m interface{
static := statics[0].(map[string]interface{})
var IPv4Static = IPv4Static{
Address: static["address"].(string),
Netmask: static["netmask"].(int),
Netmask: strconv.Itoa(static["netmask"].(int)),
}
ipv4.Static = &IPv4Static
isStatic = true
Expand Down Expand Up @@ -324,7 +325,7 @@ func resourceVNIUpdate(ctx context.Context, d *schema.ResourceData, m interface{
static := statics[0].(map[string]interface{})
var IPv4Static = IPv4Static{
Address: static["address"].(string),
Netmask: static["netmask"].(int),
Netmask: strconv.Itoa(static["netmask"].(int)),
}
log.Printf("IPv4Static=%v", IPv4Static)
ipv4.Static = &IPv4Static
Expand Down
15 changes: 15 additions & 0 deletions fmc/resource_fmc_security_zone.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ func resourceFmcSecurityZone() *schema.Resource {
UpdateContext: resourceFmcSecurityZoneUpdate,
DeleteContext: resourceFmcSecurityZoneDelete,
Schema: map[string]*schema.Schema{
"type": {
Type: schema.TypeString,
Computed: true,
Description: "The type of this resource",
},
"name": {
Type: schema.TypeString,
Required: true,
Expand Down Expand Up @@ -100,6 +105,16 @@ func resourceFmcSecurityZoneRead(ctx context.Context, d *schema.ResourceData, m
return diags
}
}

if err := d.Set("type", item.Type); err != nil {
diags = append(diags, diag.Diagnostic{
Severity: diag.Error,
Summary: "unable to read security zone",
Detail: err.Error(),
})
return diags
}

if err := d.Set("name", item.Name); err != nil {
diags = append(diags, diag.Diagnostic{
Severity: diag.Error,
Expand Down
17 changes: 12 additions & 5 deletions fmc/resource_fmc_staticIPv4_route.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package fmc

import (
"context"
"strings"

"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
Expand Down Expand Up @@ -241,15 +242,21 @@ func resourceFmcStaticIPv4RouteRead(ctx context.Context, d *schema.ResourceData,
// Warning or errors can be collected in a slice type
var diags diag.Diagnostics

// Why this GetStatic IPv4 route but others FmcStaticIPv4
item, err := c.GetFmcStaticIPv4Route(ctx, d.Get("device_id").(string), d.Id())
if err != nil {
diags = append(diags, diag.Diagnostic{
Severity: diag.Error,
Summary: "unable to read route",
Detail: err.Error(),
})
if strings.Contains(err.Error(), "404") {
d.SetId("")
} else {
diags = append(diags, diag.Diagnostic{
Severity: diag.Error,
Summary: "unable to read route",
Detail: err.Error(),
})
}
return diags
}

if err := d.Set("interface_name", item.InterfaceName); err != nil {
diags = append(diags, diag.Diagnostic{
Severity: diag.Error,
Expand Down

0 comments on commit 709bf52

Please sign in to comment.