Skip to content

Commit 7c8bb2e

Browse files
authored
Merge pull request #1 from junior/main
Initial version v1.0.0
2 parents fe921df + 5981240 commit 7c8bb2e

16 files changed

+1114
-2
lines changed

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Local .terraform directories
22
**/.terraform/*
3+
**/.terrafor*
34

45
# .tfstate files
56
*.tfstate
@@ -12,7 +13,6 @@ crash.log
1213
# .tfvars files are managed as part of configuration and so should be included in
1314
# version control.
1415
#
15-
*.zip*
1616
*.tfvars
1717

1818
# Ignore override files as they are usually used to override resources locally and so
@@ -24,6 +24,9 @@ override.tf.json
2424

2525
# General
2626
.DS_Store
27+
**/.DS_Store
28+
*.tgz
29+
*.zip
2730
.AppleDouble
2831
.LSOverride
2932

README.md

Lines changed: 70 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,71 @@
11
# oci-dotnet
2-
QuickStart on ASP.Net with simple Terraform scripts and ORM Stack
2+
3+
QuickStart ASP.Net on OCI with Terraform scripts (Includes ORM Stack)
4+
5+
## Deploy Using Oracle Resource Manager
6+
7+
1. Click [![Deploy to Oracle Cloud][magic_button]][magic_dotnet_stack]
8+
9+
If you aren't already signed in, when prompted, enter the tenancy and user credentials.
10+
11+
1. Review and accept the terms and conditions.
12+
13+
1. Select the region where you want to deploy the stack.
14+
15+
1. Follow the on-screen prompts and instructions to create the stack.
16+
17+
1. After creating the stack, click **Terraform Actions**, and select **Plan**.
18+
19+
1. Wait for the job to be completed, and review the plan.
20+
21+
To make any changes, return to the Stack Details page, click **Edit Stack**, and make the required changes. Then, run the **Plan** action again.
22+
23+
1. If no further changes are necessary, return to the Stack Details page, click **Terraform Actions**, and select **Apply**.
24+
25+
## Deploy Using the Terraform CLI
26+
27+
### Clone the Module
28+
29+
Now, you'll want a local copy of this repo. You can make that with the commands:
30+
31+
git clone https://github.com/oracle-quickstart/oci-dotnet.git
32+
cd oci-dotnet
33+
ls
34+
35+
### Set Up and Configure Terraform
36+
37+
1. Complete the prerequisites described [here](https://github.com/cloud-partners/oci-prerequisites).
38+
39+
1. Create a `terraform.tfvars` file, and specify the following variables:
40+
41+
```
42+
# Authentication
43+
tenancy_ocid = "<tenancy_ocid>"
44+
user_ocid = "<user_ocid>"
45+
fingerprint = "<finger_print>"
46+
private_key_path = "<pem_private_key_path>"
47+
48+
# Region
49+
region = "<oci_region>"
50+
51+
# Compartment
52+
compartment_ocid = "<compartment_ocid>"
53+
54+
````
55+
56+
### Create the Resources
57+
58+
Run the following commands:
59+
60+
terraform init
61+
terraform plan
62+
terraform apply
63+
64+
### Destroy the Deployment
65+
66+
When you no longer need the deployment, you can run this command to destroy the resources:
67+
68+
terraform destroy
69+
70+
[magic_button]: https://oci-resourcemanager-plugin.plugins.oci.oraclecloud.com/latest/deploy-to-oracle-cloud.svg
71+
[magic_dotnet_stack]: https://cloud.oracle.com/resourcemanager/stacks/create?zipUrl=https://github.com/oracle-quickstart/oci-dotnet/releases/latest/download/oci-dotnet-stack-latest.zip

compute.tf

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Copyright (c) 2021 Oracle and/or its affiliates. All rights reserved.
2+
# Licensed under the Universal Permissive License v 1.0 as shown at http://oss.oracle.com/licenses/upl.
3+
#
4+
5+
resource "oci_core_instance" "app_instance" {
6+
availability_domain = random_shuffle.compute_ad.result[count.index % length(random_shuffle.compute_ad.result)]
7+
compartment_id = var.compartment_ocid
8+
display_name = "DotNet-${random_string.deploy_id.result}-${count.index}"
9+
shape = var.instance_shape
10+
freeform_tags = local.common_tags
11+
12+
create_vnic_details {
13+
subnet_id = oci_core_subnet.dotnet_main_subnet.id
14+
display_name = "primaryvnic"
15+
assign_public_ip = (var.instance_visibility == "Private") ? false : true
16+
hostname_label = "dotnet-${random_string.deploy_id.result}-${count.index}"
17+
}
18+
19+
source_details {
20+
source_type = "image"
21+
source_id = lookup(data.oci_core_images.compute_images.images[0], "id")
22+
}
23+
24+
metadata = {
25+
ssh_authorized_keys = var.generate_public_ssh_key ? tls_private_key.compute_ssh_key.public_key_openssh : var.public_ssh_key
26+
user_data = data.template_cloudinit_config.instances.rendered
27+
}
28+
29+
count = var.num_instances
30+
}
31+
32+
### Important Security Notice ###
33+
# The private key generated by this resource will be stored unencrypted in your Terraform state file.
34+
# Use of this resource for production deployments is not recommended.
35+
# Instead, generate a private key file outside of Terraform and distribute it securely to the system where Terraform will be run.
36+
37+
# Generate ssh keys to access Compute Nodes, if generate_public_ssh_key=true, applies to the Compute
38+
resource "tls_private_key" "compute_ssh_key" {
39+
algorithm = "RSA"
40+
rsa_bits = 2048
41+
}

datasources.tf

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
# Copyright (c) 2021 Oracle and/or its affiliates. All rights reserved.
2+
# Licensed under the Universal Permissive License v 1.0 as shown at http://oss.oracle.com/licenses/upl.
3+
#
4+
5+
# Gets a list of Availability Domains
6+
data "oci_identity_availability_domains" "ADs" {
7+
compartment_id = var.tenancy_ocid
8+
}
9+
10+
# Randoms
11+
resource "random_string" "deploy_id" {
12+
length = 4
13+
special = false
14+
}
15+
16+
# Check for resource limits
17+
## Check available compute shape
18+
data "oci_limits_services" "compute_services" {
19+
compartment_id = var.tenancy_ocid
20+
21+
filter {
22+
name = "name"
23+
values = ["compute"]
24+
}
25+
}
26+
data "oci_limits_limit_definitions" "compute_limit_definitions" {
27+
compartment_id = var.tenancy_ocid
28+
service_name = data.oci_limits_services.compute_services.services.0.name
29+
30+
filter {
31+
name = "description"
32+
values = [var.instance_shape]
33+
}
34+
}
35+
data "oci_limits_resource_availability" "compute_resource_availability" {
36+
compartment_id = var.tenancy_ocid
37+
limit_name = data.oci_limits_limit_definitions.compute_limit_definitions.limit_definitions[0].name
38+
service_name = data.oci_limits_services.compute_services.services.0.name
39+
availability_domain = data.oci_identity_availability_domains.ADs.availability_domains[count.index].name
40+
41+
count = length(data.oci_identity_availability_domains.ADs.availability_domains)
42+
}
43+
resource "random_shuffle" "compute_ad" {
44+
input = local.compute_available_limit_ad_list
45+
result_count = length(local.compute_available_limit_ad_list)
46+
}
47+
locals {
48+
compute_available_limit_ad_list = [for limit in data.oci_limits_resource_availability.compute_resource_availability : limit.availability_domain if(limit.available - var.num_instances) >= 0]
49+
compute_available_limit_error = length(local.compute_available_limit_ad_list) == 0 ? (
50+
file("ERROR: No limits available for the chosen compute shape and number of nodes")) : 0
51+
}
52+
53+
# Gets a list of supported images based on the shape, operating_system and operating_system_version provided
54+
data "oci_core_images" "compute_images" {
55+
compartment_id = var.compartment_ocid
56+
operating_system = var.image_operating_system
57+
operating_system_version = var.image_operating_system_version
58+
shape = var.instance_shape
59+
sort_by = "TIMECREATED"
60+
sort_order = "DESC"
61+
}
62+
63+
data "oci_identity_tenancy" "tenant_details" {
64+
tenancy_id = var.tenancy_ocid
65+
66+
provider = oci.current_region
67+
}
68+
69+
data "oci_identity_regions" "home_region" {
70+
filter {
71+
name = "key"
72+
values = [data.oci_identity_tenancy.tenant_details.home_region_key]
73+
}
74+
75+
provider = oci.current_region
76+
}
77+
78+
# Available Services
79+
data "oci_core_services" "all_services" {
80+
filter {
81+
name = "name"
82+
values = ["All .* Services In Oracle Services Network"]
83+
regex = true
84+
}
85+
}
86+
87+
locals {
88+
common_tags = {
89+
Reference = "Created by OCI QuickStart for DotNet sample"
90+
}
91+
}
92+
93+
# Cloud Init
94+
data "template_cloudinit_config" "instances" {
95+
gzip = true
96+
base64_encode = true
97+
98+
part {
99+
filename = "cloud-config.yaml"
100+
content_type = "text/cloud-config"
101+
content = data.template_file.cloud_init.rendered
102+
}
103+
}
104+
data "template_file" "cloud_init" {
105+
template = file("${path.module}/scripts/cloud-config.template.yaml")
106+
107+
vars = {
108+
setup_preflight_sh_content = base64gzip(data.template_file.setup_preflight.rendered)
109+
setup_template_sh_content = base64gzip(data.template_file.setup_template.rendered)
110+
deploy_template_content = base64gzip(data.template_file.deploy_template.rendered)
111+
}
112+
}
113+
data "template_file" "setup_preflight" {
114+
template = file("${path.module}/scripts/setup.preflight.sh")
115+
}
116+
data "template_file" "setup_template" {
117+
template = file("${path.module}/scripts/setup.template.sh")
118+
}
119+
data "template_file" "deploy_template" {
120+
template = file("${path.module}/scripts/deploy.template.sh")
121+
122+
vars = {
123+
dotnet_standard_type = var.dotnet_standard_type
124+
dotnet_custom_text_for_standard_webapp = var.dotnet_custom_text_for_standard_webapp
125+
dotnet_git_custom_webapp = var.dotnet_git_custom_webapp
126+
}
127+
}

loadbalancer.tf

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# Copyright (c) 2021 Oracle and/or its affiliates. All rights reserved.
2+
# Licensed under the Universal Permissive License v 1.0 as shown at http://oss.oracle.com/licenses/upl.
3+
#
4+
5+
resource "oci_load_balancer_load_balancer" "dotnet_lb" {
6+
compartment_id = var.compartment_ocid
7+
display_name = "DotNet-${random_string.deploy_id.result}"
8+
shape = var.lb_shape
9+
subnet_ids = [oci_core_subnet.dotnet_lb_subnet.id]
10+
is_private = "false"
11+
freeform_tags = local.common_tags
12+
}
13+
14+
resource "oci_load_balancer_backend_set" "dotnet_bes" {
15+
name = "dotnet-${random_string.deploy_id.result}"
16+
load_balancer_id = oci_load_balancer_load_balancer.dotnet_lb.id
17+
policy = "IP_HASH"
18+
19+
health_checker {
20+
port = local.app_port_number
21+
protocol = "HTTP"
22+
response_body_regex = ".*"
23+
url_path = "/"
24+
return_code = 200
25+
interval_ms = 5000
26+
timeout_in_millis = 2000
27+
retries = 10
28+
}
29+
}
30+
31+
resource "oci_load_balancer_backend" "dotnet-be" {
32+
load_balancer_id = oci_load_balancer_load_balancer.dotnet_lb.id
33+
backendset_name = oci_load_balancer_backend_set.dotnet_bes.name
34+
ip_address = element(oci_core_instance.app_instance.*.private_ip, count.index)
35+
port = local.app_port_number
36+
backup = false
37+
drain = false
38+
offline = false
39+
weight = 1
40+
41+
count = var.num_instances
42+
}
43+
44+
resource "oci_load_balancer_listener" "dotnet_listener_80" {
45+
load_balancer_id = oci_load_balancer_load_balancer.dotnet_lb.id
46+
default_backend_set_name = oci_load_balancer_backend_set.dotnet_bes.name
47+
name = "dotnet-${random_string.deploy_id.result}-80"
48+
port = local.http_port_number
49+
protocol = "HTTP"
50+
51+
connection_configuration {
52+
idle_timeout_in_seconds = "30"
53+
}
54+
}
55+
56+
resource "oci_load_balancer_listener" "dotnet_listener_443" {
57+
load_balancer_id = oci_load_balancer_load_balancer.dotnet_lb.id
58+
default_backend_set_name = oci_load_balancer_backend_set.dotnet_bes.name
59+
name = "dotnet-${random_string.deploy_id.result}-443"
60+
port = local.https_port_number
61+
protocol = "HTTP"
62+
63+
connection_configuration {
64+
idle_timeout_in_seconds = "30"
65+
}
66+
}

0 commit comments

Comments
 (0)