-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from junior/main
Initial version v1.0.0
- Loading branch information
Showing
16 changed files
with
1,114 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,71 @@ | ||
# oci-dotnet | ||
QuickStart on ASP.Net with simple Terraform scripts and ORM Stack | ||
|
||
QuickStart ASP.Net on OCI with Terraform scripts (Includes ORM Stack) | ||
|
||
## Deploy Using Oracle Resource Manager | ||
|
||
1. Click [![Deploy to Oracle Cloud][magic_button]][magic_dotnet_stack] | ||
|
||
If you aren't already signed in, when prompted, enter the tenancy and user credentials. | ||
|
||
1. Review and accept the terms and conditions. | ||
|
||
1. Select the region where you want to deploy the stack. | ||
|
||
1. Follow the on-screen prompts and instructions to create the stack. | ||
|
||
1. After creating the stack, click **Terraform Actions**, and select **Plan**. | ||
|
||
1. 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. | ||
|
||
1. If no further changes are necessary, return to the Stack Details page, click **Terraform Actions**, and select **Apply**. | ||
|
||
## Deploy Using the Terraform CLI | ||
|
||
### Clone the Module | ||
|
||
Now, you'll want a local copy of this repo. You can make that with the commands: | ||
|
||
git clone https://github.com/oracle-quickstart/oci-dotnet.git | ||
cd oci-dotnet | ||
ls | ||
|
||
### Set Up and Configure Terraform | ||
|
||
1. Complete the prerequisites described [here](https://github.com/cloud-partners/oci-prerequisites). | ||
|
||
1. Create a `terraform.tfvars` file, and specify the following variables: | ||
|
||
``` | ||
# Authentication | ||
tenancy_ocid = "<tenancy_ocid>" | ||
user_ocid = "<user_ocid>" | ||
fingerprint = "<finger_print>" | ||
private_key_path = "<pem_private_key_path>" | ||
# Region | ||
region = "<oci_region>" | ||
# Compartment | ||
compartment_ocid = "<compartment_ocid>" | ||
```` | ||
### Create the Resources | ||
Run the following commands: | ||
terraform init | ||
terraform plan | ||
terraform apply | ||
### Destroy the Deployment | ||
When you no longer need the deployment, you can run this command to destroy the resources: | ||
terraform destroy | ||
[magic_button]: https://oci-resourcemanager-plugin.plugins.oci.oraclecloud.com/latest/deploy-to-oracle-cloud.svg | ||
[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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# Copyright (c) 2021 Oracle and/or its affiliates. All rights reserved. | ||
# Licensed under the Universal Permissive License v 1.0 as shown at http://oss.oracle.com/licenses/upl. | ||
# | ||
|
||
resource "oci_core_instance" "app_instance" { | ||
availability_domain = random_shuffle.compute_ad.result[count.index % length(random_shuffle.compute_ad.result)] | ||
compartment_id = var.compartment_ocid | ||
display_name = "DotNet-${random_string.deploy_id.result}-${count.index}" | ||
shape = var.instance_shape | ||
freeform_tags = local.common_tags | ||
|
||
create_vnic_details { | ||
subnet_id = oci_core_subnet.dotnet_main_subnet.id | ||
display_name = "primaryvnic" | ||
assign_public_ip = (var.instance_visibility == "Private") ? false : true | ||
hostname_label = "dotnet-${random_string.deploy_id.result}-${count.index}" | ||
} | ||
|
||
source_details { | ||
source_type = "image" | ||
source_id = lookup(data.oci_core_images.compute_images.images[0], "id") | ||
} | ||
|
||
metadata = { | ||
ssh_authorized_keys = var.generate_public_ssh_key ? tls_private_key.compute_ssh_key.public_key_openssh : var.public_ssh_key | ||
user_data = data.template_cloudinit_config.instances.rendered | ||
} | ||
|
||
count = var.num_instances | ||
} | ||
|
||
### Important Security Notice ### | ||
# The private key generated by this resource will be stored unencrypted in your Terraform state file. | ||
# Use of this resource for production deployments is not recommended. | ||
# Instead, generate a private key file outside of Terraform and distribute it securely to the system where Terraform will be run. | ||
|
||
# Generate ssh keys to access Compute Nodes, if generate_public_ssh_key=true, applies to the Compute | ||
resource "tls_private_key" "compute_ssh_key" { | ||
algorithm = "RSA" | ||
rsa_bits = 2048 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
# Copyright (c) 2021 Oracle and/or its affiliates. All rights reserved. | ||
# Licensed under the Universal Permissive License v 1.0 as shown at http://oss.oracle.com/licenses/upl. | ||
# | ||
|
||
# Gets a list of Availability Domains | ||
data "oci_identity_availability_domains" "ADs" { | ||
compartment_id = var.tenancy_ocid | ||
} | ||
|
||
# Randoms | ||
resource "random_string" "deploy_id" { | ||
length = 4 | ||
special = false | ||
} | ||
|
||
# Check for resource limits | ||
## Check available compute shape | ||
data "oci_limits_services" "compute_services" { | ||
compartment_id = var.tenancy_ocid | ||
|
||
filter { | ||
name = "name" | ||
values = ["compute"] | ||
} | ||
} | ||
data "oci_limits_limit_definitions" "compute_limit_definitions" { | ||
compartment_id = var.tenancy_ocid | ||
service_name = data.oci_limits_services.compute_services.services.0.name | ||
|
||
filter { | ||
name = "description" | ||
values = [var.instance_shape] | ||
} | ||
} | ||
data "oci_limits_resource_availability" "compute_resource_availability" { | ||
compartment_id = var.tenancy_ocid | ||
limit_name = data.oci_limits_limit_definitions.compute_limit_definitions.limit_definitions[0].name | ||
service_name = data.oci_limits_services.compute_services.services.0.name | ||
availability_domain = data.oci_identity_availability_domains.ADs.availability_domains[count.index].name | ||
|
||
count = length(data.oci_identity_availability_domains.ADs.availability_domains) | ||
} | ||
resource "random_shuffle" "compute_ad" { | ||
input = local.compute_available_limit_ad_list | ||
result_count = length(local.compute_available_limit_ad_list) | ||
} | ||
locals { | ||
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] | ||
compute_available_limit_error = length(local.compute_available_limit_ad_list) == 0 ? ( | ||
file("ERROR: No limits available for the chosen compute shape and number of nodes")) : 0 | ||
} | ||
|
||
# Gets a list of supported images based on the shape, operating_system and operating_system_version provided | ||
data "oci_core_images" "compute_images" { | ||
compartment_id = var.compartment_ocid | ||
operating_system = var.image_operating_system | ||
operating_system_version = var.image_operating_system_version | ||
shape = var.instance_shape | ||
sort_by = "TIMECREATED" | ||
sort_order = "DESC" | ||
} | ||
|
||
data "oci_identity_tenancy" "tenant_details" { | ||
tenancy_id = var.tenancy_ocid | ||
|
||
provider = oci.current_region | ||
} | ||
|
||
data "oci_identity_regions" "home_region" { | ||
filter { | ||
name = "key" | ||
values = [data.oci_identity_tenancy.tenant_details.home_region_key] | ||
} | ||
|
||
provider = oci.current_region | ||
} | ||
|
||
# Available Services | ||
data "oci_core_services" "all_services" { | ||
filter { | ||
name = "name" | ||
values = ["All .* Services In Oracle Services Network"] | ||
regex = true | ||
} | ||
} | ||
|
||
locals { | ||
common_tags = { | ||
Reference = "Created by OCI QuickStart for DotNet sample" | ||
} | ||
} | ||
|
||
# Cloud Init | ||
data "template_cloudinit_config" "instances" { | ||
gzip = true | ||
base64_encode = true | ||
|
||
part { | ||
filename = "cloud-config.yaml" | ||
content_type = "text/cloud-config" | ||
content = data.template_file.cloud_init.rendered | ||
} | ||
} | ||
data "template_file" "cloud_init" { | ||
template = file("${path.module}/scripts/cloud-config.template.yaml") | ||
|
||
vars = { | ||
setup_preflight_sh_content = base64gzip(data.template_file.setup_preflight.rendered) | ||
setup_template_sh_content = base64gzip(data.template_file.setup_template.rendered) | ||
deploy_template_content = base64gzip(data.template_file.deploy_template.rendered) | ||
} | ||
} | ||
data "template_file" "setup_preflight" { | ||
template = file("${path.module}/scripts/setup.preflight.sh") | ||
} | ||
data "template_file" "setup_template" { | ||
template = file("${path.module}/scripts/setup.template.sh") | ||
} | ||
data "template_file" "deploy_template" { | ||
template = file("${path.module}/scripts/deploy.template.sh") | ||
|
||
vars = { | ||
dotnet_standard_type = var.dotnet_standard_type | ||
dotnet_custom_text_for_standard_webapp = var.dotnet_custom_text_for_standard_webapp | ||
dotnet_git_custom_webapp = var.dotnet_git_custom_webapp | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
# Copyright (c) 2021 Oracle and/or its affiliates. All rights reserved. | ||
# Licensed under the Universal Permissive License v 1.0 as shown at http://oss.oracle.com/licenses/upl. | ||
# | ||
|
||
resource "oci_load_balancer_load_balancer" "dotnet_lb" { | ||
compartment_id = var.compartment_ocid | ||
display_name = "DotNet-${random_string.deploy_id.result}" | ||
shape = var.lb_shape | ||
subnet_ids = [oci_core_subnet.dotnet_lb_subnet.id] | ||
is_private = "false" | ||
freeform_tags = local.common_tags | ||
} | ||
|
||
resource "oci_load_balancer_backend_set" "dotnet_bes" { | ||
name = "dotnet-${random_string.deploy_id.result}" | ||
load_balancer_id = oci_load_balancer_load_balancer.dotnet_lb.id | ||
policy = "IP_HASH" | ||
|
||
health_checker { | ||
port = local.app_port_number | ||
protocol = "HTTP" | ||
response_body_regex = ".*" | ||
url_path = "/" | ||
return_code = 200 | ||
interval_ms = 5000 | ||
timeout_in_millis = 2000 | ||
retries = 10 | ||
} | ||
} | ||
|
||
resource "oci_load_balancer_backend" "dotnet-be" { | ||
load_balancer_id = oci_load_balancer_load_balancer.dotnet_lb.id | ||
backendset_name = oci_load_balancer_backend_set.dotnet_bes.name | ||
ip_address = element(oci_core_instance.app_instance.*.private_ip, count.index) | ||
port = local.app_port_number | ||
backup = false | ||
drain = false | ||
offline = false | ||
weight = 1 | ||
|
||
count = var.num_instances | ||
} | ||
|
||
resource "oci_load_balancer_listener" "dotnet_listener_80" { | ||
load_balancer_id = oci_load_balancer_load_balancer.dotnet_lb.id | ||
default_backend_set_name = oci_load_balancer_backend_set.dotnet_bes.name | ||
name = "dotnet-${random_string.deploy_id.result}-80" | ||
port = local.http_port_number | ||
protocol = "HTTP" | ||
|
||
connection_configuration { | ||
idle_timeout_in_seconds = "30" | ||
} | ||
} | ||
|
||
resource "oci_load_balancer_listener" "dotnet_listener_443" { | ||
load_balancer_id = oci_load_balancer_load_balancer.dotnet_lb.id | ||
default_backend_set_name = oci_load_balancer_backend_set.dotnet_bes.name | ||
name = "dotnet-${random_string.deploy_id.result}-443" | ||
port = local.https_port_number | ||
protocol = "HTTP" | ||
|
||
connection_configuration { | ||
idle_timeout_in_seconds = "30" | ||
} | ||
} |
Oops, something went wrong.