Skip to content

Commit 1c5f1e4

Browse files
jvizcarrdlapp
andcommitted
Initial Commit
Co-Authored-By: David Lapp <david.lapp@oracle.com>
0 parents  commit 1c5f1e4

20 files changed

+1500
-0
lines changed

.gitignore

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Local .terraform directories
2+
**/.terraform/*
3+
4+
# .tfstate files
5+
*.tfstate
6+
*.tfstate.*
7+
*.zip*
8+
*.tfvars
9+
10+
# Local .terraform lock files
11+
*.lock.*
12+
13+
# General
14+
.DS_Store
15+
.AppleDouble
16+
.LSOverride
17+
18+
# Icon must end with two \r
19+
Icon
20+
21+
# Thumbnails
22+
._*
23+
24+
# Files that might appear in the root of a volume
25+
.DocumentRevisions-V100
26+
.fseventsd
27+
.Spotlight-V100
28+
.TemporaryItems
29+
.Trashes
30+
.VolumeIcon.icns
31+
.com.apple.timemachine.donotpresent
32+
33+
# Directories potentially created on remote AFP share
34+
.AppleDB
35+
.AppleDesktop
36+
Network Trash Folder
37+
Temporary Items
38+
.apdisk

LICENSE

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
Copyright (c) 2022 Oracle and/or its affiliates. All rights reserved.
2+
3+
The Universal Permissive License (UPL), Version 1.0
4+
5+
Subject to the condition set forth below, permission is hereby granted to any person obtaining a copy of this
6+
software, associated documentation and/or data (collectively the "Software"), free of charge and under any and
7+
all copyright rights in the Software, and any and all patent rights owned or freely licensable by each licensor
8+
hereunder covering either (i) the unmodified Software as contributed to or provided by such licensor, or
9+
(ii) the Larger Works (as defined below), to deal in both
10+
11+
(a) the Software, and
12+
(b) any piece of software and/or hardware listed in the lrgrwrks.txt file if one is included with the Software
13+
(each a “Larger Work” to which the Software is contributed by such licensors),
14+
15+
without restriction, including without limitation the rights to copy, create derivative works of, display,
16+
perform, and distribute the Software and make, use, sell, offer for sale, import, export, have made, and have
17+
sold the Software and the Larger Work(s), and to sublicense the foregoing rights on either these or other terms.
18+
19+
This license is subject to the following condition:
20+
The above copyright notice and either this complete permission notice or at a minimum a reference to the UPL must
21+
be included in all copies or substantial portions of the Software.
22+
23+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
24+
THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
25+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
26+
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
27+
IN THE SOFTWARE.

README.md

Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
# Oracle Cloud Spatial Platform on ADW
2+
3+
# [![Deploy to Oracle Cloud][magic_button]][magic_sgtech_stack]
4+
5+
This architecture uses Oracle Autonomous Data Warehouse where the location components of business data are managed with a native spatial data type to enable location-based insights. The architecture also includes Oracle Spatial Studio and Oracle Application Express (APEX) for low code spatial data preparation, analysis, visualization, and application development.
6+
7+
The repository contains the [Terraform][tf] code to create a [Resource Manager][orm] stack, that creates all the required resources and configures the application on the created resources.
8+
9+
## Prerequisites
10+
11+
- Permission to `manage` the following types of resources in your Oracle Cloud Infrastructure tenancy: `autonomous-database-family`, `instance-family`, `virtual-network-family`, `dynamic-groups`, `policies`, `orm-family`.
12+
- Permission to `use` the following types of resources in your Oracle Cloud Infrastructure tenancy: `secret-family`, `keys` and `tag-namespaces`.
13+
- [Secret][secret](s) to use for Spatial Studio's database and application admin passwords
14+
- SSH key pair
15+
- Quota to create the following resources: 1 [ADW][adb] database instance, 1 [Compute instance][inst], 1 [VCN][vcn] and its required network artifacts ([Subnet][net], [IGW][igw], [Route Table][rt] and [NSG][nsg]), 1 [Dynamic Group][groups] and 1 [Policy][policies].
16+
If you don't have the required permissions and quota, contact your tenancy administrator. See [Policy Reference][policy], [Service Limits][limits], [Compartment Quotas][quota].
17+
18+
#### **Generating an SSH Key Pair on UNIX or UNIX-Like Systems Using ssh-keygen**
19+
20+
- Run the ssh-keygen command.
21+
22+
`ssh-keygen -b 2048 -t rsa`
23+
24+
- The command prompts you to enter the path to the file in which you want to save the key. A default path and file name are suggested in parentheses. For example: /home/user_name/.ssh/id_rsa. To accept the default path and file name, press Enter. Otherwise, enter the required path and file name, and then press Enter.
25+
- The command prompts you for a passphrase. Enter a passphrase, or press ENTER if you don't want to havea passphrase.
26+
Note that the passphrase isn't displayed when you type it in. Remember the passphrase. If you forget the passphrase, you can't recover it. When prompted, enter the passphrase again to confirm it.
27+
- The command generates an SSH key pair consisting of a public key and a private key, and saves them in the specified path. The file name of the public key is created automatically by appending .pub to the name of the private key file. For example, if the file name of the SSH private key is id_rsa, then the file name of the public key would be id_rsa.pub.
28+
Make a note of the path where you've saved the SSH key pair.
29+
When you create instances, you must provide the SSH public key. When you log in to an instance, you must specify the corresponding SSH private key and enter the passphrase when prompted.
30+
31+
## Components
32+
33+
| Component | Description |
34+
|---------------------------|---------------------------|
35+
| Autonomous Data Warehouse | Platform for management and analysis of business/spatial data |
36+
| Compute Instance | VM host for Spatial Studio |
37+
| Virtual Cloud Network | The virtual network used by the application |
38+
| Public Subnet | The subnet that houses the compute instance. This subnet allows public IP addresses and are exposed to the internet through the InternetGateway |
39+
| Internet Gateway | Enables the compute instance to be reachable from the internet |
40+
| Route Tables | The public subnet route rules direct traffic to use the Internet Gateway |
41+
| Network Security Group | Contains the security rules to enable HTTPS and SSH traffic from anywhere to the compute instance |
42+
| Dynamic Group | A component group containing the instance |
43+
| Identity Policy | Statements to grant the Dynamic Group access to the Tenancy's Secrets decoding capabilities and the ability to download the ADW wallet |
44+
45+
# Deployment Instructions
46+
47+
## Deploy Using Oracle Resource Manager
48+
49+
1. Click [![Deploy to Oracle Cloud][magic_button]][magic_sgtech_stack].
50+
If you aren't already signed in, when prompted, enter the tenancy and user credentials.
51+
52+
2. Review and accept the terms and conditions.
53+
3. Select the region where you want to deploy the stack.
54+
4. Follow the on-screen prompts and instructions to create the stack.
55+
5. After creating the stack, click **Terraform Actions**, and select **Plan**.
56+
6. Wait for the job to be completed, and review the plan. To make any changes, return to the Stack Details page, click **Edit Stack**, and make the required changes. Then, run the **Plan** action again.
57+
7. If no further changes are necessary, return to the Stack Details page, click **Terraform Actions**, and select **Apply**.
58+
59+
## Local Development
60+
61+
1. Perform pre-deployment setup described [here][oci-prereqs].
62+
63+
2. Clone the Module with the following commands to make a local copy fo the repo:
64+
65+
git clone https://github.com/oracle-quickstart/oci-arch-spatial.git
66+
cd oci-arch-spatial/
67+
ls
68+
69+
Note, the instructions below are to build a `.zip` file from your local copy for use in ORM. If you do not want to use ORM and instead deploy with the terraform CLI, then you need to rename `provider.tf.cli -> provider.tf`. This is because authentication works slightly differently in ORM vs the CLI. This file is ignored by the build process below. Make sure you have terraform v1.0+ cli installed and accessible from your terminal.
70+
71+
3. In order to `build` the zip file with the latest changes you made to this code, you can simply go to `build-orm` folder and use terraform to generate a new zip file:
72+
73+
On the first run you are required to initialize the terraform modules used by the template with `terraform init` command:
74+
75+
```bash
76+
$ terraform init
77+
```
78+
79+
4. Once terraform is initialized, run `terraform apply` to generate ORM zip file:
80+
81+
```bash
82+
$ terraform apply
83+
data.archive_file.generate_zip: Refreshing state...
84+
Apply complete! Resources: 0 added, 0 changed, 0 destroyed.
85+
```
86+
87+
This command will package the content of `terraform` folder into a zip and will store it in the `build-orm\dist` folder. You can check the content of the file by running `unzip -l dist/orm.zip`:
88+
89+
```bash
90+
$ unzip -l dist/orm.zip
91+
92+
Archive: orm.zip
93+
Length Date Time Name
94+
--------- ---------- ----- ----
95+
2651 01-01-2049 00:00 compute.tf
96+
866 01-01-2049 00:00 database.tf
97+
493 01-01-2049 00:00 datasources.tf
98+
1653 01-01-2049 00:00 image_subscription.tf
99+
2425 01-01-2049 00:00 locals.tf
100+
2272 01-01-2049 00:00 network.tf
101+
2032 01-01-2049 00:00 nsg.tf
102+
860 01-01-2049 00:00 oci_images.tf
103+
1860 01-01-2049 00:00 outputs.tf
104+
2222 01-01-2049 00:00 policies.tf
105+
15599 01-01-2049 00:00 schema.yaml
106+
405 01-01-2049 00:00 scripts/bootstrap.sh
107+
3961 01-01-2049 00:00 variables.tf
108+
178 01-01-2049 00:00 versions.tf
109+
--------- -------
110+
37477 14 files
111+
```
112+
113+
5. [Login](https://cloud.oracle.com/resourcemanager/stacks/create) to Oracle Cloud Infrastructure to import the stack
114+
> `Home > Developer Services > Resource Manager > Stacks > Create Stack`
115+
6. Upload the `orm.zip` and provide a name and description for the stack
116+
7. Configure the Stack. The UI will present the variables to the user dynamically, based on their selections.
117+
8. Click Next and Review the configuration.
118+
9. Click Create button to confirm and create your ORM Stack.
119+
10. On Stack Details page, you can now run `Terraform` commands to manage your infrastructure. You typically start with a plan then run apply to create and make changes to the infrastructure. More details below:
120+
121+
| TERRAFORM ACTIONS | DESCRIPTION |
122+
|----------------------------|-----------------------------------------------------------------------|
123+
|Plan | `terraform plan` is used to create an execution plan. This command is a convenient way to check the execution plan prior to make any changes to the infrastructure resources.|
124+
|Apply | `terraform apply` is used to apply the changes required to reach the desired state of the configuration described by the template.|
125+
|Destroy | `terraform destroy` is used to destroy the Terraform-managed infrastructure.|
126+
127+
## Additional Information
128+
129+
* For instructions on changing the default HTTPS port and creating additional users, see /u01/Oracle_Spatial_Studio/README.txt
130+
131+
* To configure your HTTPS certificate, see [Loading keys and certificates in Jetty](https://www.eclipse.org/jetty/documentation/jetty-9/index.html#loading-keys-and-certificates). Note: this requires understanding of TSL/SSL certificate configuration
132+
133+
* The Server is registered as a Linux startup service using custom start/stop scripts and will be automatically started when the instance is booted.
134+
135+
* Use the following system commands to gracefully start, stop or restart it.
136+
```
137+
sudo systemctl start spatialstudio
138+
sudo systemctl stop spatialstudio
139+
sudo systemctl restart spatialstudio
140+
```
141+
142+
143+
[magic_button]: https://oci-resourcemanager-plugin.plugins.oci.oraclecloud.com/latest/deploy-to-oracle-cloud.svg
144+
[magic_sgtech_stack]: https://cloud.oracle.com/resourcemanager/stacks/create?zipUrl=https://github.com/oracle-quickstart/oci-arch-spatial/releases/latest/download/spatial-stack-latest.zip
145+
[policy]: https://docs.cloud.oracle.com/en-us/iaas/Content/Identity/Reference/policyreference.htm
146+
[policies]: https://docs.oracle.com/en-us/iaas/Content/Identity/Tasks/managingpolicies.htm
147+
[limits]: https://docs.cloud.oracle.com/en-us/iaas/Content/General/Concepts/servicelimits.htm
148+
[quota]: https://docs.cloud.oracle.com/iaas/Content/General/Concepts/resourcequotas.htm
149+
[oci]: https://cloud.oracle.com/en_US/cloud-infrastructure
150+
[orm]: https://docs.cloud.oracle.com/iaas/Content/ResourceManager/Concepts/resourcemanager.htm
151+
[tf]: https://www.terraform.io
152+
[net]: https://docs.cloud.oracle.com/iaas/Content/Network/Concepts/overview.htm
153+
[vcn]: https://docs.cloud.oracle.com/iaas/Content/Network/Tasks/managingVCNs.htm
154+
[lb]: https://docs.cloud.oracle.com/iaas/Content/Balance/Concepts/balanceoverview.htm
155+
[igw]: https://docs.cloud.oracle.com/iaas/Content/Network/Tasks/managingIGs.htm
156+
[natgw]: https://docs.cloud.oracle.com/iaas/Content/Network/Tasks/NATgateway.htm
157+
[svcgw]: https://docs.cloud.oracle.com/iaas/Content/Network/Tasks/servicegateway.htm
158+
[rt]: https://docs.cloud.oracle.com/iaas/Content/Network/Tasks/managingroutetables.htm
159+
[seclist]: https://docs.cloud.oracle.com/iaas/Content/Network/Concepts/securitylists.htm
160+
[adb]: https://docs.cloud.oracle.com/iaas/Content/Database/Concepts/adboverview.htm
161+
[inst]: https://docs.cloud.oracle.com/iaas/Content/Compute/Concepts/computeoverview.htm
162+
[kms]: https://docs.cloud.oracle.com/en-us/iaas/Content/KeyManagement/Concepts/keyoverview.htm
163+
[nsg]: https://docs.oracle.com/en-us/iaas/Content/Network/Concepts/networksecuritygroups.htm
164+
[secret]: https://docs.oracle.com/en-us/iaas/Content/KeyManagement/Tasks/managingsecrets.htm
165+
[groups]: https://docs.oracle.com/en-us/iaas/Content/Identity/Tasks/managingdynamicgroups.htm
166+
[oci-prereqs]: https://github.com/oracle/oci-quickstart-prerequisites

build-orm/install.tf

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
variable "save_to" {
2+
default = ""
3+
}
4+
5+
data "archive_file" "generate_zip" {
6+
type = "zip"
7+
output_path = (var.save_to != "" ? "${var.save_to}/orm.zip" : "${path.module}/dist/orm.zip")
8+
source_dir = "../terraform"
9+
excludes = ["packer",".terraform.lock.hcl","terraform.tfstate", "terraform.tfvars.template", "terraform.tfvars", "provider.tf", ".terraform", "build-orm", "images", "README.md", "terraform.", "terraform.tfstate.backup", "test", "simple", ".git", "README", ".github", ".gitignore", ".DS_Store", "LICENSE","diagram",]
10+
}

terraform/compute.tf

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
resource "oci_core_instance" "simple-vm" {
2+
availability_domain = local.availability_domain
3+
compartment_id = var.compartment_ocid
4+
display_name = "${var.service_name}-instance-${random_string.deploy_id.result}"
5+
shape = var.instance_shape.instanceShape
6+
7+
dynamic "shape_config" {
8+
for_each = local.is_flex_shape
9+
content {
10+
ocpus = var.instance_shape.ocpus
11+
memory_in_gbs = var.instance_shape.memory
12+
}
13+
}
14+
15+
create_vnic_details {
16+
subnet_id = local.use_existing_network ? var.subnet_id : oci_core_subnet.simple_subnet[0].id
17+
display_name = "primaryvnic"
18+
assign_public_ip = local.is_public_subnet
19+
hostname_label = "${var.service_name}-instance-${random_string.deploy_id.result}"
20+
skip_source_dest_check = false
21+
nsg_ids = [oci_core_network_security_group.simple_nsg.id]
22+
}
23+
24+
source_details {
25+
source_type = "image"
26+
#use a marketplace image or custom image:
27+
source_id = local.compute_image_id
28+
}
29+
30+
lifecycle {
31+
ignore_changes = [
32+
source_details[0].source_id
33+
]
34+
}
35+
36+
metadata = {
37+
ssh_authorized_keys = var.ssh_public_key
38+
user_data = base64encode(file("./scripts/bootstrap.sh"))
39+
40+
server_ssl_port = var.console_ssl_port
41+
use_secrets = var.use_secrets
42+
admin_user = var.admin_user
43+
admin_pwd = local.admin_pwd
44+
#This random string will be used for the new database's admin and sgtech users
45+
dba_password=random_string.autonomous_database_admin_password.result
46+
47+
#required, to distinguish if DB is new or an existing one will be used, set this to false and pass an empty adb_id
48+
#to skip database metadata repository configuration
49+
create_adb_user = true
50+
#optional, if passed a datasource will be configured for studio
51+
adb_id = oci_database_autonomous_database.sgtech_autonomous_database.id
52+
#optional, default is low
53+
adb_level = var.adb_level
54+
#optional
55+
adb_wallet_path = "/u01/oracle/wallet"
56+
#required when using existing adb, optional for new one and will be defaulted to sgtech
57+
adb_user = var.adb_user
58+
#required when using existing adb, optional for new one and will be defaulted to admin's
59+
adb_user_password_ocid = var.adb_user_password_ocid
60+
#required to set max/min connections for studio
61+
is_free_adb = local.is_free_adb
62+
63+
debug_enabled=true
64+
65+
}
66+
67+
freeform_tags = var.defined_tag.freeformTags
68+
defined_tags = var.defined_tag.definedTags
69+
70+
depends_on = [
71+
oci_identity_policy.spatial_policy
72+
]
73+
}

terraform/database.tf

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# creates an ADW database
2+
## ADW Instance
3+
resource "oci_database_autonomous_database" "sgtech_autonomous_database" {
4+
admin_password = random_string.autonomous_database_admin_password.result
5+
compartment_id = var.adb_compartment_ocid
6+
cpu_core_count = local.adb_cpu_core_count
7+
data_storage_size_in_tbs = local.adb_data_storage_size_in_tbs
8+
db_name = "${var.adb_name}${random_string.deploy_id.result}"
9+
db_version = var.adb_version
10+
db_workload = "DW"
11+
display_name = "${var.adb_name}-${random_string.deploy_id.result}"
12+
license_model = local.adb_license_model
13+
is_free_tier = local.is_free_adb
14+
is_auto_scaling_enabled = local.adb_enable_auto_scale
15+
16+
freeform_tags = var.defined_tag.freeformTags
17+
defined_tags = var.defined_tag.definedTags
18+
}

terraform/datasources.tf

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
data "oci_identity_availability_domain" "ad" {
2+
compartment_id = var.tenancy_ocid
3+
ad_number = 1
4+
}
5+
6+
# Randoms
7+
resource "random_string" "deploy_id" {
8+
length = 4
9+
special = false
10+
}
11+
12+
resource "random_string" "autonomous_database_admin_password" {
13+
length = 16
14+
special = true
15+
min_upper = 3
16+
min_lower = 3
17+
min_numeric = 3
18+
min_special = 3
19+
override_special = "{}#^*<>[]%~"
20+
}

0 commit comments

Comments
 (0)