<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Xente on Medium]]></title>
        <description><![CDATA[Stories by Xente on Medium]]></description>
        <link>https://medium.com/@vivazmo?source=rss-70ae38d4854------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*I0nObBQdsDWVCPYE</url>
            <title>Stories by Xente on Medium</title>
            <link>https://medium.com/@vivazmo?source=rss-70ae38d4854------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 03:21:50 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@vivazmo/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[How to Move Specific Folders to a New Git Repository (with Full History)]]></title>
            <link>https://medium.com/@vivazmo/how-to-move-specific-folders-to-a-new-git-repository-with-full-history-5a3f2f65078d?source=rss-70ae38d4854------2</link>
            <guid isPermaLink="false">https://medium.com/p/5a3f2f65078d</guid>
            <dc:creator><![CDATA[Xente]]></dc:creator>
            <pubDate>Fri, 20 Jun 2025 15:01:39 GMT</pubDate>
            <atom:updated>2025-06-20T15:01:39.048Z</atom:updated>
            <content:encoded><![CDATA[<p>Sometimes your monorepo grows too big, and you want to split out specific folders into their own repositories — but you don’t want to lose the precious Git history. Good news: you can split a repo, keep the history for specific folders, and push it to a new clean repo using git filter-repo.</p><p>In this guide, we’ll walk through exactly that.</p><h4>Scenario</h4><pre>monorepo/<br>├── apps/<br>│   └── cool-app/<br>├── libs/<br>│   ├── shared-ui/<br>│   └── utils/<br>├── README.md<br>└── package.json</pre><p>And you want to move apps/cool-app/ and libs/shared-ui/ into a new repo called cool-stack, while keeping their <strong>Git commit history</strong>.</p><h4>Prerequisites</h4><ul><li>Git installed</li><li>SSH access configured to GitHub</li><li><a href="https://github.com/newren/git-filter-repo">git-filter-repo</a> installed:</li></ul><pre>brew install git-filter-repo          # macOS</pre><h4>Step 1: Clone the Monorepo as a Bare Repo</h4><p>We’ll start by cloning the original repository as a bare repo:</p><pre>git clone --bare git@github.com:your-org/monorepo.git<br>cd monorepo.git</pre><h4>Step 2: Filter Only the Folders You Want</h4><p>Now let’s strip away everything except the folders we care about:</p><pre>git filter-repo --path apps/cool-app --path libs/shared-ui --force</pre><p>This rewrites the repo to only include commits related to those two folders.</p><p>After this step, those folders will be at the root level of the new repo.</p><h4>Step 3: Add the New GitHub Repository as Remote</h4><p>Let’s say you already created a new empty repo called cool-stack on GitHub:</p><pre>git remote add new git@github.com:your-org/cool-stack.git</pre><h4>Step 4: Push the Filtered Repo to the New Remote</h4><p>Since the history was rewritten, we need to force push:</p><pre>git push --force new HEAD:main</pre><blockquote>If your new repo’s default branch is master, use HEAD:master instead.</blockquote><h4>Final Structure</h4><p>Your new repo will now look like this:</p><pre>cool-stack/<br>├── cool-app/<br>├── shared-ui/</pre><h4>Common Errors &amp; Fixes</h4><p>Updates were rejected…</p><p>This happens if your new repo already has commits. Fix it with:</p><pre>git push --force new HEAD:main</pre><p>RPC failed; HTTP 400</p><p>You’re using HTTPS and big repo then you can increase the postBuffer</p><pre>git config --global http.postBuffer 524288000<br>git push --force new HEAD:main</pre><p>You’re using HTTPS. Switch to SSH:</p><pre>git remote set-url new git@github.com:your-org/cool-stack.git</pre><h3>Conclusion</h3><p>Splitting Git repositories doesn’t mean losing your history. With git filter-repo, you can surgically extract only what you need — and leave the rest behind. It’s powerful, fast, and scriptable.</p><p>Happy clean coding!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5a3f2f65078d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Using the ArgoCD Helmfile Secrets Plugin for Secure Deployments]]></title>
            <link>https://medium.com/@vivazmo/using-the-argocd-helmfile-secrets-plugin-for-secure-deployments-c2674944a43f?source=rss-70ae38d4854------2</link>
            <guid isPermaLink="false">https://medium.com/p/c2674944a43f</guid>
            <category><![CDATA[secrets]]></category>
            <category><![CDATA[cloud]]></category>
            <category><![CDATA[argo-cd]]></category>
            <category><![CDATA[helmfile]]></category>
            <dc:creator><![CDATA[Xente]]></dc:creator>
            <pubDate>Fri, 20 Dec 2024 13:10:29 GMT</pubDate>
            <atom:updated>2024-12-20T13:10:29.097Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/538/1*8FIHt_15f1BCdCOT2tSLMQ.png" /></figure><p>When managing deployments at scale, security and simplicity are paramount. The <a href="https://github.com/xente/argocd-helmfile-secrets-plugin">Argo CD Helmfile Secrets Plugin</a> bridges the gap between securely managing secrets and deploying applications with Argo CD and Helmfile.</p><p>In this guide, we’ll dive into how this plugin works, its benefits, and how you can leverage it for your Kubernetes deployments.</p><h3>What is the Argo CD Helmfile Secrets Plugin?</h3><p>The Argo CD Helmfile Secrets Plugin extends Argo CD to support managing secrets when deploying Kubernetes manifests using Helmfile.</p><p>By default, Argo CD does not have native support for Helmfile, and managing secrets securely often requires additional tooling. This plugin simplifies that process by integrating Helmfile and secrets management directly into Argo CD workflows.</p><p>The plugin enables you to:</p><ul><li>Use encrypted secrets seamlessly in Helmfile.</li><li>Decrypt secrets on the fly during Argo CD’s application synchronization.</li><li>Maintain a clean separation between your secret management system and application manifests.</li></ul><h3>How Does the Plugin Work?</h3><p>The plugin acts as a custom configuration management tool for Argo CD. It integrates with Helmfile and supports popular secrets management backends such as sops, HashiCorp Vault, AWS SSM Parameter Store, Azure Key Vault and <a href="https://github.com/helmfile/vals">others</a>. Here’s a high-level view of how it operates:</p><ol><li><strong>Seamless Integration with Argo CD:</strong> Manage Helm releases and configurations directly from Argo CD with support for Helmfile’s multi-environment capabilities.</li><li><strong>Secret Management: </strong>Securely handle cloud secrets using <a href="https://github.com/helmfile/vals">Helmfile vals tool</a>.</li><li><strong>Declarative GitOps Workflow: </strong>Leverage GitOps principles to manage Helmfile configurations and associated secrets.</li><li><strong>Simplified Helmfile Handling: </strong>Eliminate the need for manual Helmfile management; automate the deployment of Helm charts across multiple environments directly within Argo CD.</li><li><strong>Customizable Secret Backends:</strong> Support for multiple secret backends like sops, HashiCorp Vault, AWS SSM Parameter Store, Azure Key Vault and [others] (<a href="https://github.com/helmfile/vals">https://github.com/helmfile/vals</a>).</li><li><strong>Helmfile Project Selector: </strong>Select specific Helmfile projects for deployment, allowing for granular control over which charts are managed by Argo CD.</li></ol><h3>Setting Up the Plugin</h3><p>To use the plugin in your Argo CD setup, follow these steps:</p><h4>1. Install the Plugin</h4><p>Clone the plugin’s repository and build the binary:</p><pre># Clone the repository<br>git clone https://github.com/xente/argocd-helmfile-secrets-plugin.git<br>cd argocd-helmfile-secrets-plugin</pre><blockquote>We are using <strong>namespace</strong> called argocd. If your Argo CD is installed in another namespace you have to update the script</blockquote><p>Create k8s configmap that&#39;s contains the command to run Helmfile</p><pre>kubectl apply -n argocd -f cmp-helmfile-configmap.yaml</pre><p>Apply path script to Argo CD repo server</p><pre>kubectl -n argocd patch deployments/argocd-repo-server --patch-file argocd-repo-server-patch.yaml</pre><h4>2. Deploy Applications</h4><p>Create Argo CD Application definition:</p><pre>apiVersion: argoproj.io/v1alpha1<br>kind: Application<br>metadata:<br>  name: my-app<br>  namespace: argocd<br>spec:<br>  project: default<br>  source:<br>    repoURL: https://github.com/my-org/my-app-repo<br>    targetRevision: HEAD<br>    path: .<br>  destination:<br>    server: https://kubernetes.default.svc<br>    namespace: my-namespace<br>  syncPolicy:<br>    automated:<br>      prune: true<br>      selfHeal: true<br>    syncOptions:<br>      - CreateNamespace=true</pre><h4>3. Select Helmfile environment:</h4><p>For use <a href="https://helmfile.readthedocs.io/en/latest/#environment">Helmfile environments</a> add environment variable called `HELM_ENVIRONMENT` into plugin section of your Argo CD application definition. The value of HELM_ENVIRONMENT has to be the equals to the environment name defined into the Helmfile.</p><pre>apiVersion: argoproj.io/v1alpha1<br>kind: Application<br>metadata:<br>  name: my-app<br>  namespace: argocd<br>spec:<br>  project: default<br>  source:<br>    repoURL: https://github.com/my-org/my-app-repo<br>    targetRevision: HEAD<br>    path: .<br>    plugin:<br>      env:<br>        - name: HELM_ENVIRONMENT<br>          value: dev<br>  destination:<br>    server: https://kubernetes.default.svc<br>    namespace: my-namespace<br>  syncPolicy:<br>    automated:<br>      prune: true<br>      selfHeal: true<br>    syncOptions:<br>      - CreateNamespace=true</pre><h4>4. Use secrets:</h4><p>For managing configuration values and secrets tool <a href="https://github.com/helmfile/vals">Helmfile vals</a> is used.</p><p>For example, if using Azure Key Vaults:</p><p>Add secret reference as value of your secret:</p><ul><li>ref+azurekeyvault://VAULT-NAME/SECRET-NAME[/VERSION]</li></ul><p>Create secret yaml:</p><pre>auth:<br>  databasePass: ref+azurekeyvault://VAULT-NAME/SECRET-NAME</pre><p>Use your secret file inside helmfile</p><pre>secrets:<br>  - secret.yaml</pre><p>The secret will be retrieved from AzureKeyVault when application will be deployed in Argo CD</p><h3>Conclusion</h3><p>The <a href="https://github.com/xente/argocd-helmfile-secrets-plugin">Argo CD Helmfile Secrets Plugin</a> is a simplest tool for teams managing complex Kubernetes deployments. By integrating secrets management into the Helmfile and Argo CD, it simplifies deployments while maintaining robust security. Whether you’re working in a startup or an enterprise, this plugin can streamline your deployment process and ensure your secrets stay safe.</p><p>Ready to get started? Check out the <a href="https://github.com/xente/argocd-helmfile-secrets-plugin">GitHub repository</a> for more details and installation instructions!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c2674944a43f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Migrating Kubernetes Workloads to Azure Container Apps with k8s-to-azure-container-app]]></title>
            <link>https://medium.com/@vivazmo/migrating-kubernetes-workloads-to-azure-container-apps-with-k8s-to-azure-container-app-0a97cb84154a?source=rss-70ae38d4854------2</link>
            <guid isPermaLink="false">https://medium.com/p/0a97cb84154a</guid>
            <category><![CDATA[k8s]]></category>
            <category><![CDATA[migration]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[azure-container-apps]]></category>
            <category><![CDATA[azure]]></category>
            <dc:creator><![CDATA[Xente]]></dc:creator>
            <pubDate>Thu, 11 Jul 2024 17:02:49 GMT</pubDate>
            <atom:updated>2024-07-11T17:02:49.092Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/720/1*s83CFplW3EKIZe_Yzg9m4w.png" /></figure><p>In the ever-evolving landscape of cloud-native technologies, Kubernetes (K8s) has established itself as a go-to orchestration platform for deploying, scaling, and managing containerized applications. However, managing Kubernetes clusters can <strong>become complex and resource-intensive</strong>. This is where Azure Container Apps (ACA) come into play, offering a serverless environment for running containerized applications without the overhead of managing Kubernetes infrastructure.</p><p>Azure Container Apps became generally available in May 2022, presenting a compelling alternative to Azure Kubernetes Service (AKS), which was a popular choice for container orchestration in Azure. However, many small companies that adopted K8s often did so with limited knowledge and a small number of services. As these companies face the need for maintenance and changes, they encounter high complexity due to their lack of Kubernetes expertise.</p><p>The<strong> motivation behind</strong> creating <a href="https://github.com/xente/k8s-to-azure-container-app">k8s-to-azure-container-app</a> was to address these challenges. The tool designed to simplify the migration process from Kubernetes deployed namespaces to Azure Container Apps supporting various objects like deployments, services, and persistent volumes.</p><p>In this article, we will check the functionality, usage, and benefits of this project, providing a comprehensive guide to seamlessly transition your K8s deployed namespaces to ACA.</p><h3>Overview of k8s-to-azure-container-app</h3><p>The <a href="https://github.com/xente/k8s-to-azure-container-app">k8s-to-azure-container-app</a> project provides a set of scripts and tools to facilitate the migration of Kubernetes deployments to Azure Container Apps. It automates the transformation of K8s deployed namespaces to ACA configurations, ensuring that your applications maintain their intended functionality with minimal manual intervention.</p><h4>Key Features</h4><ul><li><strong>Automated Conversion:</strong> Connect to your current K8s cluster and automatically export the target namespace.</li><li><strong>Conversion of k8s Objects:</strong> Converts Kubernetes deployment to ACA configurations, translating essential elements like:<br>- <strong>POD:</strong> Deployment, Pod, Horizontal Pod Autoscaler<br>- <strong>Configuration:</strong> Secrets<br>- <strong>Storage:</strong> Volumes<br>- <strong>Network/Exposure:</strong> Ingress, Service, Endpoint</li><li><strong>Several Outputs Formats:</strong> We can export into yaml, json and Terraform azurerm (In beta)</li></ul><h3>Getting Started</h3><h4>Prerequisites</h4><p>Before you start using k8s-to-azure-container-app, ensure you have the following:</p><ul><li><strong>Azure CLI: </strong>Installed and configured with the necessary permissions. <a href="https://learn.microsoft.com/en-us/cli/azure/install-azure-cli">https://learn.microsoft.com/en-us/cli/azure/install-azure-cli</a></li><li><strong>Kubernetes CLI (kubectl):</strong> To interact with your Kubernetes cluster.</li><li><strong>Azure Container Apps Extension:</strong> For the Azure CLI to manage ACA resources.</li></ul><pre>az upgrade<br>az extension add -n containerapp --upgrade</pre><h4>Installation from repository for contributions</h4><p>Clone the repository and navigate to the project directory:</p><pre>git clone https://github.com/xente/k8s-to-azure-container-app.git<br>cd k8s-to-azure-container-app</pre><p>Install any necessary dependencies:</p><pre>pip install -r requirements.txt</pre><p>Generate a package:</p><pre>pip install -e .</pre><h4>Installation from pypi</h4><p>Install package <a href="https://pypi.org/">https://pypi.org/</a></p><pre>pip install k8s-to-azure-container-app</pre><h4>Usage</h4><p>Run K8sToAca using the following command:</p><pre>K8sToAca --namespace my_name_space --context cluster_context --aca_resource_group target_resource_group --aca_environment target_container_app_environment_name</pre><p>Parameters:</p><ul><li><strong>namespace (Required):</strong> The Kubernetes namespace to be migrated.</li><li><strong>context (Required):</strong> The name of the Kubernetes config context for the cluster.</li><li><strong>aca_resource_group (Required):</strong> Azure Resource Group where the Container App Environment exists.</li><li><strong>aca_environment (Required):</strong> Name of the Azure Container App Environment.</li><li><strong>output (Optional):</strong> Output format values (yaml, json, terraform). Terraform output is in preview. Default value: yaml</li><li><strong>outputpath (Optional):</strong> Output folder. Default value: current path</li></ul><p>Install generated yaml resources into your Container App Environment:</p><p>As a output by default K8sToAca generate yaml files and deployment script into output folder that can be used to deploy into your Azure Container App Environment using az command</p><pre>cd {outputpath}<br>./deployment.sh</pre><h3>Benefits of Migrating to Azure Container Apps</h3><p>Migrating to ACA offers several advantages:</p><ol><li><strong>Serverless Operations: </strong>No need to manage underlying infrastructure, reducing operational overhead.</li><li><strong>Scalability:</strong> Automatic scaling based on demand, ensuring efficient resource utilization.</li><li><strong>Cost Efficiency: </strong>Pay only for the resources your applications consume, potentially lowering costs.</li><li><strong>Simplified Management: </strong>Integrated with Azure services for monitoring, logging, and security.</li></ol><h3>Conclusion</h3><p>The k8s-to-azure-container-app project is a powerful tool for organizations looking to transition from Kubernetes to a serverless environment on Azure. By automating the conversion of Kubernetes deployed namespaces , it enables a seamless migration to Azure Container Apps, allowing you to leverage the benefits of serverless computing while maintaining the functionality of your existing applications.</p><p>For more information and to get started, visit the <a href="https://github.com/xente/k8s-to-azure-container-app">k8s-to-azure-container-app</a> GitHub repository.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=0a97cb84154a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Use DAPR with JetBrains Rider and MAC]]></title>
            <link>https://medium.com/@vivazmo/use-dapr-with-jetbrains-rider-and-mac-bde3a41ccec3?source=rss-70ae38d4854------2</link>
            <guid isPermaLink="false">https://medium.com/p/bde3a41ccec3</guid>
            <category><![CDATA[mac]]></category>
            <category><![CDATA[dapr]]></category>
            <category><![CDATA[jetbrains-rider]]></category>
            <dc:creator><![CDATA[Xente]]></dc:creator>
            <pubDate>Sat, 12 Aug 2023 16:01:37 GMT</pubDate>
            <atom:updated>2023-08-12T16:01:37.045Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uk8_ooUPbQN3hLLy-0ajfw.jpeg" /></figure><h3>Install</h3><ol><li>Install DAPR CLI from Homebrew</li></ol><pre>brew install dapr/tap/dapr-cli</pre><p>2. Install DAPR CLI from Homebrew (ARM64)</p><pre>arch -arm64 brew install dapr/tap/dapr-cli</pre><p>3. Verify the installation</p><pre>dapr -h</pre><p>4. Init DAPR instalation</p><pre>dapr init</pre><h4>Configure DAPR in Rider</h4><p><strong>Configure DAPR as External Tool in Raider</strong></p><ol><li>Settings -&gt; External Tools</li><li>Create Tool with the next configuration:<br>- <strong>Name</strong>: Dapr<br>- <strong>Program</strong>: /opt/homebrew/bin/dapr<br>- <strong>Working directory</strong>: $ProjectFileDir$<br>- <strong>Arguments</strong>:</li></ol><pre>dapr initrun --app-id demoservice --app-port 5241 --dapr-http-port 3500 --dapr-grpc-port 50001</pre><p><strong>Run DAPR in Rider<br></strong> <br>Tools-&gt; External Tools -&gt; Dapr</p><p>Now DAPR is up and running and you can use it.</p><h3>Configure Components</h3><p>To configure your components you have to add the <a href="https://docs.dapr.io/reference/components-reference/">component configuration</a> in yaml file into ~/.dapr/components/ path.</p><p>How to configure the secret store:</p><ol><li>Create secretstores_local.yaml file into ~/.dapr/components/</li><li>Add your component configuration</li></ol><pre>apiVersion: dapr.io/v1alpha1<br>kind: Component<br>metadata:<br>  name: local-secret-store<br>spec:<br>  type: secretstores.local.file<br>  version: v1<br>  metadata:<br>  - name: secretsFile<br>    value: [path to the JSON file]<br>  - name: nestedSeparator<br>    value: &quot;:&quot;<br>  - name: multiValued<br>    value: &quot;false&quot;</pre><p>3. Restart DAPR to load the new component configuration</p><p>4. Your components now are available from the DAPR client</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bde3a41ccec3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Azure Container Apps Container with Terraform (Scaling rules for azurerm < 3.74.0) [Part 4]]]></title>
            <link>https://medium.com/@vivazmo/azure-container-apps-container-with-terraform-scaling-rules-part-4-2c29bc1c92?source=rss-70ae38d4854------2</link>
            <guid isPermaLink="false">https://medium.com/p/2c29bc1c92</guid>
            <category><![CDATA[azure]]></category>
            <category><![CDATA[terraform]]></category>
            <category><![CDATA[azure-queue-storage]]></category>
            <category><![CDATA[keda]]></category>
            <category><![CDATA[azure-container-apps]]></category>
            <dc:creator><![CDATA[Xente]]></dc:creator>
            <pubDate>Sat, 12 Aug 2023 11:36:54 GMT</pubDate>
            <atom:updated>2023-10-03T15:47:30.556Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*iFmhWOawb4uMg_Qa.png" /></figure><p>I am creating a complete tutorial for an Azure Container App using Terraform.</p><p>This tutorial has been divided into 3 parts</p><ol><li><a href="https://medium.com/@vivazmo/azure-container-apps-with-terraform-part-1-ae20649e0dff">Create simple App Container using Terraform</a></li><li><a href="https://medium.com/@vivazmo/azure-container-apps-container-with-terraform-azure-key-vault-for-secrets-part-2-f888d9d682de">Use Azure Key Vault to securitize our secrets</a></li><li><a href="https://medium.com/@vivazmo/azure-container-apps-container-with-terraform-custom-domain-part-3-ba25f7b166f1">Use custom domain</a></li><li><strong>Scaling rules (KEDA)</strong></li></ol><blockquote><em>Side note: this post assumes that you already created the resources of the Create simple App Container using Terraform tutorial and Use Azure Key Vault to securitize our secrets</em></blockquote><h3>KEDA</h3><p><strong>KEDA</strong> is a single-purpose and lightweight component that can be added to any Kubernetes cluster. KEDA works alongside standard Kubernetes components like the Horizontal Pod Autoscaler and can extend functionality without overwriting or duplication. With KEDA you can explicitly map the apps you want to use event-driven scale, with other apps continuing to function. This makes KEDA a flexible and safe option for running alongside Kubernetes applications or frameworks.</p><h3>Container App Scale rules</h3><p>Scaling is driven by three different categories of triggers:</p><ul><li><a href="https://learn.microsoft.com/en-us/azure/container-apps/scale-app?pivots=azure-cli#http">HTTP</a>: Based on the number of concurrent HTTP requests to your revision.</li><li><a href="https://learn.microsoft.com/en-us/azure/container-apps/scale-app?pivots=azure-cli#tcp">TCP</a>: Based on the number of concurrent TCP connections to your revision.</li><li><a href="https://learn.microsoft.com/en-us/azure/container-apps/scale-app?pivots=azure-cli#custom">Custom</a>: Based on CPU, memory, or supported event-driven data sources such as:</li><li>Azure Service Bus</li><li>Azure Event Hubs</li><li>Apache Kafka</li><li>Redis</li></ul><h3>Scale using Terraform</h3><p>Azurerm can be used to create and manage our container app, but in version &lt; <a href="https://registry.terraform.io/providers/hashicorp/azurerm/3.73.0/docs/resources/container_app"><em>3.73.0</em></a><em>,</em> the rules are not part of azurerm_container_app resource.</p><p>As we did in part 3 of this tutorial <a href="https://medium.com/@vivazmo/azure-container-apps-container-with-terraform-custom-domain-part-3-ba25f7b166f1">using a custom domain</a> we need to use azapi_resource to define our rules with Terraform.</p><p>On this point, we can use azapi provider to create all our infrastructure but there are some points that we have to take into account:</p><p>Use only azapi:</p><p><strong>Pros:</strong></p><ul><li>We can use all the features that Azure API provides to create the infrastructure</li></ul><p><strong>Cons:</strong></p><ul><li>We are working with JSON then there are parameters that are hard to manage when they are updated outside Terraform script. In this case, the image id will be a problem.</li></ul><p>Use azapi with Azurerm:</p><p><strong>Pros:</strong></p><ul><li>Azurerm is easy to manage and can use lifecycles like ignore_changes directly to properties.</li><li>Using azapi_update_resource we can update the resource created with Azurerm with the configurations that are not available into the Azurerm resource. And wait for new Azurerm versions with needed features</li></ul><p><strong>Cons:</strong></p><ul><li>We need to duplicate secrets into azurerm_container_app and azapi_update_resource. I´m not particularly eager to copy content but it is mandatory to send it when we use azapi_update_resource or the apply fails.</li></ul><h3>Create rules</h3><ul><li>Create azapi_update_resource resource into container_app.tf adding only properties and template-&gt;scale sections</li><li>Add secrets and rules into azapi_update_resource</li><li>Add replace_triggered_by lifecycle target to azurerm_container_app.my_first_app to ensure that after we apply changes into azurerm_container_app.my_first_app the azapi_update_resource is raised</li></ul><p>Scale based on HTTP Requests:</p><pre><br>resource &quot;azapi_update_resource&quot; &quot;my_first_app&quot; {<br>  type        = &quot;Microsoft.App/containerApps@2022-10-01&quot;<br>  resource_id = azurerm_container_app.my_first_app.id<br>  <br>  body = jsonencode({<br>    properties = {<br>      configuration = {<br>        secrets = [<br>          {<br>            name  = &quot;docker-io-pass&quot; <br>            value = &quot;$(data.azurerm_key_vault.my_first_app.vault_uri)/secrets/docker-io-pass&quot;<br>          }<br>        ],<br>      },<br>      template = {<br>        scale = {<br>          rules = [<br>            {<br>             name =&quot;http-rule&quot;,<br>             http  = {<br>               metadata = {<br>                concurrentRequests = &quot;100&quot;<br>              }<br>            }<br>          ]<br>        }<br>      }<br>    }<br>  })<br>  lifecycle {<br>    replace_triggered_by = [<br>      azurerm_container_app.my_first_app<br>    ]<br>  }<br>  depends_on = [<br>    azurerm_container_app.my_first_app<br>  ]<br>}</pre><p>Scale based on HTTP Requests as Azure Queue:</p><p>Create storage_accout.tf :</p><pre>.<br>├── README.md<br>├── main.tf<br>├── container_app.tf<br>├── variables.tf<br>├── outputs.tf<br>├── provider.tf<br>├── storage_account.tf</pre><p>Create a storage account and queue:</p><pre>resource &quot;azurerm_storage_account&quot; &quot;my_first_app&quot; {<br>  name                     = &quot;st${replace(local.stack, &quot;-&quot;, &quot;&quot;)}&quot;<br>  location                 = azurerm_resource_group.my_first_app.location<br>  resource_group_name      = azurerm_resource_group.my_first_app.name<br>  account_tier             = &quot;Standard&quot;<br>  account_replication_type = &quot;LRS&quot;<br><br>  tags = local.default_tags<br>}<br><br>resource &quot;azurerm_storage_queue&quot; &quot;my_first_app&quot; {<br>  name                 = &quot;squ-${local.stack}&quot;<br>  storage_account_name = azurerm_storage_account.my_first_app.name<br>}</pre><p>Add Storage Account connection string secrets:</p><pre>resource &quot;azurerm_container_app&quot; &quot;my_first_app&quot; {   <br>...<br>  secret {<br>    name  = &quot;storage-account-connection-string&quot;<br>    value = azurerm_storage_account.my_first_app.primary_connection_string<br>  }<br> ...<br>}</pre><p>We need to add secrets into azapi_update_resource</p><pre>resource &quot;azapi_update_resource&quot; &quot;my_first_app&quot; {<br>...<br>    secrets = [<br>        {<br>            name  = &quot;storage-account-connection-string&quot;<br>            value = azurerm_storage_account.my_first_app.primary_connection_string<br>        }<br>    ]<br>...<br>}</pre><p>Add rules for scale when messages arrive in the queue:</p><pre><br>resource &quot;azapi_update_resource&quot; &quot;my_first_app&quot; {<br>...<br>template = {<br>        scale = {<br>          rules = [<br>            {<br>             name =&quot;http-rule&quot;,<br>             http  = {<br>               metadata = {<br>                concurrentRequests = &quot;100&quot;<br>              }<br>            },<br>            {<br>              name = &quot;my_first_queue&quot;,<br>              azureQueue = {<br>                queueName : azurerm_storage_queue.my_first_app.name,<br>                queueLength = 1,<br>                auth : [<br>                  {<br>                    secretRef        = &quot;storage-account-connection-string&quot;<br>                    triggerParameter = &quot;connection&quot;<br>                  }<br>                ]<br>              }<br>            }<br>          ]<br>        }<br>      }<br>    }<br>...<br>}</pre><h4>Terraform scripts:</h4><p>storage_account.tf</p><pre>resource &quot;azurerm_storage_account&quot; &quot;my_first_app&quot; {<br>  name                     = &quot;st${replace(local.stack, &quot;-&quot;, &quot;&quot;)}&quot;<br>  location                 = azurerm_resource_group.my_first_app.location<br>  resource_group_name      = azurerm_resource_group.my_first_app.name<br>  account_tier             = &quot;Standard&quot;<br>  account_replication_type = &quot;LRS&quot;<br><br>  tags = local.default_tags<br>}<br><br>resource &quot;azurerm_storage_queue&quot; &quot;my_first_app&quot; {<br>  name                 = &quot;squ-${local.stack}&quot;<br>  storage_account_name = azurerm_storage_account.my_first_app.name<br>}</pre><p>container_app.tf</p><pre>resource &quot;azurerm_container_app_environment&quot; &quot;my_first_app&quot; {<br>  #name                      = &quot;cae-${var.app}-${var.env}-${var.location}&quot;<br>  location                   = azurerm_resource_group.my_first_app.location<br>  resource_group_name        = azurerm_resource_group.my_first_app.name<br>  log_analytics_workspace_id = azurerm_log_analytics_workspace.my_first_app.id<br><br>}<br><br>data &quot;azurerm_key_vault&quot; &quot;my_first_app&quot; {<br>  name                = &quot;kv-${var.app}-${var.env}-${var.location}&quot;<br>  resource_group_name = &quot;rg-${var.app}-${var.env}-${var.location}&quot;<br>}<br><br>resource &quot;azurerm_key_vault_access_policy&quot; &quot;my_first_app&quot; {<br>  key_vault_id = data.my_first_app.id<br>  tenant_id    = azurerm_container_app.my_first_app.identity.0.tenant_id<br>  object_id    = azurerm_container_app.my_first_app.identity.0.principal_id<br>  secret_permissions = [<br>    &quot;get&quot;<br>  ]<br>}<br><br>resource &quot;azurerm_container_app_environment_certificate&quot; &quot;my_first_app&quot; {<br>  name                         = &quot;caecer-${local.stack}&quot;<br>  container_app_environment_id = azurerm_container_app_environment.my_first_app.id<br>  certificate_blob_base64      = data.azurerm_key_vault_secret.my_first_app.value<br>  certificate_password         = &quot;&quot;<br><br>  tags = local.default_tags<br>}<br><br>resource &quot;azurerm_container_app&quot; &quot;my_first_app&quot; {<br>  name                         = &quot;ca-${var.app}-${var.env}-${var.location}&quot;<br><br>  container_app_environment_id = azurerm_container_app_environment.my_first_app.id<br>  resource_group_name          = azurerm_resource_group.my_first_app.name<br>  revision_mode                = &quot;Single&quot;<br><br>  registry {<br>    server               = &quot;docker.io&quot;<br>    username             = &quot;dockerIOUserName&quot;<br>    password_secret_name = &quot;docker-io-pass&quot;<br>  }<br><br>  ingress {<br>    allow_insecure_connections = false<br>    external_enabled           = true<br>    target_port                = 80<br>    traffic_weight {<br>      percentage = 100<br>    }<br><br>  }<br><br>  template {<br>    container {<br>      name   = &quot;${var.prefix}-ca-${var.stage}&quot;<br>      image  = &quot;nginx&quot;<br>      cpu    = 0.25<br>      memory = &quot;0.5Gi&quot;<br>  }<br><br>  identity {<br>    type = &quot;SystemAssigned&quot;<br>  }<br>  <br>  secret { <br>    name  = &quot;docker-io-pass&quot; <br>    value = &quot;$(data.azurerm_key_vault.my_first_app.vault_uri)/secrets/docker-io-pass&quot;<br>  }<br><br>  secret {<br>    name  = &quot;storage-account-connection-string&quot;<br>    value = azurerm_storage_account.my_first_app.primary_connection_string<br>  }<br><br>  depends_on = [<br>    azurerm_dns_cname_record.my_first_app,<br>    azurerm_dns_txt_record.my_first_app  <br>  ]<br><br>}<br><br>resource &quot;azapi_update_resource&quot; &quot;my_first_app&quot; {<br>  type        = &quot;Microsoft.App/containerApps@2022-10-01&quot;<br>  resource_id = azurerm_container_app.my_first_app.id<br>  <br>  body = jsonencode({<br>    properties = {<br>      configuration = {<br>        secrets = [<br>          {<br>            name  = &quot;docker-io-pass&quot; <br>            value = &quot;$(data.azurerm_key_vault.my_first_app.vault_uri)/secrets/docker-io-pass&quot;<br>          },<br>          {<br>            name  = &quot;storage-account-connection-string&quot;<br>            value = azurerm_storage_account.my_first_app.primary_connection_string<br>          }<br>        ],<br>      },<br>      template = {<br>        scale = {<br>          rules = [<br>            {<br>             name =&quot;http-rule&quot;,<br>             http  = {<br>               metadata = {<br>                concurrentRequests = &quot;100&quot;<br>              }<br>            },<br>            {<br>              name = &quot;my_first_queue&quot;,<br>              azureQueue = {<br>                queueName : azurerm_storage_queue.my_first_app.name,<br>                queueLength = 1,<br>                auth : [<br>                  {<br>                    secretRef        = &quot;storage-account-connection-string&quot;<br>                    triggerParameter = &quot;connection&quot;<br>                  }<br>                ]<br>              }<br>            }<br>          ]<br>        }<br>      }<br>    }<br>  })<br>  lifecycle {<br>    replace_triggered_by = [<br>      azurerm_container_app.my_first_app<br>    ]<br>  }<br>  depends_on = [<br>    azurerm_container_app.my_first_app<br>  ]<br>}<br></pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2c29bc1c92" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Azure Container Apps Container with Terraform (Custom Domain ) [Part 3]]]></title>
            <link>https://medium.com/@vivazmo/azure-container-apps-container-with-terraform-custom-domain-part-3-ba25f7b166f1?source=rss-70ae38d4854------2</link>
            <guid isPermaLink="false">https://medium.com/p/ba25f7b166f1</guid>
            <category><![CDATA[custom-domain]]></category>
            <category><![CDATA[azure-container-apps]]></category>
            <category><![CDATA[azure]]></category>
            <category><![CDATA[terraform]]></category>
            <dc:creator><![CDATA[Xente]]></dc:creator>
            <pubDate>Wed, 17 May 2023 21:26:26 GMT</pubDate>
            <atom:updated>2023-08-13T10:18:02.312Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tj96bM011JKquZKWh8l07A.png" /></figure><p>I am creating a full tutorial for an Azure Container App using Terraform.</p><p>This tutorial has been divided into 3 parts</p><ol><li><a href="https://medium.com/@vivazmo/azure-container-apps-with-terraform-part-1-ae20649e0dff">Create simple App Container using Terraform</a></li><li><a href="https://medium.com/@vivazmo/azure-container-apps-container-with-terraform-azure-key-vault-for-secrets-part-2-f888d9d682de">Use Azure Key Vault to securitize our secrets</a></li><li><strong>Use custom domain</strong></li><li><a href="https://medium.com/@vivazmo/azure-container-apps-container-with-terraform-scaling-rules-part-4-2c29bc1c92">Scaling rules (KEDA)</a></li></ol><blockquote>Side note: this post assumes that you already created the resources of the Create simple App Container using Terraform tutorial and Use Azure Key Vault to securitize our secrets</blockquote><h3>Using custom Domain</h3><p>Our application is up and working but it only can be accessed using the Application Url provided by Azure. Using this URL is not recommended and we need to be able to provide a custom domain</p><p>Requirements:</p><ol><li>Domain (You have to be the owner of a domain)</li><li>Azure DNS Zone (Used for your domain)</li><li>SSL cert for the domain (pfx file)</li><li>DNS server (We will use here )</li></ol><h3>Bring your own certificates</h3><p>Container App allows us to bring our own SSL certificate. This certificate has to be added to Azure Container App Environment and can be used for all the applications created under this Environment. It is recommended to use wildcard cert, then we can use it for more than 1 application of our Container App Environment</p><blockquote>At the moment is not possible to bring the certificate from Azure Key Vaul, as we can do in other services like App Services. We need to manage the Certificate lifecycle for our applications and run terraform plan after the new cert version is released into KeyVault</blockquote><p>We use Azure Key Vault to store our SSL certificate. Then we need to upload it into our Azure Key Vaul manually and then bring it into our Container App Environment.</p><p>We use <em>azurerm_key_vault_secret</em> data source to obtain our SSL certificate from Azure Key Vault</p><pre>data &quot;azurerm_key_vault_secret&quot; &quot;my_first_app_com&quot; {<br>  name         = &quot;SSL-First-Class-Cert&quot;<br>  key_vault_id = data.azurerm_key_vault.my_first_app.id<br>}</pre><p>we need to add the certificate to our Container App Environment using <em>azurerm_container_app_environment_certificate</em> resource using the <em>azurerm_key_vault_secret data source</em> attributes</p><pre><br>resource &quot;azurerm_container_app_environment_certificate&quot; &quot;my_first_app&quot; {<br>  name                         = &quot;caecer-${local.stack}&quot;<br>  container_app_environment_id = azurerm_container_app_environment.my_first_app.id<br>  certificate_blob_base64      = data.azurerm_key_vault_secret.my_first_app.value<br>  certificate_password         = &quot;&quot;<br><br>  tags = local.default_tags<br>}</pre><p>Azure Key Vault stores our certificates without a password then we have to set the mandatory field <em>certificate_password</em> as an empty string.</p><h3>Create Custom Domain</h3><p>At the moment is it not possible to create a custom domain using Terraform azurerm provider in the case that we want to create the Azure Container App Environment and the Container App in the same Terraform plan.</p><p>The main problem is that <em>custom_domain_verification_id</em> is an attribute provided by <em>azurerm_container_app</em> instead of <em>azurerm_container_app_environment</em>.</p><p>We need to use AzApi to obtain the <em>custom_domain_verification_id</em> and use this value to create the CNAME and TXT DNS record sets.</p><p>Obtain the Azure DNS Zone</p><pre>data &quot;azurerm_dns_zone&quot; &quot;my_first_app_com&quot; {<br>  name                = &quot;my_first_app.com&quot;<br>  resource_group_name = &quot;rg-shared-we&quot;<br>}</pre><h4>Create dns.tf file</h4><pre><br>data &quot;azapi_resource&quot; &quot;my_first_app_container_app_environment&quot; {<br>  resource_id = azurerm_container_app_environment.my_first_app.id<br>  type        = &quot;Microsoft.App/managedEnvironments@2022-11-01-preview&quot;<br><br>  response_export_values = [&quot;properties.customDomainConfiguration.customDomainVerificationId&quot;]<br>}<br><br><br>resource &quot;azurerm_dns_cname_record&quot; &quot;my_first_app&quot; {<br>  name                = &quot;${var.app}-${var.env}&quot;<br>  zone_name           = data.azurerm_dns_zone.my_first_app_com.name<br>  resource_group_name = data.azurerm_dns_zone.my_first_app_com.resource_group_name<br>  ttl                 = 300<br>  record              = &quot;ca-${local.stack}.${azurerm_container_app_environment.my_first_app.default_domain}&quot;<br><br>  tags = local.default_tags<br>}<br><br><br>resource &quot;azurerm_dns_txt_record&quot; &quot;my_first_app&quot; {<br>  name                = &quot;asuid.${var.app}-${var.stage}&quot;<br>  zone_name           = data.azurerm_dns_zone.my_first_app_com.name<br>  resource_group_name = data.azurerm_dns_zone.my_first_app_com.resource_group_name<br>  ttl                 = 300<br><br>  record {<br>    value = jsondecode(data.azapi_resource.my_first_app_container_app_environment.output).properties.customDomainConfiguration.customDomainVerificationId<br>  }<br><br>}<br></pre><p>We need to ensure that our Container app is created after DNS recordsets. Then we need to add the depends_on block for <em>azurerm_dns_cname_record</em> and <em>azurerm_dns_txt_record </em>into<em> azurerm_container_app </em>resource</p><pre>resource &quot;azurerm_container_app&quot; &quot;my_first_app&quot; {<br>...<br><br>  depends_on = [<br>    azurerm_dns_cname_record.my_first_app,<br>    azurerm_dns_txt_record.my_first_app  ]<br>...<br><br>}</pre><p>Now our plan can be executed and the new container app can be accessed using our custom domain</p><h3>Conclusion</h3><p>At this point, we are able to create an application that can be accessed using our custom domain.</p><p>We need to use a workaround using AzApi to obtain the <em>customDomainVerificationId</em> properties because the Azurerm provider does not provide this on Azure Container App Environment.</p><p>The cert rotation has to manage by use. My expectation is that Azure allows us in the future the use Key Valult to bring the certificate instead of uploading it.</p><p>We cam provision a full Container App Environment and Container App using the same plan.</p><h3>Terraform scripts</h3><h4>main.tf</h4><pre>locals {<br>  stack = &quot;${var.app}-${var.env}-${var.location}&quot;<br><br>  default_tags = {<br>    environment = var.env<br>    owner       = &quot;J.Son&quot;<br>    app         = var.app<br>  }<br><br>}<br><br>data &quot;azurerm_key_vault_secret&quot; &quot;my_first_app_com&quot; {<br>  name         = &quot;SSL-First-Class-Cert&quot;<br>  key_vault_id = data.azurerm_key_vault.my_first_app.id<br>}<br><br>resource &quot;azurerm_resource_group&quot; &quot;my_first_app&quot; {<br>  name     = &quot;rg-${local.stack}&quot;<br>  location = var.region<br><br>  tags = local.default_tags<br>}<br><br>resource &quot;azurerm_log_analytics_workspace&quot; &quot;my_first_app&quot; {<br>  name                = &quot;log-${local.stack}&quot;<br>  location            = azurerm_resource_group.my_first_app.location<br>  resource_group_name = azurerm_resource_group.my_first_app.name<br><br>  tags = local.default_tags<br>}<br><br>resource &quot;azurerm_resource_group&quot; &quot;my_first_app&quot; {<br>  name     = &quot;rg-${var.app}-${var.env}-${var.location}&quot;<br>  location = var.region<br>}</pre><h4>container_app.tf</h4><pre>resource &quot;azurerm_container_app_environment&quot; &quot;my_first_app&quot; {<br>  #name                      = &quot;cae-${var.app}-${var.env}-${var.location}&quot;<br>  location                   = azurerm_resource_group.my_first_app.location<br>  resource_group_name        = azurerm_resource_group.my_first_app.name<br>  log_analytics_workspace_id = azurerm_log_analytics_workspace.my_first_app.id<br><br>}<br><br>data &quot;azurerm_key_vault&quot; &quot;my_first_app&quot; {<br>  name                = &quot;kv-${var.app}-${var.env}-${var.location}&quot;<br>  resource_group_name = &quot;rg-${var.app}-${var.env}-${var.location}&quot;<br>}<br><br>resource &quot;azurerm_key_vault_access_policy&quot; &quot;my_first_app&quot; {<br>  key_vault_id = data.my_first_app.id<br>  tenant_id    = azurerm_container_app.my_first_app.identity.0.tenant_id<br>  object_id    = azurerm_container_app.my_first_app.identity.0.principal_id<br>  secret_permissions = [<br>    &quot;get&quot;<br>  ]<br>}<br><br>resource &quot;azurerm_container_app_environment_certificate&quot; &quot;my_first_app&quot; {<br>  name                         = &quot;caecer-${local.stack}&quot;<br>  container_app_environment_id = azurerm_container_app_environment.my_first_app.id<br>  certificate_blob_base64      = data.azurerm_key_vault_secret.my_first_app.value<br>  certificate_password         = &quot;&quot;<br><br>  tags = local.default_tags<br>}<br><br>resource &quot;azurerm_container_app&quot; &quot;my_first_app&quot; {<br>  name                         = &quot;ca-${var.app}-${var.env}-${var.location}&quot;<br><br>  container_app_environment_id = azurerm_container_app_environment.my_first_app.id<br>  resource_group_name          = azurerm_resource_group.my_first_app.name<br>  revision_mode                = &quot;Single&quot;<br><br>  registry {<br>    server               = &quot;docker.io&quot;<br>    username             = &quot;dockerIOUserName&quot;<br>    password_secret_name = &quot;docker-io-pass&quot;<br>  }<br><br>  ingress {<br>    allow_insecure_connections = false<br>    external_enabled           = true<br>    target_port                = 80<br>    traffic_weight {<br>      percentage = 100<br>    }<br><br>  }<br><br>  template {<br>    container {<br>      name   = &quot;${var.prefix}-ca-${var.stage}&quot;<br>      image  = &quot;nginx&quot;<br>      cpu    = 0.25<br>      memory = &quot;0.5Gi&quot;<br>  }<br><br>  identity {<br>    type = &quot;SystemAssigned&quot;<br>  }<br>  <br>  secret { <br>    name  = &quot;docker-io-pass&quot; <br>    value = &quot;$(data.azurerm_key_vault.my_first_app.vault_uri)/secrets/docker-io-pass&quot;<br>  }<br><br>  depends_on = [<br>    azurerm_dns_cname_record.my_first_app,<br>    azurerm_dns_txt_record.my_first_app  <br>  ]<br><br>}</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ba25f7b166f1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Azure Container Apps Container with Terraform (Azure Key Vault for Secrets) [Part 2]]]></title>
            <link>https://medium.com/@vivazmo/azure-container-apps-container-with-terraform-azure-key-vault-for-secrets-part-2-f888d9d682de?source=rss-70ae38d4854------2</link>
            <guid isPermaLink="false">https://medium.com/p/f888d9d682de</guid>
            <category><![CDATA[terraform]]></category>
            <category><![CDATA[azure-container-apps]]></category>
            <category><![CDATA[azure-key-vault]]></category>
            <category><![CDATA[azure]]></category>
            <dc:creator><![CDATA[Xente]]></dc:creator>
            <pubDate>Wed, 17 May 2023 21:24:13 GMT</pubDate>
            <atom:updated>2024-05-09T07:28:43.675Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tj96bM011JKquZKWh8l07A.png" /></figure><p>I am creating a full tutorial for an Azure Container App using Terraform.</p><p>This tutorial has been divided into 3 parts</p><ol><li><a href="https://medium.com/@vivazmo/azure-container-apps-with-terraform-part-1-ae20649e0dff">Create simple App Container using Terraform</a></li><li><strong>Use Azure Key Vault to securitize our secrets</strong></li><li><a href="https://medium.com/@vivazmo/azure-container-apps-container-with-terraform-custom-domain-part-3-ba25f7b166f1">Use custom domain</a></li><li><a href="https://medium.com/@vivazmo/azure-container-apps-container-with-terraform-scaling-rules-part-4-2c29bc1c92">Scaling rules (KEDA)</a></li></ol><blockquote>Side note: this post assumes that you already created the resources of the Create simple App Container using Terraform tutorial</blockquote><h4>Sensistive Data Azuren and Terraform</h4><p>Terraform state can contain sensitive data, depending on the resources in use and your definition of “sensitive.” The state contains resource IDs and all resource attributes. For resources such as App Container Secret, this may contain passwords.</p><p>To manage sensitive data in Terraform we have to ensure that our secrets are not part of our scripts directly.</p><p>My recommendation is to create an Azure Key Vault using the Azcli or the Azure Portal and populate our secrets manually.</p><p>In this way only the state will contains the secrets and never will be storage in your repository</p><h3>Configure Key Vault secrets with our Azure Container App</h3><h4>Create Azure Key Vault and secret</h4><ol><li>C<a href="https://learn.microsoft.com/en-us/azure/key-vault/general/quick-create-portal">reated Azure Key Vault</a> using the Azure Portal</li><li><a href="https://learn.microsoft.com/en-us/azure/key-vault/secrets/quick-create-portal?source=recommendations">Add a secret into Key Vault</a> called <strong><em>docker-io-pass</em></strong> with the value of our Docker.io password</li></ol><h4>Use Azure Key Vault with Container App</h4><p>Create reference to your Azure Key Vault</p><pre>data &quot;azurerm_key_vault&quot; &quot;my_first_app&quot; {<br>  name                = &quot;kv-myappsecrets-${var.env}-${var.location}&quot;<br>  resource_group_name = &quot;rg-myappsecrets-${var.env}-${var.location}&quot;<br>}</pre><p>Create reference to your secret</p><pre>data &quot;azurerm_key_vault_secret&quot; &quot;my_first_app_secret&quot; {<br>  name         = &quot;docker-io-pass&quot;<br>  key_vault_id = data.azurerm_key_vault.my_first_app.id<br>}</pre><p>Using the secret reference into the Container App</p><pre>resource &quot;azurerm_container_app&quot; &quot;my_first_app&quot; {<br>...<br><br>  registry {<br>    server               = &quot;docker.io&quot;<br>    username             = &quot;dockerIOUserName&quot;<br>    password_secret_name = &quot;docker-io-pass&quot;<br>    <br>  }<br><br>...<br>  <br>  secret { <br>    name  = &quot;docker-io-pass&quot; <br>    value = data.azurerm_key_vault_secret.my_first_app_secret.value<br>  }<br><br>}</pre><h4>How to create more secrets</h4><p>If we want to use it for reference to other secrets we only have to</p><ol><li>Create the secret in the Azure Key Vault (eg. <strong><em>database-pass</em></strong>)</li><li>Add secret data source into our terraform script</li><li>Create a secret into azurerm_container_app</li><li>Add secret as env into our Container App</li></ol><pre>data &quot;azurerm_key_vault_secret&quot; &quot;my_first_app_db_pass&quot; {<br>  name         = &quot;database-pass&quot;<br>  key_vault_id = data.azurerm_key_vault.my_first_app.id<br>}<br><br>resource &quot;azurerm_container_app&quot; &quot;my_first_app&quot; {<br>...<br> template {<br>    container {<br>       .....<br>      env {<br>        name        = &quot;db_pass&quot;<br>        secret_name = &quot;database-pass&quot;<br>      }<br>     }<br>  }<br>...<br>  <br>  secret { <br>    name  = &quot;database-pass&quot; <br>    value = data.azurerm_key_vault_secret.my_first_app_db_pass.value<br>  }<br><br>}</pre><h3>Conclusion</h3><p>Now we can use Azure keyvault secrets in our Container App. It is not the best approach that at less no more secretes are neede in our repository code.</p><h3>Terraform scripts</h3><h4>main.tf</h4><pre><br>locals {<br>  stack = &quot;${var.app}-${var.env}-${var.location}&quot;<br><br>  default_tags = {<br>    environment = var.env<br>    owner       = &quot;J.Son&quot;<br>    app         = var.app<br>  }<br><br>}<br><br>resource &quot;azurerm_resource_group&quot; &quot;my_first_app&quot; {<br>  name     = &quot;rg-${local.stack}&quot;<br>  location = var.region<br><br>  tags = local.default_tags<br>}<br><br>data &quot;azurerm_key_vault_secret&quot; &quot;my_first_app_secret&quot; {<br>  name         = &quot;docker-io-pass&quot;<br>  key_vault_id = data.azurerm_key_vault.my_first_app.id<br>}<br><br>resource &quot;azurerm_log_analytics_workspace&quot; &quot;my_first_app&quot; {<br>  name                = &quot;log-${local.stack}&quot;<br>  location            = azurerm_resource_group.my_first_app.location<br>  resource_group_name = azurerm_resource_group.my_first_app.name<br><br>  tags = local.default_tags<br>}<br><br>resource &quot;azurerm_resource_group&quot; &quot;my_first_app&quot; {<br>  name     = &quot;rg-${var.app}-${var.env}-${var.location}&quot;<br>  location = var.region<br>}</pre><h4>container_app.tf</h4><pre>resource &quot;azurerm_container_app_environment&quot; &quot;my_first_app&quot; {<br>  #name                      = &quot;cae-${var.app}-${var.env}-${var.location}&quot;<br>  location                   = azurerm_resource_group.my_first_app.location<br>  resource_group_name        = azurerm_resource_group.my_first_app.name<br>  log_analytics_workspace_id = azurerm_log_analytics_workspace.my_first_app.id<br><br>}<br><br><br>resource &quot;azurerm_container_app&quot; &quot;my_first_app&quot; {<br>  name                         = &quot;ca-${var.app}-${var.env}-${var.location}&quot;<br><br>  container_app_environment_id = azurerm_container_app_environment.my_first_app.id<br>  resource_group_name          = azurerm_resource_group.my_first_app.name<br>  revision_mode                = &quot;Single&quot;<br><br>  registry {<br>    server               = &quot;docker.io&quot;<br>    username             = &quot;dockerIOUserName&quot;<br>    password_secret_name = &quot;docker-io-pass&quot;<br>  }<br><br>  ingress {<br>    allow_insecure_connections = false<br>    external_enabled           = true<br>    target_port                = 80<br>    traffic_weight {<br>      percentage = 100<br>    }<br><br>  }<br><br>  template {<br>    container {<br>      name   = &quot;${var.prefix}-ca-${var.stage}&quot;<br>      image  = &quot;nginx&quot;<br>      cpu    = 0.25<br>      memory = &quot;0.5Gi&quot;<br>  }<br><br>  identity {<br>    type = &quot;SystemAssigned&quot;<br>  }<br>  <br>  secret { <br>    name  = &quot;docker-io-pass&quot; <br>    value = data.azurerm_key_vault_secret.my_first_app_secret.value<br>  }<br><br>}</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f888d9d682de" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Azure Container Apps with Terraform]]></title>
            <link>https://medium.com/@vivazmo/azure-container-apps-with-terraform-part-1-ae20649e0dff?source=rss-70ae38d4854------2</link>
            <guid isPermaLink="false">https://medium.com/p/ae20649e0dff</guid>
            <category><![CDATA[azure-container-apps]]></category>
            <category><![CDATA[azure]]></category>
            <category><![CDATA[terraform]]></category>
            <dc:creator><![CDATA[Xente]]></dc:creator>
            <pubDate>Wed, 17 May 2023 21:22:51 GMT</pubDate>
            <atom:updated>2024-12-21T10:35:03.682Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tj96bM011JKquZKWh8l07A.png" /></figure><p>Azure Container App using Terraform <strong>azurerm </strong>provider</p><ol><li><strong>Create simple App Container using Terraform</strong></li><li><a href="https://medium.com/@vivazmo/azure-container-apps-container-with-terraform-azure-key-vault-for-secrets-part-2-f888d9d682de">Use Azure KeyVault to securitize our secrets</a></li><li><a href="https://medium.com/@vivazmo/azure-container-apps-container-with-terraform-custom-domain-part-3-ba25f7b166f1">Use custom domain</a></li><li><a href="https://medium.com/@vivazmo/azure-container-apps-container-with-terraform-scaling-rules-part-4-2c29bc1c92">Scaling rules (KEDA)</a></li></ol><blockquote>Side note: this post assumes that you already understand what Terraform is and know the basics of it.</blockquote><h3>Container App in Terraform provider</h3><p>Container App resources were added into Terraform <strong>azurerm</strong> provided since version <a href="https://github.com/hashicorp/terraform-provider-azurerm/releases/tag/v3.43.0">v3.43.0</a>.</p><p>In this version the added the next</p><ul><li>New Data Source: azurerm_container_app_environment</li><li>New Data Source: azurerm_container_app_environment_certificate</li><li>New Resource: azurerm_container_app_environment</li><li>New Resource: azurerm_container_app_environment_storage</li><li>New Resource: azurerm_container_app_environment_dapr_component</li><li>New Resource: azurerm_container_app_environment_certificate</li><li>New Resource: azurerm_container_app</li></ul><h3>What is an Azure Container App?</h3><p>Azure Container Apps is a fully managed environment that enables you to run microservices and containerized applications on a serverless platform.</p><p>Applications built on Azure Container Apps can dynamically scale based on the following characteristics:</p><ul><li>HTTP traffic</li><li>Event-driven processing</li><li>CPU or memory load</li><li>Any <a href="https://keda.sh/docs/scalers/">KEDA-supported scaler</a></li></ul><h3>Features</h3><p>With Azure Container Apps, you can:</p><ul><li>Enable HTTPS or TCP ingress without having to manage other Azure infrastructure.</li><li>Build microservices with Dapr and access its rich set of APIs.</li><li>Run multiple container revisions and manage the container app’s application lifecycle.</li><li>Split traffic across multiple versions of an application for Blue/Green deployments and A/B testing scenarios.</li><li>Use internal ingress and service discovery for secure internal-only endpoints with built-in DNS-based service discovery.</li><li>Run containers from any registry, public or private, including Docker Hub and Azure Container Registry (ACR).</li><li>Provide an existing virtual network when creating an environment for your container apps.</li><li>Securely manage secrets directly in your application.</li></ul><h3>Prerequisites</h3><p>You <em>must</em> have the following ready</p><ul><li>Azure Account</li><li><a href="https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/guides/service_principal_client_secret#creating-a-service-principal">Service Principal</a></li></ul><h3>Bootstrap the project</h3><p>Create Terraform project using the next project structure:</p><pre>.<br>├── README.md<br>├── main.tf<br>├── container_app.tf<br>├── variables.tf<br>├── outputs.tf<br>├── provider.tf</pre><h4>Create provider.tf:</h4><p>This file contains all the providers used in our project. In this case, we only use one but in other cases where we need more than one provider is easy to find grouping all together into the same file.</p><pre>terraform {<br>  required_providers {<br>    azurerm = {<br>      source  = &quot;hashicorp/azurerm&quot;<br>      version = &quot;=3.52.0&quot;<br>    }<br>  }<br>}<br><br>provider &quot;azurerm&quot; {<br>  features {}<br>}</pre><h4>Create variables.tf</h4><p>This file contains all the variables that we need.</p><pre>variable &quot;region&quot; {<br>  description = &quot;Azure infrastructure region&quot;<br>  type    = string<br>  default = &quot;westeurope&quot;<br>}<br><br>variable &quot;app&quot; {<br>  description = &quot;Application that we want to deploy&quot;<br>  type    = string<br>  default = &quot;myapp&quot;<br>}<br><br>variable &quot;env&quot; {<br>  description = &quot;Application env&quot;<br>  type    = string<br>  default = &quot;dev&quot;<br>}<br><br>variable &quot;location&quot; {<br>  description = &quot;Location short name &quot;<br>  type    = string<br>  default = &quot;we&quot;<br>}</pre><h4>Create main.tf</h4><p>This file contains the global resources and local variables.</p><pre>locals {<br>  stack = &quot;${var.app}-${var.env}-${var.location}&quot;<br><br>  default_tags = {<br>    environment = var.env<br>    owner       = &quot;J.Son&quot;<br>    app         = var.app<br>  }<br><br>}<br><br>resource &quot;azurerm_resource_group&quot; &quot;my_first_app&quot; {<br>  name     = &quot;rg-${local.stack}&quot;<br>  location = var.region<br><br>  tags = local.default_tags<br>}<br><br>resource &quot;azurerm_log_analytics_workspace&quot; &quot;my_first_app&quot; {<br>  name                = &quot;log-${local.stack}&quot;<br>  location            = azurerm_resource_group.my_first_app.location<br>  resource_group_name = azurerm_resource_group.my_first_app.name<br><br>  tags = local.default_tags<br>}</pre><h4>Create container_app.tf</h4><p>This file contains all resources needed to create our container app</p><p>For creating Container App next resources are mandatory:</p><ol><li>Create Azure <strong>Log Analytics Workspace</strong>. <strong>Log Analytics Workspace is required for version &lt; 3.69.0. For upper versions now is optional</strong></li><li>Create <strong>Container App Environment</strong>. A Container Apps environment is a secure boundary around groups of container apps that share the same virtual network and write logs to the same logging destination.</li><li>Create <strong>Container App</strong>. The resource that contains all the configurations for our Docker Container.</li></ol><p><strong>Create Container App Environment</strong></p><pre>resource &quot;azurerm_container_app_environment&quot; &quot;my_first_app&quot; {<br>  name                      = &quot;cae-${local.stack}&quot;<br>  location                   = azurerm_resource_group.my_first_app.location<br>  resource_group_name        = azurerm_resource_group.my_first_app.name<br>  log_analytics_workspace_id = azurerm_log_analytics_workspace.my_first_app.id<br><br>  tags = local.default_tags<br>}</pre><p>We can use public images or private images. In the next script the two options are implemented, You can choose the best option for you</p><p><strong>Create Container App with a public image</strong></p><pre>resource &quot;azurerm_container_app&quot; &quot;my_first_app&quot; {<br>  name                         = &quot;ca-${local.stack}&quot;<br><br>  container_app_environment_id = azurerm_container_app_environment.my_first_app.id<br>  resource_group_name          = azurerm_resource_group.my_first_app.name<br>  revision_mode                = &quot;Single&quot;<br><br>  registry {<br>    server               = &quot;docker.io&quot;    <br>  }<br><br>  ingress {<br>    allow_insecure_connections = false<br>    external_enabled           = true<br>    target_port                = 80<br>    traffic_weight {<br>      percentage = 100<br>    }<br><br>  }<br><br>  template {<br>    container {<br>      name   = &quot;ca-${local.stack}&quot;<br>      image  = &quot;hello-world:latest&quot;<br>      cpu    = 0.25<br>      memory = &quot;0.5Gi&quot;<br>    }<br>  }<br><br>  tags = local.default_tags<br><br>}</pre><p><strong>Create Container App with a Private Registry</strong></p><pre>resource &quot;azurerm_container_app&quot; &quot;my_first_app&quot; {<br>  name                         = &quot;ca-${local.stack}&quot;<br><br>  container_app_environment_id = azurerm_container_app_environment.my_first_app.id<br>  resource_group_name          = azurerm_resource_group.my_first_app.name<br>  revision_mode                = &quot;Single&quot;<br><br>  registry {<br>    server               = &quot;docker.io&quot;<br>    username             = &quot;dockerIOUserName&quot;<br>    password_secret_name = &quot;docker-io-pass&quot;<br>    <br>  }<br><br>  ingress {<br>    allow_insecure_connections = false<br>    external_enabled           = true<br>    target_port                = 80<br>    traffic_weight {<br>      percentage = 100<br>    }<br><br>  }<br><br>  template {<br>    container {<br>      name   = &quot;ca-${local.stack}&quot;<br>      image  = &quot;test/myapp&quot;<br>      cpu    = 0.25<br>      memory = &quot;0.5Gi&quot;<br>  }<br>  <br>  secret { <br>    name  = &quot;docker-io-pass&quot; <br>    value = &quot;MyDockerIOPass&quot; <br>  }<br><br>  tags = local.default_tags<br><br>}</pre><p>When a registry with credentials is used we need to add a secret block with the password and reference it into the <em>password_secret_name</em> property.</p><h4>Create <a href="https://outputs.tf/">outputs</a>.tf</h4><pre>output &quot;azurerm_container_app_url&quot; {<br>  value = azurerm_container_app.my_first_app.latest_revision_fqdn<br>}</pre><h3>Deploy infrastructure</h3><p>Now our infrastructure is ready to be used. We only need to run the Terraform apply command and deploy it.</p><p>Init Terraform project</p><pre>terraform init</pre><p>Apply Terraform plan</p><pre>terraform apply</pre><h3>Test Application</h3><p>When the application is deployed we can now access our application using the URL provided by the output <em>azurerm_container_app_url</em>.</p><h3>Conclusion</h3><p>It is great that the <strong>azurerm</strong> provider now supports Azure Container Apps and we are not more needed the AzApi provider for that. It will be easy to integrate into our current Terraform projects.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ae20649e0dff" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Using Loguru with Grafana Loki]]></title>
            <link>https://medium.com/@vivazmo/using-loguru-with-grafana-loki-1181d28c2d1a?source=rss-70ae38d4854------2</link>
            <guid isPermaLink="false">https://medium.com/p/1181d28c2d1a</guid>
            <category><![CDATA[logs]]></category>
            <category><![CDATA[loki]]></category>
            <category><![CDATA[grafana]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[Xente]]></dc:creator>
            <pubDate>Sun, 16 Apr 2023 11:23:26 GMT</pubDate>
            <atom:updated>2023-11-06T15:38:22.348Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/538/1*7m457wSxZBeJSJYKms8QJw.png" /></figure><p><a href="https://github.com/Delgan/loguru"><strong>Loguru</strong></a> is a library that makes logging in to Python simple.</p><p>It provides us with a lot of features:</p><ul><li><a href="https://github.com/Delgan/loguru#ready-to-use-out-of-the-box-without-boilerplate">Ready to use out of the box without boilerplate</a></li><li><a href="https://github.com/Delgan/loguru#no-handler-no-formatter-no-filter-one-function-to-rule-them-all">No Handler, no Formatter, no Filter: one function to rule them all</a></li><li><a href="https://github.com/Delgan/loguru#easier-file-logging-with-rotation-retention-compression">Easier file logging with rotation / retention / compression</a></li><li><a href="https://github.com/Delgan/loguru#modern-string-formatting-using-braces-style">Modern string formatting using braces style</a></li><li><a href="https://github.com/Delgan/loguru#exceptions-catching-within-threads-or-main">Exceptions catching within threads or main</a></li><li><a href="https://github.com/Delgan/loguru#pretty-logging-with-colors">Pretty logging with colors</a></li><li><a href="https://github.com/Delgan/loguru#asynchronous-thread-safe-multiprocess-safe">Asynchronous, Thread-safe, Multiprocess-safe</a></li><li><a href="https://github.com/Delgan/loguru#fully-descriptive-exceptions">Fully descriptive exceptions</a></li><li><a href="https://github.com/Delgan/loguru#structured-logging-as-needed">Structured logging as needed</a></li><li><a href="https://github.com/Delgan/loguru#lazy-evaluation-of-expensive-functions">Lazy evaluation of expensive functions</a></li><li><a href="https://github.com/Delgan/loguru#customizable-levels">Customizable levels</a></li><li><a href="https://github.com/Delgan/loguru#better-datetime-handling">Better datetime handling</a></li><li><a href="https://github.com/Delgan/loguru#suitable-for-scripts-and-libraries">Suitable for scripts and libraries</a></li><li><a href="https://github.com/Delgan/loguru#entirely-compatible-with-standard-logging">Entirely compatible with standard logging</a></li><li><a href="https://github.com/Delgan/loguru#personalizable-defaults-through-environment-variables">Personalizable defaults through environment variables</a></li><li><a href="https://github.com/Delgan/loguru#convenient-parser">Convenient parser</a></li><li><a href="https://github.com/Delgan/loguru#exhaustive-notifier">Exhaustive notifier</a></li></ul><p><a href="https://github.com/grafana/loki"><strong>Loki</strong></a> is a horizontally-scalable, highly-available, multi-tenant log aggregation system inspired by <a href="https://prometheus.io/">Prometheus</a>. It is designed to be very cost-effective and easy to operate. It does not index the contents of the logs, but rather a set of labels for each log stream.</p><p>Both tools are great, but there is no integration of Loguru with Loki. For this reason, I have created a Loguru handler that allows us to join both tools in an easy way.</p><h3>Loki Logger Handlers</h3><p><a href="https://github.com/xente/loki-logger-handler">Loki Logger Handlers</a> is a handler created for Loguru and Logger that sends logs to Grafana Loki in JSON format</p><h4><strong>Features</strong></h4><ul><li>Logs pushed in JSON format</li><li>Custom labels definition</li><li>Allows defining Loguru and logger extra keys as labels</li><li>Logger extra keys are added automatically as keys into pushed JSON</li><li>Send logs in batch to Loki</li><li>Send logs compressed to Loki</li></ul><h4>How to use with Loguru</h4><ol><li>Install Loguru: <em>pip install loguru</em></li><li>Install loki-logger-handler: <em>pip install loki-logger-handler</em></li><li>Import Loguru library</li><li>Import LokiLoggerHandler and LoguruFormatter</li><li>Define Loki push URL of our Loki server.</li><li>Configure Loguru with LokiLoggerHandler</li></ol><h4>Configure</h4><p>Loki Handler can be configured with:</p><ul><li>URL: Loki push URL with credentials</li><li>labels: list of fixed Loki labels. Sample “application”: “MyApp”. These labels will appear in our Loki logs system</li><li>labelKeys: List of keys that Loguru keys that can be defined as Loki label: message, timestamp, process, thread, function, module, name, and logger extra keys</li><li>timeout (int, optional): The time in seconds to wait before flushing the buffer. Defaults to 10.</li><li>defaultFormatter (logging.Formatter, optional): The formatter to use for log messages. Defaults to LoggerFormatter().</li></ul><pre>from loki_logger_handler.loki_logger_handler import LokiLoggerHandler, LoguruFormatter<br>from loguru import logger<br>import os<br><br>os.environ[<br>    &quot;LOKI_URL&quot;<br>] = &quot;https://USER:PASSWORD@logs-prod-eu-west-0.grafana.net/loki/api/v1/push&quot;<br><br>custom_handler = LokiLoggerHandler(<br>    url=os.environ[&quot;LOKI_URL&quot;],<br>    labels={&quot;application&quot;: &quot;MyApp&quot;},<br>    labelKeys={},<br>    timeout=10,<br>    defaultFormatter=LoguruFormatter(),<br>)<br><br>logger.configure(handlers=[{&quot;sink&quot;: custom_handler, &quot;serialize&quot;: True}])<br><br>logger.info(<br>    &quot;Response code {code} HTTP/1.1 GET {url}&quot;, code=200, url=&quot;https://loki_handler.io&quot;<br>)</pre><h4>How to use with Logger</h4><ol><li>Install loki-logger-handler: <em>pip install loki-logger-handler</em></li><li>Import LokiLoggerHandler</li><li>Define Loki push URL of our Loki server.</li><li>Configure Loguru with LokiLoggerHandler</li></ol><h4>Configure</h4><p>Loki Handler can be configured with:</p><ul><li>URL: Loki push URL with credentials</li><li>labels: list of fixed Loki labels. Sample “application”: “MyApp”. These labels will appear in our Loki logs system</li><li>labelKeys: List of keys that Loguru keys that can be defined as Loki label: message, timestamp, process, thread, function, module, name, and logger extra keys</li><li>timeout (int, optional): The time in seconds to wait before flushing the buffer. Defaults to 10.</li><li>defaultFormatter (logging.Formatter, optional): The formatter to use for log messages. Defaults to LoggerFormatter().</li></ul><pre>from loki_logger_handler.loki_logger_handler import LokiLoggerHandler,<br>import logging<br>import os <br><br># Set up logging<br>logger = logging.getLogger(&quot;custom_logger&quot;)<br>logger.setLevel(logging.DEBUG)<br><br># Create an instance of the custom handler<br>custom_handler = LokiLoggerHandler(<br>    url=os.environ[&quot;LOKI_URL&quot;],<br>    labels={&quot;application&quot;: &quot;MyApp&quot;},<br>    labelKeys={},<br>    timeout=10,<br>)<br># Create an instance of the custom handler<br><br>logger.addHandler(custom_handler)<br>logger.debug(f&quot;Response code {code} HTTP/1.1 GET {url}&quot;, extra={&#39;code&#39;: 200,&#39;url&#39;:&quot;https://loki_handler.io })</pre><h4>Messages to Loki</h4><p>When the handler is enabled all the logs generated into the application are managed by it and are sent to the Loki server in JSON format.</p><p><strong>Without extra:</strong></p><pre>logger.info(&quot;Starting service&quot;)</pre><pre>{<br>  &quot;message&quot;: &quot;Starting service&quot;,<br>  &quot;timestamp&quot;: 1681638266.542849,<br>  &quot;process&quot;: 48906,<br>  &quot;thread&quot;: 140704422327936,<br>  &quot;function&quot;: &quot;run&quot;,<br>  &quot;module&quot;: &quot;test&quot;,<br>  &quot;name&quot;: &quot;__main__&quot;<br>}</pre><p><strong>With extra:</strong></p><p>when we use templates for our logs Loki handler adds these extra keys into our JSON message automatically. It provides us the possibility to look for these keys using the Loki label filter expression</p><pre>logger.info(<br>    &quot;Response code {code} HTTP/1.1 GET {url}&quot;, code=200, url=&quot;https://loki_handler.io&quot;<br>)</pre><pre>{<br>  &quot;message&quot;: &quot;Request return 200 HTTP/1.1 GET https://loki_handler.io&quot;,<br>  &quot;timestamp&quot;: 1681638225.877143,<br>  &quot;process&quot;: 48870,<br>  &quot;thread&quot;: 140704422327936,<br>  &quot;function&quot;: &quot;run&quot;,<br>  &quot;module&quot;: &quot;test&quot;,<br>  &quot;name&quot;: &quot;__main__&quot;,<br>  &quot;code&quot;: 200,<br>  &quot;url&quot;: &quot;https://loki_handler.io&quot;<br>}</pre><p><strong>Exceptions:</strong></p><pre>logger.exception(e)</pre><pre>{<br>  &quot;message&quot;: &quot;name &#39;test&#39; is not defined&quot;,<br>  &quot;timestamp&quot;: 1681638284.358464,<br>  &quot;process&quot;: 48906,<br>  &quot;thread&quot;: 140704422327936,<br>  &quot;function&quot;: &quot;run&quot;,<br>  &quot;module&quot;: &quot;test&quot;,<br>  &quot;name&quot;: &quot;__main__&quot;,<br>  &quot;file&quot;: &quot;test.py&quot;,<br>  &quot;path&quot;: &quot;/test.py&quot;,<br>  &quot;line&quot;: 39<br>}</pre><h4>Loki Query Sample</h4><p>Filter by label:</p><pre>{environment=&quot;Develop&quot;} |= `` | json</pre><p>Filter by the label filter expression</p><pre>{environment=&quot;Develop&quot;, level=&quot;INFO&quot;} |= `` | json | code=`200`</pre><h3>Conclusion</h3><p>This handle can provide an easy way to integrate your current Python code with Loki.</p><p>I am happy to share it with the community.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1181d28c2d1a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Terraform Cloud Authenticate Providers with Dynamic Credentials for AWS]]></title>
            <link>https://medium.com/@vivazmo/terraform-cloud-dynamic-credentials-for-aws-e492efaf529d?source=rss-70ae38d4854------2</link>
            <guid isPermaLink="false">https://medium.com/p/e492efaf529d</guid>
            <category><![CDATA[security]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[terraform-cloud]]></category>
            <category><![CDATA[devops]]></category>
            <dc:creator><![CDATA[Xente]]></dc:creator>
            <pubDate>Wed, 15 Mar 2023 22:45:17 GMT</pubDate>
            <atom:updated>2023-03-15T22:54:32.821Z</atom:updated>
            <cc:license>http://creativecommons.org/publicdomain/zero/1.0/</cc:license>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*FHHa7QjU4PC11_FV.jpg" /></figure><p>Using the AWS credentials (client_id and client_secret_id) in our terraform workspace provides an easy way to create our infrastructure under AWS with a simple configuration.</p><p>This kind of authentication has several problems from a security perspective.</p><ul><li>We can not enable MFA for that users</li><li>We have to store our credentials in an external provider like Terraform Cloud</li><li>We need to manage and rotate credentials</li></ul><p>For that reason, this kind of auth is not fully recommended from a security perspective.</p><p>Terraform Team has provided us with other credentials mechanisms called Dynamic Provider Credentials.</p><h3><strong>Dynamic Provider Credentials</strong></h3><p>Using Dynamic Provider Credentials Terraform Cloud uses a <a href="https://developer.hashicorp.com/terraform/cloud-docs/workspaces/dynamic-provider-credentials/workload-identity-tokens"><em>workload identity token</em></a> that is compliant with OpenID Connect protocol (OIDC) to provide temporal access to our AWS resources.</p><h3><strong>AWS and Terraform workspace configuration</strong></h3><p><strong>Create a new Identity provider for your AWS account.</strong></p><p>1- Go to IAM Console</p><p>2- Access to Identity providers:</p><ul><li>Select OpenID Connect</li><li>Provider <a href="https://app.terraform.io/"><em>https://app.terraform.io</em></a></li><li>Audience <em>aws.workload.identity</em></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/774/1*WjuGGHoOV09SoX7WU9cgdg.png" /></figure><p>Create a Web identity Role with permission policies needed to operate our infrastructure</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bzhnCL6qgsdU0TWYV_beuQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*f25rkoMq8-Oi1mhhnDC1Ug.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*T7P4i5ZG_QCEmJCAld0l3g.png" /></figure><blockquote>By default, the role allows connection from Terraform Cloud organization<strong>.</strong></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/814/1*jiUyVr22p5qOtipn6fFrdg.png" /></figure><p>We need to prevent unauthorized access by adding a condition for sub Claim.</p><blockquote><strong>sub</strong> : Fully qualified path to a workspace, followed by the run phase. For example: organization:my-organization-name:project:Default Project:workspace:my-workspace-name:run_phase:apply</blockquote><p>Then our trust relationships rule has to be populated with a conditioning base on sub claim “app.terraform.io:sub”. For example, we can limit access for:</p><ul><li>Organization: my-organization</li><li>Project: api</li><li>Workspace: prod</li><li>Phase: * (plan or apply)</li></ul><pre>{<br>    &quot;Version&quot;: &quot;2012-10-17&quot;,<br>    &quot;Statement&quot;: [<br>        {<br>            &quot;Effect&quot;: &quot;Allow&quot;,<br>            &quot;Principal&quot;: {<br>                &quot;Federated&quot;: &quot;arn:aws:iam::000000000:oidc-provider/app.terraform.io&quot;<br>            },<br>            &quot;Action&quot;: &quot;sts:AssumeRoleWithWebIdentity&quot;,<br>            &quot;Condition&quot;: {<br>                &quot;StringEquals&quot;: {<br>                    &quot;app.terraform.io:aud&quot;: &quot;aws.workload.identity&quot;,<br>                    &quot;app.terraform.io:sub&quot;: &quot;organization:my-organization:project:api:workspace:prod:run_phase:*&quot;<br>                }<br>            }<br>        }<br>    ]<br>}</pre><p>You can use wildcards to filter the sub Claim. It can provide the possibility to use the same policy for different workspaces that need the same policy to operate under the same AWS account</p><pre>{<br>    &quot;Version&quot;: &quot;2012-10-17&quot;,<br>    &quot;Statement&quot;: [<br>        {<br>            &quot;Effect&quot;: &quot;Allow&quot;,<br>            &quot;Principal&quot;: {<br>                &quot;Federated&quot;: &quot;arn:aws:iam::000000000:oidc-provider/app.terraform.io&quot;<br>            },<br>            &quot;Action&quot;: &quot;sts:AssumeRoleWithWebIdentity&quot;,<br>            &quot;Condition&quot;: {<br>                &quot;StringEquals&quot;: {<br>                    &quot;app.terraform.io:aud&quot;: &quot;aws.workload.identity&quot;<br>                },<br>                &quot;StringLike&quot;: {<br>                    &quot;app.terraform.io:sub&quot;: &quot;organization:my-organization-name:project:api:workspace:prod-*:run_phase:*&quot;<br>                }<br>            }<br>        }<br>    ]<br>}</pre><p>In the code, we can see that only workspaces that start with prod- and are under api project can use this role.</p><p><strong>Configure your Terraform Workspace</strong></p><p>To enable dynamic credentials under our terraform workspace we only need to create 2 environment variables:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/688/1*IPvES4NZ7wrVNoUyg8tTEw.png" /></figure><p>We can use different roles per plans and apply the phases terraform provide to our next group of variables for that proposal:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/688/1*IPvES4NZ7wrVNoUyg8tTEw.png" /></figure><p><em>That it! Simple configuration.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e492efaf529d" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>