Skip to content

Commit

Permalink
chore: Adding default prefixfiletr for TGW connection resource depe… (I…
Browse files Browse the repository at this point in the history
…BM-Cloud#5406)

* chore: Adding  default prefixfiletr for TGW connection resource  dependency:none

* chore: Adding  default prefixfiletr for TGW connection resource  dependency:none

---------

Co-authored-by: sushmitha M <sushmitham@sushmithas-MacBook-Pro.local>
  • Loading branch information
2 people authored and deepaksibm committed Jun 14, 2024
1 parent 856d1c3 commit 7e0738b
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 4 deletions.
10 changes: 10 additions & 0 deletions ibm/service/transitgateway/data_source_ibm_tg_gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,13 @@ func DataSourceIBMTransitGateway() *schema.Resource {
Type: schema.TypeString,
Computed: true,
},
tgDefaultPrefixFilter: {
Type: schema.TypeString,
Optional: true,
Computed: true,
ValidateFunc: validate.InvokeValidator("ibm_tg_connection_prefix_filter", tgAction),
Description: "Whether to permit or deny the prefix filter",
},
},
},
},
Expand Down Expand Up @@ -284,6 +291,9 @@ func dataSourceIBMTransitGatewayConnectionsRead(d *schema.ResourceData, meta int
if instance.Status != nil {
tgConn[tgConnectionStatus] = *instance.Status
}
if instance.PrefixFiltersDefault != nil {
tgConn[tgDefaultPrefixFilter] = *instance.PrefixFiltersDefault
}

connections = append(connections, tgConn)

Expand Down
21 changes: 21 additions & 0 deletions ibm/service/transitgateway/resource_ibm_tg_gateway_connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ const (
tgRemoteTunnelIp = "remote_tunnel_ip"
tgZone = "zone"
tgMtu = "mtu"
tgDefaultPrefixFilter = "default_prefix_filter"
)

func ResourceIBMTransitGatewayConnection() *schema.Resource {
Expand Down Expand Up @@ -177,6 +178,13 @@ func ResourceIBMTransitGatewayConnection() *schema.Resource {
Computed: true,
Description: "The crn of the transit gateway",
},
tgDefaultPrefixFilter: {
Type: schema.TypeString,
Optional: true,
Computed: true,
ValidateFunc: validate.InvokeValidator("ibm_tg_connection_prefix_filter", tgAction),
Description: "Whether to permit or deny the prefix filter",
},
},
}
}
Expand Down Expand Up @@ -265,6 +273,10 @@ func resourceIBMTransitGatewayConnectionCreate(d *schema.ResourceData, meta inte
zoneIdentity.Name = &zoneName
createTransitGatewayConnectionOptions.SetZone(zoneIdentity)
}
if _, ok := d.GetOk(tgDefaultPrefixFilter); ok {
default_prefix_filter := d.Get(tgDefaultPrefixFilter).(string)
createTransitGatewayConnectionOptions.SetPrefixFiltersDefault(default_prefix_filter)
}

tgConnections, response, err := client.CreateTransitGatewayConnection(createTransitGatewayConnectionOptions)
if err != nil {
Expand Down Expand Up @@ -374,6 +386,9 @@ func resourceIBMTransitGatewayConnectionRead(d *schema.ResourceData, meta interf
if instance.RequestStatus != nil {
d.Set(tgRequestStatus, *instance.RequestStatus)
}
if instance.PrefixFiltersDefault != nil {
d.Set(tgDefaultPrefixFilter, *instance.PrefixFiltersDefault)
}
d.Set(tgConnectionId, *instance.ID)
d.Set(tgGatewayId, gatewayId)
getTransitGatewayOptions := &transitgatewayapisv1.GetTransitGatewayOptions{
Expand Down Expand Up @@ -421,6 +436,12 @@ func resourceIBMTransitGatewayConnectionUpdate(d *schema.ResourceData, meta inte
updateTransitGatewayConnectionOptions.Name = &name
}
}
if d.HasChange(tgDefaultPrefixFilter) {
if d.Get(tgDefaultPrefixFilter) != nil {
prefixFilter := d.Get(tgDefaultPrefixFilter).(string)
updateTransitGatewayConnectionOptions.PrefixFiltersDefault = &prefixFilter
}
}

_, response, err = client.UpdateTransitGatewayConnection(updateTransitGatewayConnectionOptions)
if err != nil {
Expand Down
6 changes: 3 additions & 3 deletions website/docs/d/tg_gateway.html.markdown
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
---

subcategory: "Transit Gateway"
layout: "ibm"
Expand All @@ -13,19 +12,19 @@ Retrieve information of an existing IBM Cloud infrastructure transit gateway as

## Example usage

---
```terraform
resource "ibm_tg_gateway" "new_tg_gw" {
name = "transit-gateway-1"
location = "us-south"
global = true
resource_group = "30951d2dff914dafb26455a88c0c0092"
}
data "ibm_tg_gateway" "ds_tggateway" {
name = ibm_tg_gateway.new_tg_gw.name
}
```

---
## Argument reference
Review the argument references that you can specify for your data source.

Expand Down Expand Up @@ -63,3 +62,4 @@ In addition to the argument reference list, you can access the following attribu
- `zone` - (String) The location of the GRE tunnel. This field only applies to network type `gre_tunnel` and `unbound_gre_tunnel` connections.
- `status` - (String) The gateway status.
- `updated_at` - (Timestamp) The date and time resource is last updated.
- `default_prefix_filter` - (String) Whether to permit or deny the prefix filter, Default value for action for prefix filters
7 changes: 6 additions & 1 deletion website/docs/r/tg_connection.html.markdown
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
---

subcategory: "Transit Gateway"
layout: "ibm"
page_title: "IBM : tg_connection"
Expand All @@ -11,6 +11,7 @@ Create, update and delete for the transit gateway's connection resource. For mor

## Example usage

---
```terraform
resource "ibm_tg_connection" "test_ibm_tg_connection" {
gateway = ibm_tg_gateway.test_tg_gateway.id
Expand All @@ -20,6 +21,7 @@ resource "ibm_tg_connection" "test_ibm_tg_connection" {
}
```
---

## Argument reference
Review the argument references that you can specify for your resource.
Expand All @@ -37,6 +39,7 @@ Review the argument references that you can specify for your resource.
- `remote_gateway_ip` - (Optional, Forces new resource, String) - The remote gateway IP address. This field only applies to network type `gre_tunnel` and `unbound_gre_tunnel` connections.
- `remote_tunnel_ip` - (Optional, Forces new resource, String) - The remote tunnel IP address. This field only applies to network type `gre_tunnel` and `unbound_gre_tunnel` connections.
- `zone` - (Optional, Forces new resource, String) - The location of the GRE tunnel. This field only applies to network type `gre_tunnel` and `unbound_gre_tunnel` connections.
- `default_prefix_filter` - (Optinal, String) Whether to permit or deny the prefix filter

## Attribute reference

Expand All @@ -60,7 +63,9 @@ The `ibm_tg_connection` resource can be imported by using transit gateway ID and

**Example**

---
```
$ terraform import ibm_tg_connection.example 5ffda12064634723b079acdb018ef308/cea6651a-bd0a-4438-9f8a-a0770bbf3ebb
```
---

0 comments on commit 7e0738b

Please sign in to comment.