<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Rafael Maia</title>
    <description>The latest articles on DEV Community by Rafael Maia (@rafmaia92).</description>
    <link>https://dev.to/rafmaia92</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F377034%2F2cb25a25-ee2e-4bf5-bad8-f2b46ccd81f9.jpeg</url>
      <title>DEV Community: Rafael Maia</title>
      <link>https://dev.to/rafmaia92</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/rafmaia92"/>
    <language>en</language>
    <item>
      <title>Deploy your first Spring boot app using IaC on Azure</title>
      <dc:creator>Rafael Maia</dc:creator>
      <pubDate>Fri, 14 Apr 2023 16:17:28 +0000</pubDate>
      <link>https://dev.to/rafmaia92/deploy-your-first-spring-boot-app-using-iac-on-azure-3ba5</link>
      <guid>https://dev.to/rafmaia92/deploy-your-first-spring-boot-app-using-iac-on-azure-3ba5</guid>
      <description>&lt;p&gt;Are you a Spring Boot and Infrastructure as Code (IaC) pro already? Great, then skip to the end of this blog post and grab the code to finish your POC and call it a day! But if you're new to this, buckle up! In this post, we'll take you on a journey to deploy your first Spring Boot application using IaC on Azure. It's going to be a wild ride, but we promise it'll be fun!&lt;/p&gt;

&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;Are you new to Spring Boot and Infrastructure as Code (IaC)? In this blog post, we will guide you through the process of deploying your first Spring Boot application using IaC on Azure.&lt;/p&gt;

&lt;p&gt;IaC is a modern approach to infrastructure management that emphasizes fully automated deployment workflows. This approach allows developers to focus on writing code while the infrastructure is automatically provisioned and managed.&lt;/p&gt;

&lt;p&gt;In this post, we'll use Bicep, a human-readable language for defining Azure resources. Bicep simplifies creating and managing Azure resources by abstracting the underlying JSON syntax. You can define resources as code, version it, test it, and deploy it using tools like Azure CLI, Azure PowerShell, or GitHub Actions. Developed by Microsoft, Bicep is open source and gaining popularity among Azure users for its ease of use and flexibility.&lt;/p&gt;

&lt;p&gt;Azure is a cloud platform that provides a wide range of infrastructure services. It is a popular choice for deploying Spring Boot applications due to its scalability, reliability, and ease of use.&lt;/p&gt;

&lt;p&gt;In this blog post, we will cover the following steps:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Create a spring boot project&lt;/li&gt;
&lt;li&gt;Create an azure account and subscription&lt;/li&gt;
&lt;li&gt;Install Azure CLI&lt;/li&gt;
&lt;li&gt;Azure App Service&lt;/li&gt;
&lt;li&gt;Create a Resource group&lt;/li&gt;
&lt;li&gt;Create bicep file&lt;/li&gt;
&lt;li&gt;Deploy the infra &lt;/li&gt;
&lt;li&gt;Build and Deploy Spring Boot app&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;By the end of this blog post, you will have a fully functional Spring Boot application running on Azure using IaC. Let's get started!&lt;/p&gt;

&lt;h2&gt;
  
  
  Create a spring boot project.
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Go to &lt;strong&gt;&lt;a href="https://start.spring.io/" rel="noopener noreferrer"&gt;https://start.spring.io/&lt;/a&gt;&lt;/strong&gt; and select "Generate a Gradle Project" or "Generate a Maven Project" depending on your preference.&lt;/li&gt;
&lt;li&gt;Choose a project name, package name, and location to store the project files.&lt;/li&gt;
&lt;li&gt;Click on the "Generate" button to create the project.&lt;/li&gt;
&lt;li&gt;Import the project into your IDE of choice.&lt;/li&gt;
&lt;li&gt;Start coding your Spring Boot application.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;First, let’s add the spring web dependency to build our rest API&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight xml"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;dependency&amp;gt;&lt;/span&gt;
            &lt;span class="nt"&gt;&amp;lt;groupId&amp;gt;&lt;/span&gt;org.springframework.boot&lt;span class="nt"&gt;&amp;lt;/groupId&amp;gt;&lt;/span&gt;
            &lt;span class="nt"&gt;&amp;lt;artifactId&amp;gt;&lt;/span&gt;spring-boot-starter-web&lt;span class="nt"&gt;&amp;lt;/artifactId&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/dependency&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;or if you prefer gradle&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
implementation group: 'org.springframework.boot', name: 'spring-boot-starter-web', version: '3.0.5'

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;now let’s a create a simple Controller&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="nd"&gt;@RestController&lt;/span&gt;
&lt;span class="nd"&gt;@RequestMapping&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"/api/v1"&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;HelloController&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;

    &lt;span class="nd"&gt;@GetMapping&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"/hello"&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="nf"&gt;hello&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s"&gt;"hello from java app"&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;

&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;let’s test it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="n"&gt;mvn&lt;/span&gt; &lt;span class="n"&gt;spring&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nl"&gt;boot:&lt;/span&gt; &lt;span class="n"&gt;run&lt;/span&gt; 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;you should be able to hit the rest api&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;curl http://localhost:8080/api/v1/hello
hello from java app
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Create a subscription
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;First, create an Azure account if you haven't already. You can sign up for a free account or a paid account, depending on your needs.&lt;/li&gt;
&lt;li&gt;Once you have an Azure account, go to the Azure portal at &lt;strong&gt;&lt;a href="https://portal.azure.com/" rel="noopener noreferrer"&gt;https://portal.azure.com/&lt;/a&gt;&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;In the top-right corner of the page, click on the "Create a resource" button.&lt;/li&gt;
&lt;li&gt;From the list of available services, select "Subscription".&lt;/li&gt;
&lt;li&gt;On the "Create subscription" page, enter the required information such as your subscription name, billing information, and your Azure Active Directory tenant (if applicable).&lt;/li&gt;
&lt;li&gt;Review the terms and conditions, and then click on the "Create" button to create your new subscription.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Once you have created your subscription, you can start using Azure services such as virtual machines, databases, storage, and more. You'll be charged for the services you use based on the pricing plan you selected during the subscription creation process. You can also manage your subscription and its resources through the Azure portal, Azure CLI, or Azure PowerShell.&lt;/p&gt;

&lt;h2&gt;
  
  
  Install Azure CLI
&lt;/h2&gt;

&lt;p&gt;instructions can be find here &lt;a href="https://learn.microsoft.com/en-us/cli/azure/" rel="noopener noreferrer"&gt;https://learn.microsoft.com/en-us/cli/azure/&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What is needed to create an Azure AppService
&lt;/h2&gt;

&lt;p&gt;To create an App Service on Azure, you need the following components:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Resource Group&lt;/strong&gt;: A logical container for resources that are deployed within an Azure subscription. It helps you organize and manage resources based on their lifecycle and their relationship to each other.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;App Service Plan&lt;/strong&gt;: This defines a set of compute resources for a web app to run. It determines the performance, cost, and features available to your application. You can choose from various tiers, including Free, Shared, Basic, Standard, Premium, and Isolated, based on your needs.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;App Service&lt;/strong&gt;: This is a fully managed platform for building, deploying, and scaling your web apps. It supports a variety of programming languages and frameworks, such as .NET, Java, Node.js, Python, and PHP. You can deploy your application to an App Service, which automatically provides the necessary underlying infrastructure, scaling, and management capabilities.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Create a resource group
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;az group create &lt;span class="nt"&gt;--location&lt;/span&gt; westeurope &lt;span class="nt"&gt;--resource-group&lt;/span&gt; todo-rg
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Create the bicep files
&lt;/h2&gt;

&lt;p&gt;We are going to start with a few bicep code blocks: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Parameters
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="nx"&gt;param&lt;/span&gt; &lt;span class="nx"&gt;location&lt;/span&gt; &lt;span class="nx"&gt;string&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;westeurope&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="nx"&gt;param&lt;/span&gt; &lt;span class="nx"&gt;appName&lt;/span&gt; &lt;span class="nx"&gt;string&lt;/span&gt;
&lt;span class="nx"&gt;param&lt;/span&gt; &lt;span class="nx"&gt;appServicePlanName&lt;/span&gt; &lt;span class="nx"&gt;string&lt;/span&gt;
&lt;span class="nx"&gt;param&lt;/span&gt; &lt;span class="nx"&gt;sku&lt;/span&gt; &lt;span class="nx"&gt;string&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;F1&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This code snippet defines parameters in a Bicep configuration file. Parameters allow you to pass values into your Bicep file when deploying your resources, making the configuration more dynamic and reusable. Let's break down each parameter:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;param location string = 'westeurope'&lt;/code&gt;&lt;/strong&gt;: This defines a parameter named &lt;strong&gt;&lt;code&gt;location&lt;/code&gt;&lt;/strong&gt; of type &lt;strong&gt;&lt;code&gt;string&lt;/code&gt;&lt;/strong&gt; with a default value of &lt;strong&gt;&lt;code&gt;'westeurope'&lt;/code&gt;&lt;/strong&gt;. The &lt;strong&gt;&lt;code&gt;location&lt;/code&gt;&lt;/strong&gt; parameter represents the Azure region where resources will be deployed.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;param appName string&lt;/code&gt;&lt;/strong&gt;: This defines a parameter named &lt;strong&gt;&lt;code&gt;appName&lt;/code&gt;&lt;/strong&gt; of type &lt;strong&gt;&lt;code&gt;string&lt;/code&gt;&lt;/strong&gt;. This parameter does not have a default value, so it must be provided when deploying the Bicep file. The &lt;strong&gt;&lt;code&gt;appName&lt;/code&gt;&lt;/strong&gt; parameter represents the name of the App Service to be created.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;param appServicePlanName string&lt;/code&gt;&lt;/strong&gt;: This defines a parameter named &lt;strong&gt;&lt;code&gt;appServicePlanName&lt;/code&gt;&lt;/strong&gt; of type &lt;strong&gt;&lt;code&gt;string&lt;/code&gt;&lt;/strong&gt;. This parameter also does not have a default value and must be provided when deploying the Bicep file. The &lt;strong&gt;&lt;code&gt;appServicePlanName&lt;/code&gt;&lt;/strong&gt; parameter represents the name of the App Service Plan to be created.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;param sku string = 'F1'&lt;/code&gt;&lt;/strong&gt;: This defines a parameter named &lt;strong&gt;&lt;code&gt;sku&lt;/code&gt;&lt;/strong&gt; of type &lt;strong&gt;&lt;code&gt;string&lt;/code&gt;&lt;/strong&gt; with a default value of &lt;strong&gt;&lt;code&gt;'F1'&lt;/code&gt;&lt;/strong&gt;. The &lt;strong&gt;&lt;code&gt;sku&lt;/code&gt;&lt;/strong&gt; parameter represents the SKU (Stock Keeping Unit) of the App Service Plan, which determines its pricing tier and performance characteristics. The default value &lt;strong&gt;&lt;code&gt;'F1'&lt;/code&gt;&lt;/strong&gt; corresponds to the Free tier.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;These parameters allow you to customise the deployment of your Azure resources, such as specifying different names, locations, or pricing tiers, without modifying the Bicep configuration file directly.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;App Service Plan
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="nx"&gt;resource&lt;/span&gt; &lt;span class="nx"&gt;appServicePlan&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Microsoft.Web/serverfarms@2022-03-01&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;appServicePlanName&lt;/span&gt;
  &lt;span class="na"&gt;location&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;location&lt;/span&gt;
  &lt;span class="na"&gt;properties&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;reserved&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="nl"&gt;sku&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;sku&lt;/span&gt;
    &lt;span class="na"&gt;tier&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Free&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
    &lt;span class="na"&gt;size&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;sku&lt;/span&gt;
    &lt;span class="na"&gt;family&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;F&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
    &lt;span class="na"&gt;capacity&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This code snippet is a Bicep configuration for defining an Azure App Service Plan resource. Let's break it down:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;resource appServicePlan 'Microsoft.Web/serverfarms@2022-03-01'&lt;/code&gt;&lt;/strong&gt;: This line declares a new resource named &lt;strong&gt;&lt;code&gt;appServicePlan&lt;/code&gt;&lt;/strong&gt; of type &lt;strong&gt;&lt;code&gt;Microsoft.Web/serverfarms&lt;/code&gt;&lt;/strong&gt; with an API version &lt;strong&gt;&lt;code&gt;2022-03-01&lt;/code&gt;&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;name: appServicePlanName&lt;/code&gt;&lt;/strong&gt;: This sets the name of the App Service Plan to the value of the &lt;strong&gt;&lt;code&gt;appServicePlanName&lt;/code&gt;&lt;/strong&gt; parameter.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;location: location&lt;/code&gt;&lt;/strong&gt;: This sets the location (region) where the App Service Plan will be deployed, using the value of the &lt;strong&gt;&lt;code&gt;location&lt;/code&gt;&lt;/strong&gt; parameter.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;properties: { reserved: true }&lt;/code&gt;&lt;/strong&gt;: This sets the &lt;strong&gt;&lt;code&gt;reserved&lt;/code&gt;&lt;/strong&gt; property to &lt;strong&gt;&lt;code&gt;true&lt;/code&gt;&lt;/strong&gt;. For an App Service Plan running on Linux, this property must be set to &lt;strong&gt;&lt;code&gt;true&lt;/code&gt;&lt;/strong&gt;. It's not applicable for Windows-based App Service Plans.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;sku: { ... }&lt;/code&gt;&lt;/strong&gt;: This block defines the pricing tier and performance characteristics of the App Service Plan.

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;name: sku&lt;/code&gt;&lt;/strong&gt;: This sets the name of the SKU (Stock Keeping Unit) using the value of the &lt;strong&gt;&lt;code&gt;sku&lt;/code&gt;&lt;/strong&gt; parameter.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;tier: 'Free'&lt;/code&gt;&lt;/strong&gt;: This sets the tier of the App Service Plan to 'Free'. Other options include Shared, Basic, Standard, Premium, and Isolated.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;size: sku&lt;/code&gt;&lt;/strong&gt;: This sets the size of the SKU using the value of the &lt;strong&gt;&lt;code&gt;sku&lt;/code&gt;&lt;/strong&gt; parameter.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;family: 'F'&lt;/code&gt;&lt;/strong&gt;: This sets the family of the SKU to 'F', which corresponds to the Free tier.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;capacity: 1&lt;/code&gt;&lt;/strong&gt;: This sets the capacity, which represents the number of instances (VMs) allocated for this App Service Plan, to 1.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;In summary, this Bicep configuration creates a new Azure App Service Plan resource with the specified name and location, running on Linux, using the Free pricing tier with a single instance.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;App Service
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;
&lt;span class="nx"&gt;resource&lt;/span&gt; &lt;span class="nx"&gt;appService&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Microsoft.Web/sites@2022-03-01&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;appName&lt;/span&gt;
  &lt;span class="na"&gt;location&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;location&lt;/span&gt;
  &lt;span class="na"&gt;properties&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;serverFarmId&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;appServicePlan&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;
    &lt;span class="na"&gt;siteConfig&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="na"&gt;linuxFxVersion&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;JAVA|17-java17&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;    
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This code snippet is a Bicep configuration for defining an Azure App Service resource. Let's break it down:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;resource appService 'Microsoft.Web/sites@2022-03-01'&lt;/code&gt;&lt;/strong&gt;: This line declares a new resource named &lt;strong&gt;&lt;code&gt;appService&lt;/code&gt;&lt;/strong&gt; of type &lt;strong&gt;&lt;code&gt;Microsoft.Web/sites&lt;/code&gt;&lt;/strong&gt; with an API version &lt;strong&gt;&lt;code&gt;2022-03-01&lt;/code&gt;&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;name: appName&lt;/code&gt;&lt;/strong&gt;: This sets the name of the App Service to the value of the &lt;strong&gt;&lt;code&gt;appName&lt;/code&gt;&lt;/strong&gt; parameter.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;location: location&lt;/code&gt;&lt;/strong&gt;: This sets the location (region) where the App Service will be deployed, using the value of the &lt;strong&gt;&lt;code&gt;location&lt;/code&gt;&lt;/strong&gt; parameter.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;properties: { ... }&lt;/code&gt;&lt;/strong&gt;: This block defines the properties of the App Service.

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;serverFarmId: appServicePlan.id&lt;/code&gt;&lt;/strong&gt;: This associates the App Service with an App Service Plan by setting the &lt;strong&gt;&lt;code&gt;serverFarmId&lt;/code&gt;&lt;/strong&gt; property to the &lt;strong&gt;&lt;code&gt;id&lt;/code&gt;&lt;/strong&gt; of the &lt;strong&gt;&lt;code&gt;appServicePlan&lt;/code&gt;&lt;/strong&gt; resource defined earlier.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;siteConfig: { ... }&lt;/code&gt;&lt;/strong&gt;: This block sets the configuration for the App Service.

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;linuxFxVersion: 'JAVA|17-java17'&lt;/code&gt;&lt;/strong&gt;: This sets the runtime environment for the App Service to Java 17. The &lt;strong&gt;&lt;code&gt;linuxFxVersion&lt;/code&gt;&lt;/strong&gt; property is used to specify the runtime stack when deploying an App Service on Linux.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;In summary, this Bicep configuration creates a new Azure App Service resource with the specified name and location, running on a Linux environment with Java 17 as the runtime stack, and associates it with an App Service Plan defined by &lt;strong&gt;&lt;code&gt;appServicePlan.id&lt;/code&gt;&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;enough blah blah, right? &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fg8b07y0cf6epczxntzi9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fg8b07y0cf6epczxntzi9.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Create a main.bicep&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;param location string &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'westeurope'&lt;/span&gt;
param appName string
param appServicePlanName string
param sku string &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'F1'&lt;/span&gt;

resource appServicePlan &lt;span class="s1"&gt;'Microsoft.Web/serverfarms@2022-03-01'&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
  name: appServicePlanName
  location: location
  properties: &lt;span class="o"&gt;{&lt;/span&gt;
    reserved: &lt;span class="nb"&gt;true&lt;/span&gt;
  &lt;span class="o"&gt;}&lt;/span&gt;
  sku: &lt;span class="o"&gt;{&lt;/span&gt;
    name: sku
    tier: &lt;span class="s1"&gt;'Free'&lt;/span&gt;
    size: sku
    family: &lt;span class="s1"&gt;'F'&lt;/span&gt;
    capacity: 1
  &lt;span class="o"&gt;}&lt;/span&gt;

&lt;span class="o"&gt;}&lt;/span&gt;

resource appService &lt;span class="s1"&gt;'Microsoft.Web/sites@2022-03-01'&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
  name: appName
  location: location
  properties: &lt;span class="o"&gt;{&lt;/span&gt;
    serverFarmId: appServicePlan.id
    siteConfig: &lt;span class="o"&gt;{&lt;/span&gt;
      linuxFxVersion: &lt;span class="s1"&gt;'JAVA|17-java17'&lt;/span&gt;    
    &lt;span class="o"&gt;}&lt;/span&gt;
  &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;now it's time to deploy your infra.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="nx"&gt;az&lt;/span&gt; &lt;span class="nx"&gt;deployment&lt;/span&gt; &lt;span class="nx"&gt;group&lt;/span&gt; &lt;span class="nx"&gt;create&lt;/span&gt; &lt;span class="o"&gt;--&lt;/span&gt;&lt;span class="nx"&gt;resource&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;group&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;todo-rg&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="o"&gt;--&lt;/span&gt;&lt;span class="nx"&gt;template&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;file&lt;/span&gt; &lt;span class="nx"&gt;main&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;bicep&lt;/span&gt; &lt;span class="o"&gt;--&lt;/span&gt;&lt;span class="nx"&gt;parameters&lt;/span&gt; &lt;span class="nx"&gt;appName&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;todo-app-as&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="nx"&gt;appServicePlanName&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;todo-app-asp&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can follow the deployments on azure portal&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3sk133k2mksashl8ecty.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3sk133k2mksashl8ecty.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;and after a new minutes you will be able to see the infra created here. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxyetw7jn0ot6jouo7rh8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxyetw7jn0ot6jouo7rh8.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Deploy Jar file via Azure CLI
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="nx"&gt;az&lt;/span&gt; &lt;span class="nx"&gt;webapp&lt;/span&gt; &lt;span class="nx"&gt;deploy&lt;/span&gt; &lt;span class="o"&gt;--&lt;/span&gt;&lt;span class="nx"&gt;resource&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;group&lt;/span&gt;  &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;todo-rg&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="o"&gt;--&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;todo-app-as&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="o"&gt;--&lt;/span&gt;&lt;span class="nx"&gt;src&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;path&lt;/span&gt; &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="nx"&gt;target&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="nx"&gt;todo&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mf"&gt;0.0&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;SNAPSHOT&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;jar&lt;/span&gt; &lt;span class="o"&gt;--&lt;/span&gt;&lt;span class="nx"&gt;type&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;jar&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Pro Tips
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;When you're playing around with cloud vendors like Microsoft, it's always a good idea to keep your configurations as code. This way, you can easily delete and recreate your infrastructure only when you're using it. That way, you won't be surprised by an unpleasant cloud bill.&lt;/li&gt;
&lt;li&gt;if you are new to Azure, just be patient, if the CLI says it worked, it worked even thought you can see it yet on the portal.&lt;/li&gt;
&lt;li&gt;This is not production code, be aware, stay secure!&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  What's next?
&lt;/h2&gt;

&lt;p&gt;This is an introductory post featuring a basic Java application deployed on Azure App Services, but there is so much more to come! In the upcoming posts, we will delve into other Azure services such as Key Vault and App Insights. Additionally, we will explore the creation of build pipelines and the deployment of a variety of exciting applications. So, get ready to be amazed and stay tuned for more updates and insights!&lt;/p&gt;

&lt;p&gt;You can find the code examples here: &lt;a href="https://github.com/RafMaia92/blog-code/tree/main/01-spring-iac-appservice-basic" rel="noopener noreferrer"&gt;https://github.com/RafMaia92/blog-code/tree/main/01-spring-iac-appservice-basic&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;feel always free to reach out via twitter &lt;a class="mentioned-user" href="https://dev.to/rafmaia92"&gt;@rafmaia92&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Happy Coding! &lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
