|
| 1 | +// Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved. |
| 2 | + |
| 3 | +variable "tenancy_ocid" {} |
| 4 | +variable "user_ocid" {} |
| 5 | +variable "fingerprint" {} |
| 6 | +variable "private_key_path" {} |
| 7 | +variable "region" {} |
| 8 | + |
| 9 | +variable "compartment_ocid" {} |
| 10 | +variable "ssh_public_key" {} |
| 11 | + |
| 12 | +variable "instance_shape" { |
| 13 | + default = "VM.Standard2.1" |
| 14 | +} |
| 15 | + |
| 16 | +/* |
| 17 | + * This example file shows how to configure the oci provider to target a single region. |
| 18 | + */ |
| 19 | +provider "oci" { |
| 20 | + region = "${var.region}" |
| 21 | + tenancy_ocid = "${var.tenancy_ocid}" |
| 22 | + user_ocid = "${var.user_ocid}" |
| 23 | + fingerprint = "${var.fingerprint}" |
| 24 | + private_key_path = "${var.private_key_path}" |
| 25 | +} |
| 26 | + |
| 27 | +data "oci_identity_availability_domain" "ad" { |
| 28 | + compartment_id = "${var.tenancy_ocid}" |
| 29 | + ad_number = 1 |
| 30 | +} |
| 31 | + |
| 32 | +resource "oci_core_vcn" "pic_vcn" { |
| 33 | + cidr_block = "10.1.0.0/16" |
| 34 | + compartment_id = "${var.compartment_ocid}" |
| 35 | + display_name = "PICVcn" |
| 36 | + dns_label = "PICVcn" |
| 37 | +} |
| 38 | + |
| 39 | +resource "oci_core_subnet" "pic_subnet" { |
| 40 | + availability_domain = "${data.oci_identity_availability_domain.ad.name}" |
| 41 | + cidr_block = "10.1.20.0/24" |
| 42 | + display_name = "PICSubnet" |
| 43 | + dns_label = "PICSubnet" |
| 44 | + security_list_ids = ["${oci_core_vcn.pic_vcn.default_security_list_id}"] |
| 45 | + compartment_id = "${var.compartment_ocid}" |
| 46 | + vcn_id = "${oci_core_vcn.pic_vcn.id}" |
| 47 | + route_table_id = "${oci_core_route_table.pic_rt.id}" |
| 48 | + dhcp_options_id = "${oci_core_vcn.pic_vcn.default_dhcp_options_id}" |
| 49 | +} |
| 50 | + |
| 51 | +resource "oci_core_internet_gateway" "pic_ig" { |
| 52 | + compartment_id = "${var.compartment_ocid}" |
| 53 | + display_name = "PICIG" |
| 54 | + vcn_id = "${oci_core_vcn.pic_vcn.id}" |
| 55 | +} |
| 56 | + |
| 57 | +resource "oci_core_route_table" "pic_rt" { |
| 58 | + compartment_id = "${var.compartment_ocid}" |
| 59 | + vcn_id = "${oci_core_vcn.pic_vcn.id}" |
| 60 | + display_name = "PICRT" |
| 61 | + |
| 62 | + route_rules { |
| 63 | + destination = "0.0.0.0/0" |
| 64 | + destination_type = "CIDR_BLOCK" |
| 65 | + network_entity_id = "${oci_core_internet_gateway.pic_ig.id}" |
| 66 | + } |
| 67 | +} |
| 68 | + |
| 69 | +data "oci_core_app_catalog_listings" "test_app_catalog_listings" { |
| 70 | + filter { |
| 71 | + name = "publisher_name" |
| 72 | + values = ["Oracle CCE Image Management Pipeline"] |
| 73 | + } |
| 74 | +} |
| 75 | + |
| 76 | +data "oci_core_app_catalog_listing_resource_versions" "test_app_catalog_listing_resource_versions" { |
| 77 | + #Required |
| 78 | + listing_id = "${lookup(data.oci_core_app_catalog_listings.test_app_catalog_listings.app_catalog_listings[0],"listing_id")}" |
| 79 | +} |
| 80 | + |
| 81 | +resource "oci_core_app_catalog_listing_resource_version_agreement" "test_app_catalog_listing_resource_version_agreement" { |
| 82 | + #Required |
| 83 | + listing_id = "${lookup(data.oci_core_app_catalog_listing_resource_versions.test_app_catalog_listing_resource_versions.app_catalog_listing_resource_versions[0], "listing_id")}" |
| 84 | + listing_resource_version = "${lookup(data.oci_core_app_catalog_listing_resource_versions.test_app_catalog_listing_resource_versions.app_catalog_listing_resource_versions[0], "listing_resource_version")}" |
| 85 | +} |
| 86 | + |
| 87 | +resource "oci_core_app_catalog_subscription" "test_app_catalog_subscription" { |
| 88 | + compartment_id = "${var.compartment_ocid}" |
| 89 | + eula_link = "${oci_core_app_catalog_listing_resource_version_agreement.test_app_catalog_listing_resource_version_agreement.eula_link}" |
| 90 | + listing_id = "${oci_core_app_catalog_listing_resource_version_agreement.test_app_catalog_listing_resource_version_agreement.listing_id}" |
| 91 | + listing_resource_version = "${oci_core_app_catalog_listing_resource_version_agreement.test_app_catalog_listing_resource_version_agreement.listing_resource_version}" |
| 92 | + oracle_terms_of_use_link = "${oci_core_app_catalog_listing_resource_version_agreement.test_app_catalog_listing_resource_version_agreement.oracle_terms_of_use_link}" |
| 93 | + signature = "${oci_core_app_catalog_listing_resource_version_agreement.test_app_catalog_listing_resource_version_agreement.signature}" |
| 94 | + time_retrieved = "${oci_core_app_catalog_listing_resource_version_agreement.test_app_catalog_listing_resource_version_agreement.time_retrieved}" |
| 95 | + |
| 96 | + timeouts { |
| 97 | + create = "20m" |
| 98 | + } |
| 99 | +} |
| 100 | + |
| 101 | +resource "oci_core_instance" "pic_instance" { |
| 102 | + availability_domain = "${data.oci_identity_availability_domain.ad.name}" |
| 103 | + compartment_id = "${var.compartment_ocid}" |
| 104 | + display_name = "pic_instance" |
| 105 | + shape = "${var.instance_shape}" |
| 106 | + |
| 107 | + create_vnic_details { |
| 108 | + subnet_id = "${oci_core_subnet.pic_subnet.id}" |
| 109 | + display_name = "picprimaryvnic" |
| 110 | + assign_public_ip = true |
| 111 | + hostname_label = "PICInstance" |
| 112 | + } |
| 113 | + |
| 114 | + source_details { |
| 115 | + source_type = "image" |
| 116 | + source_id = "${lookup(data.oci_core_app_catalog_subscriptions.test_app_catalog_subscriptions.app_catalog_subscriptions[0], "listing_resource_id")}" |
| 117 | + } |
| 118 | + |
| 119 | + metadata = { |
| 120 | + ssh_authorized_keys = "${var.ssh_public_key}" |
| 121 | + } |
| 122 | + |
| 123 | + timeouts { |
| 124 | + create = "60m" |
| 125 | + } |
| 126 | +} |
| 127 | + |
| 128 | +data "oci_core_app_catalog_subscriptions" "test_app_catalog_subscriptions" { |
| 129 | + #Required |
| 130 | + compartment_id = "${var.compartment_ocid}" |
| 131 | + |
| 132 | + #Optional |
| 133 | + listing_id = "${oci_core_app_catalog_subscription.test_app_catalog_subscription.listing_id}" |
| 134 | + |
| 135 | + filter { |
| 136 | + name = "listing_resource_version" |
| 137 | + values = ["${oci_core_app_catalog_subscription.test_app_catalog_subscription.listing_resource_version}"] |
| 138 | + } |
| 139 | +} |
| 140 | + |
| 141 | +output "subscriptions" { |
| 142 | + value = ["${data.oci_core_app_catalog_subscriptions.test_app_catalog_subscriptions.app_catalog_subscriptions}"] |
| 143 | +} |
0 commit comments