oracle / terraform-provider-oci

Terraform Oracle Cloud Infrastructure provider
https://www.terraform.io/docs/providers/oci/
Mozilla Public License 2.0
758 stars 680 forks source link

Cannot update route table with service gateway as destination #641

Closed kral2 closed 6 years ago

kral2 commented 6 years ago

Terraform and OCI Provider Version

- Terraform v0.11.8 - provider.oci v3.5.0

Description

Hi,

I am trying to deploy a Service Gateway and then update a route table accordingly to use it, but get an "invalid CIDR" return (http status code: 400).

The "special" oci-/region/-objectstorage CIDR used for Service Gateway when targeting object storage seems to be wrongly evaluated by the terraform provider.

Terraform file and plan/apply outputs

Here is my example code :

# 1. get available services for the region
data "oci_core_services" "R1OCI_services" {
  provider = "oci.${var.OCI_R1["short"]}"
}

# 2. create a service gateway
resource "oci_core_service_gateway" "sgw_R1VCN1" {
  provider = "oci.${var.OCI_R1["short"]}"
  compartment_id = "${var.compartment_ocid}"
  vcn_id = "${oci_core_vcn.R1VCN1.id}"
  display_name = "SGW-R1VCN1"

  services {
    service_id = "${lookup(data.oci_core_services.R1OCI_services.services[0],"id")}"
  }

  freeform_tags = {
    "Terraformed" = "yes"
  }
}

This part is working as intended : service gateway is created targeting the right service. Now I try to update a route table to actually use the Service Gateway for object storage traffic :

# 3. Update the routing table
resource "oci_core_route_table" "R1-routing-net2" {
  provider       = "oci.${var.OCI_R1["short"]}"
  compartment_id = "${var.compartment_ocid}"

  route_rules = [
    {
      // Default route to NATGW
      destination       = "${var.network_cidr["default-route"]}"
      network_entity_id = "${oci_core_nat_gateway.ngw_R1VCN1.id}"
    },
    {
      // Default route to SGW <---- this is the added section for Service Gateway usage
      destination       = "${lookup(data.oci_core_services.R1OCI_services.services[0],"cidr_block")}"
      network_entity_id = "${oci_core_service_gateway.sgw_R1VCN1.id}"
    },
  ]

  vcn_id       = "${oci_core_vcn.R1VCN1.id}"
  display_name = "${var.OCI_R1["short"]}-${var.network_name["net2"]}-routing"
  freeform_tags = {
    "Terraformed" = "yes"
  }
}

variable evaluation seems OK as shown by the terraform plan output :

An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
  ~ update in-place

Terraform will perform the following actions:

  ~ oci_core_route_table.R1-routing-net2
      route_rules.#:                            "1" => "2"
      route_rules.3321414917.destination:       "0.0.0.0/0" => "0.0.0.0/0"
      route_rules.3321414917.network_entity_id: "ocid1.natgateway.oc1.eu-frankfurt-1.aaaaaaaab6tqzezrpar2exbmqj3e2hvws6e4shysx3bthxidfmwbtjrznxva" => "ocid1.natgateway.oc1.eu-frankfurt-1.aaaaaaaab6tqzezrpar2exbmqj3xxxxx"
      route_rules.3907151364.cidr_block:        "" => <computed>
      route_rules.3907151364.destination:       "" => "oci-fra-objectstorage"
      route_rules.3907151364.destination_type:  "" => <computed>
      route_rules.3907151364.network_entity_id: "" => "ocid1.servicegateway.oc1.eu-frankfurt-1.aaaaaaaals5frw4nqnirxksff2drn6fqoftwi6pnbj4xh7umnghbbslreblq"

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

But terraform apply command fail complaining about the CIDR beeing invalid (unable to parse).

Error: Error applying plan:

1 error(s) occurred:

* oci_core_route_table.R1-routing-net2: 1 error(s) occurred:

* oci_core_route_table.R1-routing-net2: Service error:InvalidParameter. The requested CIDR oci-fra-objectstorage is invalid: unable to parse.. http status code: 400. Opc request id: be7fe13e5a52a1f11d851a5b472dc310/742D0E4C223DDD0A41F8BB5C1A3974E2/7AAC3F215A2248369199CXXXXXXX
rcohenma commented 6 years ago

You need to specify a destination_type in your route_rules to use the service gateway

destination_type defaults to CIDR_BLOCK which is incorrect for service gateway route rules

you want the SERVICE_CIDR_BLOCK destination_type

https://www.terraform.io/docs/providers/oci/r/core_route_table.html#destination_type

    {
      // Default route to NATGW
      destination       = "${var.network_cidr["default-route"]}"
      network_entity_id = "${oci_core_nat_gateway.ngw_R1VCN1.id}"
    },
    {
      // Default route to SGW <---- this is the added section for Service Gateway usage
      destination       = "${lookup(data.oci_core_services.R1OCI_services.services[0],"cidr_block")}"
      destination_type = "SERVICE_CIDR_BLOCK"
      network_entity_id = "${oci_core_service_gateway.sgw_R1VCN1.id}"
    },