Skip to content

Commit 709bf52

Browse files
Merge pull request #143 from CiscoDevNet/develop
Develop
2 parents f53b373 + f3576b2 commit 709bf52

9 files changed

+78
-51
lines changed

.DS_Store

0 Bytes
Binary file not shown.

docs/resources/security_zone.md

+1
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,6 @@ resource "fmc_security_zone" "test" {
3939
### Read-Only
4040

4141
- `id` (String) The ID of this resource.
42+
- `type` (String) The type of this resource
4243

4344

examples/fmc_device_sub_interfaces/main.tf

+26-24
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,19 @@ terraform {
88
}
99

1010
provider "fmc" {
11-
fmc_username = var.fmc_username
12-
fmc_password = var.fmc_password
13-
fmc_host = var.fmc_host
11+
fmc_username = var.fmc_username
12+
fmc_password = var.fmc_password
13+
fmc_host = var.fmc_host
1414
fmc_insecure_skip_verify = var.fmc_insecure_skip_verify
1515
}
1616

1717
data "fmc_devices" "device" {
18-
name = "FTD1"
18+
name = "FTD1"
1919
}
2020

2121
resource "fmc_security_zone" "outside" {
22-
name = "outside"
23-
interface_mode = "ROUTED"
22+
name = "outside"
23+
interface_mode = "ROUTED"
2424
}
2525

2626

@@ -30,28 +30,30 @@ resource "fmc_security_zone" "outside" {
3030
# }
3131

3232
resource "fmc_device_subinterfaces" "sub" {
33-
device_id = data.fmc_devices.device.id
34-
ifname = "Testing12"
35-
subinterface_id = 12345
36-
vlan_id = 80
37-
name = "GigabitEthernet0/1"
38-
mode = "NONE"
39-
mtu = 1600
40-
enabled = true
41-
priority = 69
42-
security_zone_id = fmc_security_zone.outside.id
43-
ipv4_dhcp_enabled = false
44-
ipv4_dhcp_route_metric = 1
45-
46-
enable_ipv6 = true
47-
ipv6_address = "2001:10:240:ac::a"
48-
ipv6_prefix = "124"
49-
ipv6_enforce_eui = false
33+
device_id = data.fmc_devices.device.id
34+
ifname = "Testing12"
35+
subinterface_id = 12345
36+
vlan_id = 80
37+
name = "GigabitEthernet0/1"
38+
mode = "NONE"
39+
mtu = 1600
40+
enabled = true
41+
priority = 69
42+
security_zone_id = fmc_security_zone.outside.id
43+
ipv4_dhcp_enabled = false
44+
ipv4_dhcp_route_metric = 1
45+
ipv4_static_address = "192.168.0.10"
46+
ipv4_static_netmask = 24
47+
48+
enable_ipv6 = true
49+
ipv6_address = "2001:10:240:ac::a"
50+
ipv6_prefix = "124"
51+
ipv6_enforce_eui = false
5052

5153
}
5254

5355
output "new_subinterface_sub" {
54-
value = fmc_device_subinterfaces.sub
56+
value = fmc_device_subinterfaces.sub
5557
}
5658

5759
# output "old_physical_interfaces" {

fmc/fmc_device_physicalinterfaces.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ type IPv6Address struct {
1717
}
1818

1919
type IPv6 struct {
20-
EnableIPv6 bool `json:"enableIPV6,omitempty"`
21-
Addresses []IPv6Address `json:"addresses,omitempty"`
20+
EnableIPv6 bool `json:"enableIPV6,omitempty"`
21+
Addresses []IPv6Address `json:"addresses,omitempty"`
2222
}
2323

2424
// IPv4 Structs
@@ -30,7 +30,7 @@ type IPv4DHCP struct {
3030

3131
type IPv4Static struct {
3232
Address string `json:"address,omitempty"`
33-
Netmask int `json:"netmask,omitempty"`
33+
Netmask string `json:"netmask,omitempty"`
3434
}
3535

3636
type IPv4 struct {

fmc/resource_fmc_device_physicalinterfaces.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package fmc
33
import (
44
"context"
55
"log"
6+
"strconv"
67

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

208209
var IPv4Static = IPv4Static{
209210
Address: ipv4StaticAddress,
210-
Netmask: ipv4StaticNetmask,
211+
Netmask: strconv.Itoa(ipv4StaticNetmask),
211212
}
212213
var IPv4DHCP = IPv4DHCP{
213214
Enable: ipv4DhcpEnabled,

fmc/resource_fmc_device_subinterfaces.go

+16-16
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package fmc
22

33
import (
44
"context"
5+
"strconv"
56

67
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
78
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
@@ -73,10 +74,10 @@ func resourceFmcSubInterface() *schema.Resource {
7374
Computed: true,
7475
Description: "The type of this resource",
7576
},
76-
"mode": {
77+
"mode": {
7778
Type: schema.TypeString,
7879
Optional: true,
79-
Default: "NONE",
80+
Default: "NONE",
8081
Description: "The mode of this resource",
8182
},
8283
"name": {
@@ -93,7 +94,7 @@ func resourceFmcSubInterface() *schema.Resource {
9394
"priority": {
9495
Type: schema.TypeInt,
9596
Optional: true,
96-
Default: 0,
97+
Default: 0,
9798
Description: "The type of this resource",
9899
},
99100
"security_zone_id": {
@@ -193,14 +194,13 @@ func resourceFmcSubInterfaceCreate(ctx context.Context, d *schema.ResourceData,
193194

194195
var diags diag.Diagnostics
195196

196-
197197
ipv4StaticAddress := d.Get("ipv4_static_address").(string)
198198
ipv4StaticNetmask := d.Get("ipv4_static_netmask").(int)
199199
ipv4DhcpEnabled := d.Get("ipv4_dhcp_enabled").(bool)
200200
ipv4DhcpRouteMetric := d.Get("ipv4_dhcp_route_metric").(int)
201-
201+
202202
securityZoneId := d.Get("security_zone_id").(string)
203-
203+
204204
ipv6Address := d.Get("ipv6_address").(string)
205205
ipv6Prefix := d.Get("ipv6_prefix").(int)
206206
ipv6EnforceEUI := d.Get("ipv6_enforce_eui").(bool)
@@ -215,15 +215,15 @@ func resourceFmcSubInterfaceCreate(ctx context.Context, d *schema.ResourceData,
215215
})
216216
}
217217

218-
var IPv6 = IPv6{EnableIPv6:enable_ipv6 ,Addresses: IPv6Add}
218+
var IPv6 = IPv6{EnableIPv6: enable_ipv6, Addresses: IPv6Add}
219219

220220
var SubInterfaceSecurityZone = PhysicalInterfaceSecurityZone{
221221
ID: securityZoneId,
222222
Type: "SecurityZone",
223223
}
224224
var IPv4Static = IPv4Static{
225225
Address: ipv4StaticAddress,
226-
Netmask: ipv4StaticNetmask,
226+
Netmask: strconv.Itoa(ipv4StaticNetmask),
227227
}
228228
var IPv4DHCP = IPv4DHCP{
229229
Enable: ipv4DhcpEnabled,
@@ -242,14 +242,14 @@ func resourceFmcSubInterfaceCreate(ctx context.Context, d *schema.ResourceData,
242242
Mode: d.Get("mode").(string),
243243
Name: d.Get("name").(string),
244244
IPv4: IPv4,
245-
VlanID: d.Get("vlan_id").(int),
245+
VlanID: d.Get("vlan_id").(int),
246246
SubInterfaceID: d.Get("subinterface_id").(int),
247247
Enabled: d.Get("enabled").(bool),
248248
SecurityZone: SubInterfaceSecurityZone,
249249
MgmntOnly: d.Get("management_only").(bool),
250250
Priority: d.Get("priority").(int),
251251
MTU: d.Get("mtu").(int),
252-
IPv6: IPv6,
252+
IPv6: IPv6,
253253
})
254254
if err != nil {
255255
diags = append(diags, diag.Diagnostic{
@@ -268,7 +268,7 @@ func resourceFmcSubInterfaceUpdate(ctx context.Context, d *schema.ResourceData,
268268

269269
var diags diag.Diagnostics
270270
id := d.Id()
271-
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") {
271+
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") {
272272

273273
ipv4StaticAddress := d.Get("ipv4_static_address").(string)
274274
ipv4StaticNetmask := d.Get("ipv4_static_netmask").(int)
@@ -283,7 +283,7 @@ func resourceFmcSubInterfaceUpdate(ctx context.Context, d *schema.ResourceData,
283283
}
284284
var IPv4Static = IPv4Static{
285285
Address: ipv4StaticAddress,
286-
Netmask: ipv4StaticNetmask,
286+
Netmask: strconv.Itoa(ipv4StaticNetmask),
287287
}
288288
var IPv4DHCP = IPv4DHCP{
289289
Enable: ipv4DhcpEnabled,
@@ -311,22 +311,22 @@ func resourceFmcSubInterfaceUpdate(ctx context.Context, d *schema.ResourceData,
311311
})
312312
}
313313

314-
var IPv6 = IPv6{EnableIPv6:enable_ipv6 ,Addresses: IPv6Add}
314+
var IPv6 = IPv6{EnableIPv6: enable_ipv6, Addresses: IPv6Add}
315315

316316
_, err := c.UpdateFmcSubInterface(ctx, d.Get("device_id").(string), id, &SubInterface{
317317
ID: id,
318318
Ifname: d.Get("ifname").(string),
319319
Mode: d.Get("mode").(string),
320320
Name: d.Get("name").(string),
321321
IPv4: IPv4,
322-
VlanID: d.Get("vlan_id").(int),
322+
VlanID: d.Get("vlan_id").(int),
323323
Enabled: d.Get("enabled").(bool),
324324
SecurityZone: SubInterfaceSecurityZone,
325325
SubInterfaceID: d.Get("subinterface_id").(int),
326326
MgmntOnly: d.Get("management_only").(bool),
327327
Priority: d.Get("priority").(int),
328328
MTU: d.Get("mtu").(int),
329-
IPv6: IPv6,
329+
IPv6: IPv6,
330330
})
331331
if err != nil {
332332
diags = append(diags, diag.Diagnostic{
@@ -348,7 +348,7 @@ func resourceFmcSubInterfaceDelete(ctx context.Context, d *schema.ResourceData,
348348

349349
id := d.Id()
350350

351-
err := c.DeleteFmcSubInterface(ctx, d.Get("device_id").(string) ,id)
351+
err := c.DeleteFmcSubInterface(ctx, d.Get("device_id").(string), id)
352352
if err != nil {
353353
diags = append(diags, diag.Diagnostic{
354354
Severity: diag.Error,

fmc/resource_fmc_device_vni.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package fmc
33
import (
44
"context"
55
"log"
6+
"strconv"
67

78
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
89
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
@@ -223,7 +224,7 @@ func resourceVNICreate(ctx context.Context, d *schema.ResourceData, m interface{
223224
static := statics[0].(map[string]interface{})
224225
var IPv4Static = IPv4Static{
225226
Address: static["address"].(string),
226-
Netmask: static["netmask"].(int),
227+
Netmask: strconv.Itoa(static["netmask"].(int)),
227228
}
228229
ipv4.Static = &IPv4Static
229230
isStatic = true
@@ -324,7 +325,7 @@ func resourceVNIUpdate(ctx context.Context, d *schema.ResourceData, m interface{
324325
static := statics[0].(map[string]interface{})
325326
var IPv4Static = IPv4Static{
326327
Address: static["address"].(string),
327-
Netmask: static["netmask"].(int),
328+
Netmask: strconv.Itoa(static["netmask"].(int)),
328329
}
329330
log.Printf("IPv4Static=%v", IPv4Static)
330331
ipv4.Static = &IPv4Static

fmc/resource_fmc_security_zone.go

+15
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ func resourceFmcSecurityZone() *schema.Resource {
2828
UpdateContext: resourceFmcSecurityZoneUpdate,
2929
DeleteContext: resourceFmcSecurityZoneDelete,
3030
Schema: map[string]*schema.Schema{
31+
"type": {
32+
Type: schema.TypeString,
33+
Computed: true,
34+
Description: "The type of this resource",
35+
},
3136
"name": {
3237
Type: schema.TypeString,
3338
Required: true,
@@ -100,6 +105,16 @@ func resourceFmcSecurityZoneRead(ctx context.Context, d *schema.ResourceData, m
100105
return diags
101106
}
102107
}
108+
109+
if err := d.Set("type", item.Type); err != nil {
110+
diags = append(diags, diag.Diagnostic{
111+
Severity: diag.Error,
112+
Summary: "unable to read security zone",
113+
Detail: err.Error(),
114+
})
115+
return diags
116+
}
117+
103118
if err := d.Set("name", item.Name); err != nil {
104119
diags = append(diags, diag.Diagnostic{
105120
Severity: diag.Error,

fmc/resource_fmc_staticIPv4_route.go

+12-5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package fmc
22

33
import (
44
"context"
5+
"strings"
56

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

245+
// Why this GetStatic IPv4 route but others FmcStaticIPv4
244246
item, err := c.GetFmcStaticIPv4Route(ctx, d.Get("device_id").(string), d.Id())
245247
if err != nil {
246-
diags = append(diags, diag.Diagnostic{
247-
Severity: diag.Error,
248-
Summary: "unable to read route",
249-
Detail: err.Error(),
250-
})
248+
if strings.Contains(err.Error(), "404") {
249+
d.SetId("")
250+
} else {
251+
diags = append(diags, diag.Diagnostic{
252+
Severity: diag.Error,
253+
Summary: "unable to read route",
254+
Detail: err.Error(),
255+
})
256+
}
251257
return diags
252258
}
259+
253260
if err := d.Set("interface_name", item.InterfaceName); err != nil {
254261
diags = append(diags, diag.Diagnostic{
255262
Severity: diag.Error,

0 commit comments

Comments
 (0)