1+ // Copyright (c) 2017, 2021, Oracle and/or its affiliates. All rights reserved.
2+ // Licensed under the Mozilla Public License v2.0
3+ //
4+ // We will create a database_tools_connection.
5+ // The database_tools_connection will use a database_tools_private_endpoint.
6+ // The database_tools_private_endpoint will need to be in a subnet, so we will create a vcn and a subnet.
7+ // We will also create an oci_core_network_security_group to be used by the database_tools_private_endpoint.
8+
9+ variable "tenancy_ocid" {
10+ }
11+
12+ variable "user_ocid" {
13+ }
14+
15+ variable "fingerprint" {
16+ }
17+
18+ variable "private_key_path" {
19+ }
20+
21+ variable "compartment_ocid" {
22+ }
23+
24+ variable "region" {
25+ }
26+
27+ provider "oci" {
28+ region = var. region
29+ tenancy_ocid = var. tenancy_ocid
30+ user_ocid = var. user_ocid
31+ fingerprint = var. fingerprint
32+ private_key_path = var. private_key_path
33+ }
34+
35+ # ## Network resources - vcn, subnet and network security group
36+ # vcn
37+ resource "oci_core_vcn" "tf_vcn" {
38+ cidr_block = " 10.0.3.0/24"
39+ compartment_id = var. compartment_ocid
40+ display_name = " test databaseTools Vcn"
41+ }
42+
43+ # subnet
44+ resource "oci_core_subnet" "tf_subnet" {
45+ compartment_id = var. compartment_ocid
46+ vcn_id = oci_core_vcn. tf_vcn . id
47+ cidr_block = " 10.0.3.0/26"
48+ display_name = " test databaseTools Subnet"
49+ }
50+
51+ # network security group
52+ resource "oci_core_network_security_group" "test_network_security_group" {
53+ # Required
54+ compartment_id = var. compartment_ocid
55+ vcn_id = oci_core_vcn. tf_vcn . id
56+
57+ # Optional
58+ display_name = " nsg1"
59+ freeform_tags = {" Department" = " Finance" }
60+ }
61+
62+ # ## Endpoints services
63+ # Endpoints services - Data Sources
64+ data "oci_database_tools_database_tools_endpoint_services" "test_database_tools_endpoint_services" {
65+ compartment_id = var. compartment_ocid
66+ state = " ACTIVE"
67+ }
68+
69+ data "oci_database_tools_database_tools_endpoint_service" "test_database_tools_endpoint_service" {
70+ database_tools_endpoint_service_id = data. oci_database_tools_database_tools_endpoint_services . test_database_tools_endpoint_services . database_tools_endpoint_service_collection . 0 . items . 0 . id
71+ }
72+
73+ output "endpoint_service" {
74+ value = data. oci_database_tools_database_tools_endpoint_service . test_database_tools_endpoint_service
75+ }
76+
77+ # ## Private Endpoint
78+ # Private Endpoint - Resource
79+ resource "oci_database_tools_database_tools_private_endpoint" "test_database_tools_private_endpoint" {
80+ # Required
81+ compartment_id = var. compartment_ocid
82+ display_name = " My private endpoint"
83+ endpoint_service_id = data. oci_database_tools_database_tools_endpoint_service . test_database_tools_endpoint_service . id
84+ subnet_id = oci_core_subnet. tf_subnet . id
85+
86+ # Optional
87+ description = " Private Endpoint used by connection"
88+ nsg_ids = [oci_core_network_security_group . test_network_security_group . id ]
89+ private_endpoint_ip = " 10.0.3.4"
90+ }
91+
92+ # Private Endpoint - Data Sources
93+ data "oci_database_tools_database_tools_private_endpoints" "test_database_tools_private_endpoints" {
94+ compartment_id = var. compartment_ocid
95+ state = " ACTIVE"
96+ subnet_id = oci_core_subnet. tf_subnet . id
97+ display_name = oci_database_tools_database_tools_private_endpoint. test_database_tools_private_endpoint . display_name
98+ }
99+
100+ output "private_endpoints_d" {
101+ value = data. oci_database_tools_database_tools_private_endpoints . test_database_tools_private_endpoints
102+ }
103+
104+ data "oci_database_tools_database_tools_private_endpoint" "test_database_tools_private_endpoint" {
105+ database_tools_private_endpoint_id = data. oci_database_tools_database_tools_private_endpoints . test_database_tools_private_endpoints . database_tools_private_endpoint_collection . 0 . items . 0 . id
106+ }
107+
108+ output "private_endpoint_d" {
109+ value = data. oci_database_tools_database_tools_private_endpoint . test_database_tools_private_endpoint
110+ }
111+
112+ # ## Connection
113+ # Connection - Resource
114+ resource "oci_database_tools_database_tools_connection" "dbtools_connection" {
115+ compartment_id = var. compartment_ocid
116+ display_name = " My Connection"
117+ type = " ORACLE_DATABASE"
118+ connection_string = " tcps://adb-prod.us-phoenix-1.oraclecloud.com:1522/exampleb2baffff_db20210323ffff_low.adb.oraclecloud.com"
119+ 120+ user_password {
121+ value_type = " SECRETID"
122+
123+ # Here, we assume that the user password to use exists as a secret in an OCI Vault
124+ secret_id = " ocid1.vaultsecret.oc1.phx.exampleaihuofciaiazy2u5ko3uyz3sspwd6hf7oqhqmlk5xu3xdetkpffff"
125+ }
126+
127+ # Optional
128+ freeform_tags = { my-Freeform-tag1 = " value f1" , my-Freeform-tag2 = " value f2" }
129+ advanced_properties = {
130+ " oracle.jdbc.loginTimeout" : " 0"
131+ }
132+ related_resource {
133+ entity_type = " DATABASE"
134+ identifier = " ocid1.database.oc1.phx.exampletksujfufl4bhe5sqkfgn7t7lcrkkpy7km5iwzvg6ycls7r5dlffff"
135+ }
136+ private_endpoint_id = oci_database_tools_database_tools_private_endpoint. test_database_tools_private_endpoint . id
137+ }
138+
139+ output "connection_r" {
140+ value = oci_database_tools_database_tools_connection. dbtools_connection
141+ }
142+
143+ # Connection - Data Sources
144+ data "oci_database_tools_database_tools_connections" "test_database_tools_connections" {
145+ compartment_id = var. compartment_ocid
146+ display_name = oci_database_tools_database_tools_connection. dbtools_connection . display_name
147+ state = " ACTIVE"
148+ }
149+
150+ output "connections_d" {
151+ value = data. oci_database_tools_database_tools_connections . test_database_tools_connections
152+ }
0 commit comments