diff --git a/README.adoc b/README.adoc new file mode 100644 index 0000000..14686ee --- /dev/null +++ b/README.adoc @@ -0,0 +1,24 @@ +// Copyright (c) 2020 Oracle and/or its affiliates. +// Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. + +# Asset Template + +Creating a module documentation + +### link:https://terraform-docs.io[Terradoc] + +Create a asciidoc file for a module +`terraform-docs asciidoc document --sort=false ./ > ./readme.adoc` + +Create a md file for a module +`terraform-docs markdown --sort=false ./ > ./readme.md` + +### link:https://asciidoctor.org[Asciidoctor] + +transfer an adoc file into docbook xml format +`asciidoc -b docbook index.adoc` + +### link:https://pandoc.org[Pandoc] + +transfer docbook xml format into md format +`iconv -t utf-8 index.xml | pandoc -f docbook -t markdown_strict --wrap=none | iconv -f utf-8 > index.md` \ No newline at end of file diff --git a/backup.tf b/backup.tf new file mode 100644 index 0000000..956227c --- /dev/null +++ b/backup.tf @@ -0,0 +1,22 @@ +# Copyright (c) 2020 Oracle and/or its affiliates. +# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. + +/* +resource "oci_database_autonomous_database_backup" "database" { + #Required + autonomous_database_id = oci_database_autonomous_database.autonomous_database.id + display_name = var.autonomous_database_backup_display_name +} + +resource "oci_database_autonomous_database" "database_from_backup" { + #Required + admin_password = random_string.autonomous_database_admin_password.result + compartment_id = var.compartment_ocid + cpu_core_count = "1" + data_storage_size_in_tbs = "1" + db_name = "adbdb2" + clone_type = "FULL" + source = "BACKUP_FROM_ID" + autonomous_database_backup_id = oci_database_autonomous_database_backup.autonomous_database_backup.id +} +*/ \ No newline at end of file diff --git a/config.tf b/config.tf new file mode 100644 index 0000000..9c799e0 --- /dev/null +++ b/config.tf @@ -0,0 +1,36 @@ +# Copyright (c) 2020 Oracle and/or its affiliates. +# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. + +// --- terraform provider --- +terraform { + required_providers { + oci = { + source = "hashicorp/oci" + } + } +} + +data "oci_identity_compartments" "database" { + compartment_id = var.tenancy.id + access_level = "ANY" + compartment_id_in_subtree = true + name = try(var.database.compartment, var.resident.name) + state = "ACTIVE" +} +data "oci_database_autonomous_databases" "database" { + compartment_id = data.oci_identity_compartments.database.compartments[0].id +} + +locals { + adb_count = var.input.create ? 1 : 0 +} + + +// Define the wait state for the data requests +resource "null_resource" "previous" {} + +// This resource will destroy (potentially immediately) after null_resource.next +resource "time_sleep" "wait" { + depends_on = [null_resource.previous] + create_duration = "2m" +} \ No newline at end of file diff --git a/input.tf b/input.tf new file mode 100644 index 0000000..9800ab1 --- /dev/null +++ b/input.tf @@ -0,0 +1,61 @@ +# Copyright (c) 2020 Oracle and/or its affiliates. +# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. + +variable "input" { + type = object({ + create = bool + }) + description = "Input for database module" +} + +variable "tenancy" { + type = object({ + id = string, + class = number, + buckets = string, + region = map(string) + }) + description = "Tenancy Configuration" +} + +variable "assets" { + type = object({ + resident = any + encryption = any + }) + description = "Retrieve asset identifier" +} + +variable "resident" { + type = object({ + owner = string, + name = string, + label = string, + stage = number, + region = map(string) + compartments = map(number), + repository = string, + groups = map(string), + policies = map(any), + notifications = map(any), + tag_namespaces = map(number), + tags = any + }) + description = "Service Configuration" +} + +variable "database" { + type = object({ + name = string, + cores = number, + storage = number, + type = string, + compartment = string, + stage = number, + display_name = string, + version = string, + password = string, + license = string + }) + description = "Database Configuration" +} \ No newline at end of file diff --git a/output.tf b/output.tf new file mode 100644 index 0000000..859ced6 --- /dev/null +++ b/output.tf @@ -0,0 +1,23 @@ +# Copyright (c) 2020 Oracle and/or its affiliates. +# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. + +output "database_ids" { + description = "A list of automous databases created by the database module" + value = { for adb in data.oci_database_autonomous_databases.database.autonomous_databases : adb.display_name => adb.id } +} + +output "service_console_url" { + value = oci_database_autonomous_database.database[0].service_console_url +} + +output "connection_strings" { + value = oci_database_autonomous_database.database[0].connection_strings[0].all_connection_strings +} + +output "connection_urls" { + value = oci_database_autonomous_database.database[0].connection_urls[0] +} + +output "password" { + value = var.assets.encryption.passwords[var.database.password] +} \ No newline at end of file diff --git a/resources.tf b/resources.tf new file mode 100644 index 0000000..50cad85 --- /dev/null +++ b/resources.tf @@ -0,0 +1,18 @@ +# Copyright (c) 2020 Oracle and/or its affiliates. +# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. + +resource "oci_database_autonomous_database" "database" { + compartment_id = data.oci_identity_compartments.database.compartments[0].id + count = local.adb_count + cpu_core_count = var.database.cores + data_storage_size_in_tbs = var.database.storage + db_name = var.database.name + admin_password = var.assets.encryption.passwords[var.database.password] + db_version = var.database.version + display_name = var.database.display_name + db_workload = var.database.type + is_free_tier = var.tenancy.class == "FREE_TIER" ? "true" : "false" + license_model = var.database.license + defined_tags = var.assets.resident.defined_tags + freeform_tags = var.assets.resident.freeform_tags +} \ No newline at end of file