# .Net in the cloud with OCI

Just over a month ago, I joined Oracle, specifically OCI, as a Master Principal Cloud Architect. While Oracle products such as E-Business Suite, Java, and Oracle databases are ubiquitous in the corporate world, Oracle Cloud Infrastructure or OCI is less so.

Ok, so you might be thinking… Oracle is the home of Java… so can you even run .NET in OCI? The answer is an unreserved YES! I mean.. why else would I be here?

## OCI is all about choice

OCI’s mission is to give you the tools that you need to run the applications you need the way you need to run them. There are billions of .NET applications out there, from commercial software to internal applications, that keep the lights on for every kind of business imaginable.

Of course, one of the first things I did when I started at Oracle was to dive in and figure out how to run .NET Applications on OCI as quickly as possible. There was, of course, a learning curve as I adapted to the new technologies. Let's face it: when you open up the console of a new provider, you are simultaneously faced with two thoughts.

1. Oh my god, this is overwhelming…
    
2. I’m a kid in a toy store; where do I start playing?
    

OCI is no exception, with a wide range of services designed to address the core needs of every business. I am only just starting to scratch the surface of the developer tools.

## Building my first .NET App for OCI

Disclaimer: Oracle did not hire me for my artistic talent. So clearly my first web site is going to be similar to the test apps I have built a dozen times before… The default .NET MVC application that comes with the starter kit…

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1727460027124/e6b76101-b8e4-4803-af83-6896fc550586.png align="center")

The sample app includes retrieving the hostname and IP address for the machine it is being run on to help illustrate the handling of load balancers. *Note: as of the date of publishing this article, there is a bug in the .NET appl that retrieves the 127.0.0.1 address for both deployed instances.*

As always, I have included the source code for the application and the files I will use to deploy the solution on GitHub so you can download them and experiment on your own. [Here](https://github.com/BasementProgrammer/DotNetOCIDeploymentQuickstart)

## Infrastructure as Code (IaC)

Now, of course, if we are going to be deploying something into the cloud, we should be using IaC and my sample application is no exception. There was a fair bit of learning to do on my part to get to understand all of the new OCI tech, which meant trying new things, deploying them, then destroying the stack and trying again… without IaC, this would have been much more time-consuming and difficult.

### Getting the files

There are two ways that you can get the files for this sample. First, and easiest, you can simply download the zip file from GitHub and use that directly. This method is extremely easy, you don’t even have to unzip the files.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1727460809994/80921734-7cd7-460b-bea0-f2bef23016c7.png align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1727460841166/4a0811e9-6029-45f9-8078-333e4caad5cc.png align="center")

The other alternative is to clone the repo and get access to all the source files and go from there.

Once you have the files, log into your OCI tenancy as normal.

### Resource Manager

You can find the IaC management tool “Resource Manager” under development tools.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1727461110201/aba3dd5c-ed59-4b49-a1d6-00af98c6ad8d.png align="center")

From the resource manager, choose Stacks.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1727461151488/a2272c80-9de7-475a-9fc1-6670aeb9979f.png align="center")

And from there, select the compartment you want to deploy the stack into, and then click on **Create stack.**

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1727461233232/6f02a677-afcb-4cce-af99-f0d361a1d8a3.png align="center")

### Deploying the stack

Depending on if you choose to clone the directory or download the zip file, you will either drag and drop the ZIP file onto the resource manager screen or drag and drop the tf\_project folder from the repo onto the web application.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1727461377793/9577311b-26a6-4777-8834-8f69dc2e18ab.png align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1727461544103/ebcd0267-3148-4f6e-8f00-a03d1b29f69a.gif align="center")

It doesn’t matter whether you use the zip file or the folder; the rest of the deployment will be the same.

From there, click Next, and Next again to get to the last page of the install wizard. The only change you should make from the default install is on the final page where you enable the **Run apply** option before clicking **Create.**

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1727461729001/fe623288-3a56-4d92-b2cc-4c4f78de8800.png align="center")

The deployment will take a few minutes, giving us time to look at the solution.

### Quick start code

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1727461858673/a9265b03-98b4-4190-8edc-db5e543ba64a.png align="center")

The quick start is broken up into several sections.

***img*** \- These are the images from the GitHub readme file. Ignore these  
***resources*** \- This contains an architecture diagram for the deployment  
***ociTestASPNET*** \- This contains the source code for the ASP .NET Core application that gets deployed to the virtual machines. You don’t need this code as the application is already built and stored as App.zip in the Github Repo as a release.  
***scripts*** - This contains copies of the install scripts that are used to configure the instances  
***tf\_project*** - This contains all of the Terraform files that are used to deploy the solution

Out of all the files in the repo, the tf\_files folder will be the most interesting to look at as it contains the Terraform files used for the actual deployment and the installation script that gets passed in as the CloudInit script.

Once deployed, you will have a structure deployed into your compartment that looks like this:

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1727462204572/c466636d-ea7f-4629-8c41-53dd9726be13.png align="center")

The Terraform scripts deploy two Ubuntu servers into a VCN and a public subnet. The instances are attached to a load balancer and have the necessary Netywork Security Groups to allow traffic to them.

### Finishing up

If all goes well, your deployment will be complete. Scroll down the log window to the bottom for your deployment, and you can get the IP addresses of the instances and the load balancer that has been deployed.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1727462294870/c977a47a-69f4-4b31-b3c1-1a44bfdae617.png align="center")

You can copy the IP address for the load balancer and put it into your web browser to see the ASP .NET application deployed into your infrastructure.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1727464797615/d90b66bc-a15d-4a6e-902c-6c5ac0f7e0a6.png align="center")

## Next Steps

This application and deployment is obviously extremely basic and lacks a lot of features. As I continue to dive into the developer-centric tools on OCI, I’ll publish more blog posts and videos to show how well OCI is at hosting your .NET applications. Stay tuned for more .NET on OCI content.

## Cleanup

If you use this test deployment in your account, make sure to delete the resources so that you don’t end up with a surprise bill. The cleanup has two steps, destroying the stack and then deleting the stack. These two steps must be completed in the correct order or you will have to go through your account and delete the resources manually.

### Destroy the stack

Destroying a stack tells the resource manager service to go through the resources that were created and delete them from your account. This action does not remove the actual stack definition but clears out all the resources that were created as part of applying the stack.

Inside of the resource manager stacks view, clock on your stack.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1727465112759/c40ea713-e1ce-4fb7-ab7b-1b6b59be2125.png align="center")

Inside the stack definition, click **Destroy** to delete all of the resources created as part of the stack.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1727465169573/a83229c2-9beb-4e01-ae7e-f6dbf208b218.png align="center")

The destroy process will take a few minutes to complete.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1727465422235/e11b3740-1849-48b4-9bd2-9c3ae3c1e3c5.png align="center")

Once the destroy process has been completed, you can return to the stack definition and delete the stack.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1727465480731/04430eda-b77f-4549-b02b-ca7254a597de.png align="center")

Deleting the stack will be complete almost instantly, as all it has to do is delete the stack definition, not the resources.
