Skip to content

Commit b1d63d8

Browse files
committed
Add support for VCN Transit Routing to Oracle Services via Service Gateways
1 parent 1b930cb commit b1d63d8

File tree

8 files changed

+51
-8
lines changed

8 files changed

+51
-8
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
- Support for moving `identity_compartment` resource tree across compartments
1616
- Support for moving `dns_zone` and `dns_steering_policy` resources across compartments
1717
- Support in autonomous database and object data sources for encoding downloaded binary content as base64. This works around behavior in Terraform v0.12 that could cause binary content to be corrupted if written directly to state.
18+
- Support for VCN Transit Routing to Oracle Services via Service Gateways
1819

1920
### Fixed
2021
- Address panics caused by invalid type assertions in object map conversion. This could potentially affect attributes

examples/networking/service_gateway/service_gateway.tf

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ resource "oci_core_service_gateway" "test_service_gateway" {
4848
vcn_id = "${oci_core_vcn.test_vcn.id}"
4949

5050
#Optional
51-
display_name = "testServiceGateway"
51+
display_name = "testServiceGateway"
52+
route_table_id = "${oci_core_route_table.test_route_table_transit_routing.id}"
5253
}
5354

5455
data "oci_core_service_gateways" "test_service_gateways" {
@@ -76,6 +77,12 @@ resource "oci_core_route_table" "test_route_table" {
7677
}
7778
}
7879

80+
resource "oci_core_route_table" "test_route_table_transit_routing" {
81+
compartment_id = "${var.compartment_ocid}"
82+
vcn_id = "${oci_core_vcn.test_vcn.id}"
83+
display_name = "testRouteTableTransitRouting"
84+
}
85+
7986
resource "oci_core_security_list" "test_security_list" {
8087
compartment_id = "${var.compartment_ocid}"
8188
vcn_id = "${oci_core_vcn.test_vcn.id}"

oci/core_service_gateway_resource.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,11 @@ func CoreServiceGatewayResource() *schema.Resource {
7676
Computed: true,
7777
Elem: schema.TypeString,
7878
},
79+
"route_table_id": {
80+
Type: schema.TypeString,
81+
Optional: true,
82+
Computed: true,
83+
},
7984

8085
// Computed
8186
"block_traffic": {
@@ -187,6 +192,11 @@ func (s *CoreServiceGatewayResourceCrud) Create() error {
187192
request.FreeformTags = objectMapToStringMap(freeformTags.(map[string]interface{}))
188193
}
189194

195+
if routeTableId, ok := s.D.GetOkExists("route_table_id"); ok {
196+
tmp := routeTableId.(string)
197+
request.RouteTableId = &tmp
198+
}
199+
190200
request.Services = []oci_core.ServiceIdRequestDetails{}
191201
if services, ok := s.D.GetOkExists("services"); ok {
192202
set := services.(*schema.Set)
@@ -271,6 +281,11 @@ func (s *CoreServiceGatewayResourceCrud) Update() error {
271281
request.FreeformTags = objectMapToStringMap(freeformTags.(map[string]interface{}))
272282
}
273283

284+
if routeTableId, ok := s.D.GetOkExists("route_table_id"); ok {
285+
tmp := routeTableId.(string)
286+
request.RouteTableId = &tmp
287+
}
288+
274289
tmp := s.D.Id()
275290
request.ServiceGatewayId = &tmp
276291

@@ -333,6 +348,10 @@ func (s *CoreServiceGatewayResourceCrud) SetData() error {
333348

334349
s.D.Set("freeform_tags", s.Res.FreeformTags)
335350

351+
if s.Res.RouteTableId != nil {
352+
s.D.Set("route_table_id", *s.Res.RouteTableId)
353+
}
354+
336355
services := []interface{}{}
337356
for _, item := range s.Res.Services {
338357
services = append(services, ServiceIdResponseDetailsToMap(item))

oci/core_service_gateway_test.go

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,17 @@ var (
3636
"services": RepresentationGroup{Required, serviceGatewayServicesRepresentation},
3737
"vcn_id": Representation{repType: Required, create: `${oci_core_vcn.test_vcn.id}`},
3838
"defined_tags": Representation{repType: Optional, create: `${map("${oci_identity_tag_namespace.tag-namespace1.name}.${oci_identity_tag.tag1.name}", "value")}`, update: `${map("${oci_identity_tag_namespace.tag-namespace1.name}.${oci_identity_tag.tag1.name}", "updatedValue")}`},
39-
"display_name": Representation{repType: Optional, create: `displayName`, update: `displayName2`},
39+
"display_name": Representation{repType: Optional, create: `MyServiceGateway`, update: `displayName2`},
4040
"freeform_tags": Representation{repType: Optional, create: map[string]string{"Department": "Finance"}, update: map[string]string{"Department": "Accounting"}},
41+
"route_table_id": Representation{repType: Optional, create: `${oci_core_vcn.test_vcn.default_route_table_id}`, update: `${oci_core_route_table.test_route_table.id}`},
4142
}
4243
serviceGatewayServicesRepresentation = map[string]interface{}{
4344
"service_id": Representation{repType: Required, create: `${lookup(data.oci_core_services.test_services.services[0], "id")}`},
4445
}
4546

46-
ServiceGatewayResourceDependencies = VcnRequiredOnlyResource + VcnResourceDependencies + `
47-
data "oci_core_services" "test_services" {
48-
}
49-
`
47+
ServiceGatewayResourceDependencies = DefinedTagsDependencies + VcnResourceConfig + ObjectStorageCoreService +
48+
generateResourceFromRepresentationMap("oci_core_route_table", "test_route_table", Required, Create, routeTableRepresentation) +
49+
generateResourceFromRepresentationMap("oci_core_internet_gateway", "test_network_entity", Required, Create, internetGatewayRepresentation)
5050
)
5151

5252
func TestCoreServiceGatewayResource_basic(t *testing.T) {
@@ -106,9 +106,10 @@ func TestCoreServiceGatewayResource_basic(t *testing.T) {
106106
resource.TestCheckResourceAttrSet(resourceName, "block_traffic"),
107107
resource.TestCheckResourceAttr(resourceName, "compartment_id", compartmentId),
108108
resource.TestCheckResourceAttr(resourceName, "defined_tags.%", "1"),
109-
resource.TestCheckResourceAttr(resourceName, "display_name", "displayName"),
109+
resource.TestCheckResourceAttr(resourceName, "display_name", "MyServiceGateway"),
110110
resource.TestCheckResourceAttr(resourceName, "freeform_tags.%", "1"),
111111
resource.TestCheckResourceAttrSet(resourceName, "id"),
112+
resource.TestCheckResourceAttrSet(resourceName, "route_table_id"),
112113
resource.TestCheckResourceAttr(resourceName, "services.#", "1"),
113114
CheckResourceSetContainsElementWithProperties(resourceName, "services", map[string]string{},
114115
[]string{
@@ -136,9 +137,10 @@ func TestCoreServiceGatewayResource_basic(t *testing.T) {
136137
resource.TestCheckResourceAttrSet(resourceName, "block_traffic"),
137138
resource.TestCheckResourceAttr(resourceName, "compartment_id", compartmentIdU),
138139
resource.TestCheckResourceAttr(resourceName, "defined_tags.%", "1"),
139-
resource.TestCheckResourceAttr(resourceName, "display_name", "displayName"),
140+
resource.TestCheckResourceAttr(resourceName, "display_name", "MyServiceGateway"),
140141
resource.TestCheckResourceAttr(resourceName, "freeform_tags.%", "1"),
141142
resource.TestCheckResourceAttrSet(resourceName, "id"),
143+
resource.TestCheckResourceAttrSet(resourceName, "route_table_id"),
142144
resource.TestCheckResourceAttr(resourceName, "services.#", "1"),
143145
CheckResourceSetContainsElementWithProperties(resourceName, "services", map[string]string{},
144146
[]string{
@@ -169,6 +171,7 @@ func TestCoreServiceGatewayResource_basic(t *testing.T) {
169171
resource.TestCheckResourceAttr(resourceName, "display_name", "displayName2"),
170172
resource.TestCheckResourceAttr(resourceName, "freeform_tags.%", "1"),
171173
resource.TestCheckResourceAttrSet(resourceName, "id"),
174+
resource.TestCheckResourceAttrSet(resourceName, "route_table_id"),
172175
resource.TestCheckResourceAttr(resourceName, "services.#", "1"),
173176
CheckResourceSetContainsElementWithProperties(resourceName, "services", map[string]string{},
174177
[]string{

oci/core_service_gateways_data_source.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,10 @@ func (s *CoreServiceGatewaysDataSourceCrud) SetData() error {
124124
serviceGateway["id"] = *r.Id
125125
}
126126

127+
if r.RouteTableId != nil {
128+
serviceGateway["route_table_id"] = *r.RouteTableId
129+
}
130+
127131
services := []interface{}{}
128132
for _, item := range r.Services {
129133
services = append(services, ServiceIdResponseDetailsToMap(item))

oci/oci_dependency_graph.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ func initDependencyGraph() {
7272
DependencyGraph["providerService"] = append(DependencyGraph["providerService"], "CoreVirtualCircuit")
7373
DependencyGraph["routeTable"] = append(DependencyGraph["routeTable"], "CoreDrgAttachment")
7474
DependencyGraph["routeTable"] = append(DependencyGraph["routeTable"], "CoreLocalPeeringGateway")
75+
DependencyGraph["routeTable"] = append(DependencyGraph["routeTable"], "CoreServiceGateway")
7576
DependencyGraph["routeTable"] = append(DependencyGraph["routeTable"], "CoreSubnet")
7677
DependencyGraph["steeringPolicy"] = append(DependencyGraph["steeringPolicy"], "DnsSteeringPolicyAttachment")
7778
DependencyGraph["subnet"] = append(DependencyGraph["subnet"], "CoreInstance")

website/docs/d/core_service_gateways.html.markdown

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ The following attributes are exported:
5151
* `display_name` - A user-friendly name. Does not have to be unique, and it's changeable. Avoid entering confidential information.
5252
* `freeform_tags` - Free-form tags for this resource. Each tag is a simple key-value pair with no predefined name, type, or namespace. For more information, see [Resource Tags](https://docs.cloud.oracle.com/iaas/Content/General/Concepts/resourcetags.htm). Example: `{"Department": "Finance"}`
5353
* `id` - The [OCID](https://docs.cloud.oracle.com/iaas/Content/General/Concepts/identifiers.htm) of the service gateway.
54+
* `route_table_id` - The OCID of the route table the service gateway is using. For information about why you would associate a route table with a service gateway, see [Transit Routing: Private Access to Oracle Services Network](https://docs.cloud.oracle.com/iaas/Content/Network/Tasks/transitroutingoracleservices.htm).
5455
* `services` - List of the [Service](https://docs.cloud.oracle.com/iaas/api/#/en/iaas/20160918/Service/) objects enabled for this service gateway. The list can be empty. You can enable a particular `Service` by using [AttachServiceId](https://docs.cloud.oracle.com/iaas/api/#/en/iaas/20160918/ServiceGateway/AttachServiceId) or [UpdateServiceGateway](https://docs.cloud.oracle.com/iaas/api/#/en/iaas/20160918/ServiceGateway/UpdateServiceGateway).
5556
* `service_id` - The [OCID](https://docs.cloud.oracle.com/iaas/Content/General/Concepts/identifiers.htm) of the service.
5657
* `service_name` - The name of the service.

website/docs/r/core_service_gateway.html.markdown

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ resource "oci_core_service_gateway" "test_service_gateway" {
3636
defined_tags = {"Operations.CostCenter"= "42"}
3737
display_name = "${var.service_gateway_display_name}"
3838
freeform_tags = {"Department"= "Finance"}
39+
route_table_id = "${oci_core_route_table.test_route_table.id}"
3940
}
4041
```
4142

@@ -47,6 +48,11 @@ The following arguments are supported:
4748
* `defined_tags` - (Optional) (Updatable) Defined tags for this resource. Each key is predefined and scoped to a namespace. For more information, see [Resource Tags](https://docs.cloud.oracle.com/iaas/Content/General/Concepts/resourcetags.htm). Example: `{"Operations.CostCenter": "42"}`
4849
* `display_name` - (Optional) (Updatable) A user-friendly name. Does not have to be unique, and it's changeable. Avoid entering confidential information.
4950
* `freeform_tags` - (Optional) (Updatable) Free-form tags for this resource. Each tag is a simple key-value pair with no predefined name, type, or namespace. For more information, see [Resource Tags](https://docs.cloud.oracle.com/iaas/Content/General/Concepts/resourcetags.htm). Example: `{"Department": "Finance"}`
51+
* `route_table_id` - (Optional) (Updatable) The OCID of the route table the service gateway will use.
52+
53+
If you don't specify a route table here, the service gateway is created without an associated route table. The Networking service does NOT automatically associate the attached VCN's default route table with the service gateway.
54+
55+
For information about why you would associate a route table with a service gateway, see [Transit Routing: Private Access to Oracle Services Network](https://docs.cloud.oracle.com/iaas/Content/Network/Tasks/transitroutingoracleservices.htm).
5056
* `services` - (Required) (Updatable) List of the OCIDs of the [Service](https://docs.cloud.oracle.com/iaas/api/#/en/iaas/20160918/Service/) objects to enable for the service gateway. This list can be empty if you don't want to enable any `Service` objects when you create the gateway. You can enable a `Service` object later by using either [AttachServiceId](https://docs.cloud.oracle.com/iaas/api/#/en/iaas/20160918/ServiceGateway/AttachServiceId) or [UpdateServiceGateway](https://docs.cloud.oracle.com/iaas/api/#/en/iaas/20160918/ServiceGateway/UpdateServiceGateway).
5157

5258
For each enabled `Service`, make sure there's a route rule with the `Service` object's `cidrBlock` as the rule's destination and the service gateway as the rule's target. See [Route Table](https://docs.cloud.oracle.com/iaas/api/#/en/iaas/20160918/RouteTable/).
@@ -67,6 +73,7 @@ The following attributes are exported:
6773
* `display_name` - A user-friendly name. Does not have to be unique, and it's changeable. Avoid entering confidential information.
6874
* `freeform_tags` - Free-form tags for this resource. Each tag is a simple key-value pair with no predefined name, type, or namespace. For more information, see [Resource Tags](https://docs.cloud.oracle.com/iaas/Content/General/Concepts/resourcetags.htm). Example: `{"Department": "Finance"}`
6975
* `id` - The [OCID](https://docs.cloud.oracle.com/iaas/Content/General/Concepts/identifiers.htm) of the service gateway.
76+
* `route_table_id` - The OCID of the route table the service gateway is using. For information about why you would associate a route table with a service gateway, see [Transit Routing: Private Access to Oracle Services Network](https://docs.cloud.oracle.com/iaas/Content/Network/Tasks/transitroutingoracleservices.htm).
7077
* `services` - List of the [Service](https://docs.cloud.oracle.com/iaas/api/#/en/iaas/20160918/Service/) objects enabled for this service gateway. The list can be empty. You can enable a particular `Service` by using [AttachServiceId](https://docs.cloud.oracle.com/iaas/api/#/en/iaas/20160918/ServiceGateway/AttachServiceId) or [UpdateServiceGateway](https://docs.cloud.oracle.com/iaas/api/#/en/iaas/20160918/ServiceGateway/UpdateServiceGateway).
7178
* `service_id` - The [OCID](https://docs.cloud.oracle.com/iaas/Content/General/Concepts/identifiers.htm) of the service.
7279
* `service_name` - The name of the service.

0 commit comments

Comments
 (0)