|
| 1 | +// Copyright (c) 2017, 2021, Oracle and/or its affiliates. All rights reserved. |
| 2 | +// Licensed under the Mozilla Public License v2.0 |
| 3 | + |
| 4 | +variable "tenancy_ocid" {} |
| 5 | +variable "user_ocid" {} |
| 6 | +variable "fingerprint" {} |
| 7 | +variable "private_key_path" {} |
| 8 | +variable "region" {} |
| 9 | +variable "compartment_ocid" {} |
| 10 | + |
| 11 | +provider "oci" { |
| 12 | + tenancy_ocid = var.tenancy_ocid |
| 13 | + user_ocid = var.user_ocid |
| 14 | + fingerprint = var.fingerprint |
| 15 | + private_key_path = var.private_key_path |
| 16 | + region = var.region |
| 17 | +} |
| 18 | + |
| 19 | +resource "oci_apigateway_deployment" "test_deployment" { |
| 20 | + compartment_id = var.compartment_ocid |
| 21 | + gateway_id = oci_apigateway_gateway.test_gateway.id |
| 22 | + path_prefix = "/" |
| 23 | + |
| 24 | + specification { |
| 25 | + # An example route making use of a request validation policy |
| 26 | + # requiring a header parameter. |
| 27 | + routes { |
| 28 | + path = "/no-tracking" |
| 29 | + methods = ["GET", "HEAD"] |
| 30 | + |
| 31 | + backend { |
| 32 | + type = "STOCK_RESPONSE_BACKEND" |
| 33 | + status = 200 |
| 34 | + body = "Hello World" |
| 35 | + } |
| 36 | + |
| 37 | + request_policies { |
| 38 | + header_validations { |
| 39 | + headers { |
| 40 | + name = "DNT" |
| 41 | + required = true |
| 42 | + } |
| 43 | + |
| 44 | + headers { |
| 45 | + name = "X-Request-ID" |
| 46 | + required = false |
| 47 | + } |
| 48 | + } |
| 49 | + } |
| 50 | + } |
| 51 | + |
| 52 | + # An example route making use of a request validation policy |
| 53 | + # requiring a query parameter. |
| 54 | + routes { |
| 55 | + path = "/authorize" |
| 56 | + methods = ["GET", "HEAD"] |
| 57 | + |
| 58 | + backend { |
| 59 | + type = "STOCK_RESPONSE_BACKEND" |
| 60 | + status = 200 |
| 61 | + body = "Hello World" |
| 62 | + } |
| 63 | + |
| 64 | + request_policies { |
| 65 | + query_parameter_validations { |
| 66 | + parameters { |
| 67 | + name = "client_id" |
| 68 | + required = true |
| 69 | + } |
| 70 | + |
| 71 | + parameters { |
| 72 | + name = "client_secret" |
| 73 | + required = false |
| 74 | + } |
| 75 | + } |
| 76 | + } |
| 77 | + } |
| 78 | + |
| 79 | + # An example route making use of a request validation policy |
| 80 | + # requiring a JSON or XML request body in permissive mode. |
| 81 | + routes { |
| 82 | + path = "/users" |
| 83 | + methods = ["POST"] |
| 84 | + |
| 85 | + backend { |
| 86 | + type = "STOCK_RESPONSE_BACKEND" |
| 87 | + status = 201 |
| 88 | + body = "User Created" |
| 89 | + } |
| 90 | + |
| 91 | + request_policies { |
| 92 | + body_validation { |
| 93 | + validation_mode = "PERMISSIVE" |
| 94 | + |
| 95 | + required = true |
| 96 | + |
| 97 | + content { |
| 98 | + media_type = "application/json" |
| 99 | + validation_type = "NONE" |
| 100 | + } |
| 101 | + |
| 102 | + content { |
| 103 | + media_type = "application/xml" |
| 104 | + validation_type = "NONE" |
| 105 | + } |
| 106 | + } |
| 107 | + } |
| 108 | + } |
| 109 | + } |
| 110 | +} |
| 111 | + |
| 112 | +resource "oci_apigateway_gateway" "test_gateway" { |
| 113 | + compartment_id = var.compartment_ocid |
| 114 | + endpoint_type = "PUBLIC" |
| 115 | + subnet_id = oci_core_subnet.regional_subnet.id |
| 116 | +} |
| 117 | + |
| 118 | +resource "oci_core_vcn" "vcn1" { |
| 119 | + cidr_block = "10.0.0.0/16" |
| 120 | + compartment_id = var.compartment_ocid |
| 121 | + display_name = "exampleVCN" |
| 122 | + dns_label = "tfexamplevcn" |
| 123 | +} |
| 124 | + |
| 125 | +resource "oci_core_subnet" "regional_subnet" { |
| 126 | + cidr_block = "10.0.1.0/24" |
| 127 | + display_name = "regionalSubnet" |
| 128 | + dns_label = "regionalsubnet" |
| 129 | + compartment_id = var.compartment_ocid |
| 130 | + vcn_id = oci_core_vcn.vcn1.id |
| 131 | +} |
0 commit comments