<?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 Siddharth Satpute on Medium]]></title>
        <description><![CDATA[Stories by Siddharth Satpute on Medium]]></description>
        <link>https://medium.com/@sid2631?source=rss-22f4ef672231------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*oAtfGbSJny2W8tYHZGCsog.jpeg</url>
            <title>Stories by Siddharth Satpute on Medium</title>
            <link>https://medium.com/@sid2631?source=rss-22f4ef672231------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 05:19:40 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@sid2631/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[Provisioning GCP Resources with Terraform & Azure DevOps]]></title>
            <link>https://medium.com/google-cloud/provisioning-google-cloud-resources-using-terraform-and-azure-devops-with-workload-identity-bbd2ad4d2cd6?source=rss-22f4ef672231------2</link>
            <guid isPermaLink="false">https://medium.com/p/bbd2ad4d2cd6</guid>
            <category><![CDATA[google-cloud-platform]]></category>
            <category><![CDATA[infrastructure]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[azure]]></category>
            <category><![CDATA[terraform]]></category>
            <dc:creator><![CDATA[Siddharth Satpute]]></dc:creator>
            <pubDate>Sun, 20 Oct 2024 13:41:01 GMT</pubDate>
            <atom:updated>2024-12-21T09:51:07.003Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zn75ZWeQ2XlkmWiRr0wGRw.jpeg" /></figure><p>In this blog post, we’ll explore how to provision Google Cloud Platform (GCP) resources using Terraform via Azure DevOps pipelines. Specifically, we’ll focus on leveraging Workload Identity Federation, which allows external workloads to access GCP resources without requiring a service account key.</p><h3>Agenda</h3><ol><li>Introduction</li><li>Overview</li><li>Architecture</li><li>Prerequisites</li><li>Configuration on Azure DevOps and Azure<br>- Create a Service Connection</li><li>Agent pool in Azure DevOps<br>- Create a Agent Pool<strong><br>- </strong>Set up the agent</li><li>Configuration on Google Cloud<br>- Permissions to Configure Workload Identity<br>- Configure Workload Identity using gcloud<br>- Configure Workload Identity using Console<br>- Grant external identity access to impersonate the service account</li><li>Configuring the pipeline on Azure DevOps</li><li>Conclusion</li></ol><h3>Overview</h3><p>There are two approaches for provisioning Google Cloud Platform (GCP) resources through Azure DevOps:</p><ol><li><strong>Using Service Account Keys</strong></li><li><strong>Using Workload Identity Federation</strong></li></ol><p>In this blog post, we focus on the second approach, i.e. provisioning GCP resources with Terraform using Workload Identity Federation. This method leverages OAuth 2.0 token exchange to authenticate external workloads securely, eliminating the need for static service account keys. It offers a more secure and efficient way to manage cloud resources, ensuring that sensitive credentials are not exposed or mismanaged.</p><h3><strong>Architecture</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*uMbQtV6lBC7KQM1Z" /></figure><p>The architecture for this setup includes:</p><ol><li><strong>Azure DevOps Pipeline</strong>: Configured to use a self-hosted agent that executes Terraform commands.</li><li><strong>Google Cloud Workload Identity Federation</strong>: Facilitates secure authentication without the need for static service account keys.</li></ol><h3>Prerequisites</h3><p>Before setting up the pipeline, ensure you have:</p><ul><li>An Azure Subscription and Resource Group</li><li>Access to the Azure Cloud Console</li><li>Access to Azure DevOps Pipeline</li><li>Basic knowledge of Terraform and Google Cloud</li></ul><h3>Configuration on Azure DevOps and Azure</h3><p><strong>Create a Service Connection</strong></p><ol><li><strong>Log in to Azure DevOps</strong>: Navigate to the project where you want to create the service connection.</li><li><strong>Create a New Service Connection</strong>: Go to Project settings &gt; Service connections &gt; New service connection.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*fD5WY63zopu7fGk9" /></figure><p><strong>3. Select Azure Resource Manager</strong>: Choose Workload Identity Federation. (automatic) as the authentication method.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*1JNlS_fHNWbYgg_C" /></figure><p>4. <strong>Enter Required Details</strong>: Provide the subscription, resource group, service connection name, and description.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*wik6kFW__23uVS8D" /></figure><p>5. <strong>Manage Service Principal</strong>: Navigate to Manage Service Principal, then Certificates and secrets</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*-8UQQAAE9MZb4TbT" /></figure><p>6. Go to <strong>Certificates &amp; Secrets</strong> in the App Registration section. Then, navigate to <strong>Federated Credentials</strong>. Click on <strong>Federated Credentials</strong> and make a note of the <strong>Issuer</strong>, <strong>Subject Identifier</strong>, and <strong>Audience</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tN9xXhoCqLNeOVmGD7jDGA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*y4kVR-1pku56omjK7nu39w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3tfLmIDAhyspWzlZ9m0zWg.png" /></figure><h3>Agent pool in Azure DevOps</h3><p><strong>Create a Agent Pool</strong>: <br>1. Go toProject settings &gt; Agent pools &gt; add pool.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*-cOkRXXaDtFQ2xHW" /></figure><p>2. Choose Self-hosted and provide a name for the agent pool</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*oELJUzLU3veEETOU" /></figure><p>3. Add a new agent by following the prompts.</p><p><strong>Set Up the Agent</strong>:</p><ol><li>Create a Linux VM on Azure and run the following commands:</li></ol><pre>wget https://vstsagentpackage.azureedge.net/agent/3.239.1/vsts-agent-linux-x64-3.239.1.tar.gz<br>tar zxvf vsts-agent-linux-x64-3.239.1.tar.gz<br>./config.sh </pre><p>2. After running the config.sh file , provide the following inputs</p><pre>Server URL: https://dev.azure.com/&lt; organization name&gt;<br>Personal access token: &lt;Provide your users personal access token&gt;<br>Agent pool name: &lt;Enter name of the agent pool which was created in the earlier steps&gt;<br>Agent name: &lt;Enter any name of your choice&gt;<br>Work folder: &lt;Enter the path of azure devops working directory</pre><p>3. Verify the agent is registered in the agent pool on Azure DevOps console.</p><p>4.<strong> Install Prerequisites</strong>: Ensure Git and Azure CLI are installed</p><pre>sudo apt-get update &amp;&amp; sudo apt-get install git -y<br><br>curl -sL https://aka.ms/InstallAzureCLIDeb | sudo bash</pre><h3>Configuration on Google Cloud</h3><h4>Permissions to Configure Workload Identity</h4><p>To configure Workload Identity Federation on Google Cloud, you need to ensure that the user performing these actions has the necessary permissions. Specifically, the user requires the following IAM roles:</p><ul><li><strong>roles/iam.serviceAccountAdmin</strong>: This role allows the user to create and manage service accounts.</li><li><strong>roles/iam.workloadIdentityPoolAdmin</strong>: This role allows the user to create and manage Workload Identity Pools and Providers.</li></ul><h4>Configure Workload Identity using gcloud</h4><ul><li>Create the workload identity pool and provider using the below gcloud commands.</li></ul><pre>gcloud iam workload-identity-pools create azure \<br>    --location=&quot;global&quot; \<br>    --display-name=&quot;Azure&quot;<br><br>gcloud iam workload-identity-pools providers create-oidc azure \<br>    --location=&quot;global&quot; \<br>    --workload-identity-pool=&quot;azure&quot; \<br>    --issuer-uri=&quot;&lt;ISSUER URI&gt;&quot; \<br>    --attribute-mapping=&quot;google.subject=assertion.sub&quot; \<br>    --allowed-audiences=&quot;&lt;ALLOWED AUDIENCE&gt;&quot;</pre><ul><li>Replace the <strong>ISSUER URI</strong> and <strong>ALLOWED</strong> <strong>AUDIENCES</strong> with the values we noted</li><li>Create the service account and provide the Workload Identity User role to the service account.</li></ul><pre>gcloud iam service-account2s create SERVICE_ACCOUNT_NAME \<br>    --description=&quot;DESCRIPTION_OF_SERVICE_ACCOUNT&quot; \<br>    --display-name=&quot;DISPLAY_NAME_OF_SERVICE_ACCOUNT&quot;</pre><pre>gcloud projects add-iam-policy-binding PROJECT_ID \<br>    --member=&quot;serviceAccount:SERVICE_ACCOUNT_EMAIL&quot; \<br>    --role=&quot;roles/iam.workloadIdentityUser&quot;</pre><ul><li>Add the roles to the service account for specific resources you want to create from terraform</li></ul><h4>Configure Workload Identity using Console</h4><p>1.<strong> Create a Workload Identity Pool:</strong></p><ul><li>Go to the Google Cloud Console.</li><li>Navigate to <strong>IAM &amp; Admin</strong> &gt; <strong>Workload Identity Federation</strong>.</li><li>Click on <strong>Create Pool</strong>.</li><li>Provide a name and description for the pool, then create it.</li></ul><p>2.<strong> Create a Workload Identity Provider:</strong></p><ul><li>Within your newly created pool, click on <strong>Create Provider</strong>.</li><li>Set the <strong>Provider Type</strong> to <strong>OIDC</strong>.</li><li>Enter the <strong>Issuer URL</strong> from Azure DevOps (e.g., <a href="https://vstoken.dev.azure.com/d4d675c3-5be0-439e-9c7c-0df7648faf70).">https://vstoken.dev.azure.com/</a>example<a href="https://vstoken.dev.azure.com/d4d675c3-5be0-439e-9c7c-0df7648faf70).">).</a></li><li>Set the <strong>Allowed Audiences</strong> to api://AzureADTokenExchange.</li><li>For <strong>Attribute Mapping</strong>, set google.subject to assertion.sub.</li><li>Save the configuration.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/506/1*u_scteBPZFFU3G-AnEbhBw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/506/1*nSvE0PtZq-VLso3j4Hi_9Q.png" /></figure><p>3.<strong> Create a Service Account:</strong></p><ul><li>Go to <strong>IAM &amp; Admin</strong> &gt; <strong>Service Accounts</strong>.</li><li>Click <strong>Create Service Account</strong> and provide a name, description, and ID.</li><li>Grant the service account the <strong>Workload Identity User</strong> role.</li><li>Add additional roles like <strong>Storage Admin</strong> if needed. (this role i am using because i am creating storage bucket using Terraform.)</li></ul><h4><strong>Grant external identity access to impersonate the service account</strong></h4><ul><li>Go to the Workload Identity Pools page.</li><li>Select Grant access.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Roj0dQMxsnjI8Kz9psZB1Q.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*iwocJ8wGA-naJ6K2" /></figure><ul><li>Add the subject value as the <strong>subject identifier</strong> which we noted</li><li>Click Save and then Dismiss.</li></ul><h3>Configuring the pipeline on Azure DevOps</h3><ul><li>Push the terraform code to the azure repository.</li></ul><pre>terraform {<br>  required_version = &quot;&gt;= 0.13&quot;<br>  required_providers {<br>    google = {<br>      source  = &quot;hashicorp/google&quot;<br>      version = &quot;~&gt; 4.0&quot;<br>    }<br>  }<br>}<br><br>provider &quot;google&quot; {<br>  project     = &quot;&lt;project_name&gt;&quot;<br>  region      = &quot;us-central1&quot; # Replace with your desired region<br>}<br><br>resource &quot;google_storage_bucket&quot; &quot;crate_storage&quot; {<br>  name          = &quot;&lt;bucket_name&gt;&quot;<br>  location      = &quot;us-central1&quot;<br>  storage_class = &quot;STANDARD&quot; # or choose other storage classes if needed<br>  versioning {<br>    enabled = true<br>  }<br><br>}</pre><ul><li>Go to pipelines and select the new pipeline option.</li><li>Select `Azure Repo Git` as the repository for the pipeline and select the repository where we have the Terraform code.</li><li>Select the starter pipeline option.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*6gy3ePBbv6mqXURd" /></figure><ul><li>Add the below configuration to the pipeline.</li></ul><pre>variables:<br>- name: Azure.WorkloadIdentity.Connection<br> value: &lt;NAME OF THE SERVICE CONNECTION&gt;<br>- name: GoogleCloud.WorkloadIdentity.ProjectNumber<br> value: &lt;GCP PROJECT NUMBER&gt;<br>- name: GoogleCloud.WorkloadIdentity.Pool<br> value: &lt;GCP WORKLOAD IDENTITY POOL NAME&gt;<br>- name: GoogleCloud.WorkloadIdentity.Provider<br> value: &lt;GCP WORKLOAD IDENTITY PROVIDER NAME&gt;<br>- name: GoogleCloud.WorkloadIdentity.ServiceAccount<br> value: &lt;GCP SERVICE ACCOUNT EMAIL&gt;<br>- name: GOOGLE_APPLICATION_CREDENTIALS<br> value: $(Pipeline.Workspace)/.workload_identity.wlconfig<br>trigger:<br> branches:<br>   include:<br>     - main<br> paths:<br>   include:<br>     - .<br>pool:<br> name: &lt;AGENT POOL NAME&gt;<br> demands:<br> - Agent.Name -equals &lt;AGENT NAME&gt;<br>steps:<br> - task: AzureCLI@2<br>   inputs:<br>     connectedServiceNameARM: $(Azure.WorkloadIdentity.Connection)<br>     addSpnToEnvironment: true<br>     scriptType: &#39;bash&#39;<br>     scriptLocation: &#39;inlineScript&#39;<br>     inlineScript: |<br>       echo $idToken &gt; $(Pipeline.Workspace)/.workload_identity.jwt<br>       cat &lt;&lt; EOF &gt; $GOOGLE_APPLICATION_CREDENTIALS<br>       {<br>         &quot;type&quot;: &quot;external_account&quot;,<br>         &quot;audience&quot;: &quot;//iam.googleapis.com/projects/$(GoogleCloud.WorkloadIdentity.ProjectNumber)/locations/global/workloadIdentityPools/$(GoogleCloud.WorkloadIdentity.Pool)/providers/$(GoogleCloud.WorkloadIdentity.Provider)&quot;,<br>         &quot;subject_token_type&quot;: &quot;urn:ietf:params:oauth:token-type:jwt&quot;,<br>         &quot;token_url&quot;: &quot;https://sts.googleapis.com/v1/token&quot;,<br>         &quot;credential_source&quot;: {<br>           &quot;file&quot;: &quot;$(Pipeline.Workspace)/.workload_identity.jwt&quot;<br>         },<br>         &quot;service_account_impersonation_url&quot;: &quot;https://iamcredentials.googleapis.com/v1/projects/-/serviceAccounts/$(GoogleCloud.WorkloadIdentity.ServiceAccount):generateAccessToken&quot;<br>       }<br>       EOF<br><br>       terraform init<br>       terraform plan<br>       terraform apply --auto-approve</pre><p>Replace the following,</p><p>NAME OF SERVICE CONNECTION: Enter name of service connection which we<br>created <a href="https://docs.google.com/document/d/1ZwUAqmmefT-XJlmmUXUeotMKKNwMiRhjqTE1dCkL58s/edit?pli=1#heading=h.sf60y3rvczni">above</a>.</p><p>GCP PROJECT NUMBER: Project number where we have the Workload Identity created.<br>GCP WORKLOAD IDENTITY PROVIDER NAME: Name of the workload identity provider.</p><p>GCP WORKLOAD IDENTITY POOL NAME: Name of the workload identity pool.</p><p>GCP SERVICE ACCOUNT EMAIL: Service account email, which we are impersonating.</p><p>AGENT POOL NAME: Name of the agent pool which we created <a href="https://docs.google.com/document/d/1ZwUAqmmefT-XJlmmUXUeotMKKNwMiRhjqTE1dCkL58s/edit?pli=1#heading=h.9snzwh1lp5go">above</a>.<br>AGENT NAME: Name of the agent in the agent pool.</p><ul><li>Save and run the pipeline to test.</li><li>Navigate to the <strong>Cloud Storage</strong> section in the Google Cloud Console. Under <strong>Buckets</strong>, you should see the newly created bucket listed with the name specified in your Terraform configuration.</li></ul><h3>Conclusion</h3><p>In this blog post, we demonstrated how to provision Google Cloud Platform (GCP) resources using Terraform through Azure DevOps pipelines by leveraging Workload Identity Federation. This approach significantly enhances security and efficiency by eliminating the need for static service account keys and using OAuth 2.0 token exchange for authentication.</p><p>By setting up Workload Identity Federation, you can securely manage GCP resources from Azure DevOps pipelines without exposing sensitive credentials. This method ensures that your infrastructure is managed in a more secure manner, reducing the risk of credential leakage and simplifying credential management.</p><p>Here’s a summary of the key steps covered:</p><ol><li><strong>Configuration on Azure DevOps</strong>: We created a service connection using Workload Identity Federation, configured the self-hosted agent, and ensured the agent had the necessary prerequisites.</li><li><strong>Configuration on Google Cloud</strong>: We created a Workload Identity Pool and Provider, set up the service account with the necessary roles, and granted access to the external identity.</li><li><strong>Pipeline Configuration</strong>: We set up the Azure DevOps pipeline with Terraform configurations, ensuring it correctly interacts with GCP using the Workload Identity Federation.</li></ol><p>By following these steps, you can leverage Workload Identity Federation to securely and efficiently manage your GCP resources from Azure DevOps, ensuring a streamlined and secure DevOps workflow.</p><p>If you have any questions or need further assistance, feel free to reach out or leave a comment below. <br>Happy provisioning!✌️</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bbd2ad4d2cd6" width="1" height="1" alt=""><hr><p><a href="https://medium.com/google-cloud/provisioning-google-cloud-resources-using-terraform-and-azure-devops-with-workload-identity-bbd2ad4d2cd6">Provisioning GCP Resources with Terraform &amp; Azure DevOps</a> was originally published in <a href="https://medium.com/google-cloud">Google Cloud - Community</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Automating Slack Notifications: Sending Messages as a Bot with Python]]></title>
            <link>https://medium.com/@sid2631/automating-slack-notifications-sending-messages-as-a-bot-with-python-2beb6c16cd8c?source=rss-22f4ef672231------2</link>
            <guid isPermaLink="false">https://medium.com/p/2beb6c16cd8c</guid>
            <category><![CDATA[slack]]></category>
            <category><![CDATA[bots]]></category>
            <category><![CDATA[automation]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[Siddharth Satpute]]></dc:creator>
            <pubDate>Sat, 09 Mar 2024 05:12:38 GMT</pubDate>
            <atom:updated>2024-03-09T05:12:38.954Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*i3sYD6YUFpONiWXwoONuQw.jpeg" /></figure><h3>Introduction:</h3><p>In today’s fast-paced work environments, effective communication is crucial for team collaboration and productivity. Slack, a widely used communication tool, offers powerful APIs that enable developers to automate various tasks and streamline workflows. In this tutorial, we’ll delve into how to send messages programmatically in Slack using Python, empowering you to automate notifications and enhance team communication.</p><h3>Prerequisites:</h3><ol><li>Python installed on your system.</li><li>An active Slack workspace where you have permissions to create and manage apps.</li></ol><h3><strong>Step 1: Create a Slack Channel</strong></h3><ol><li>Go to your Slack workspace.</li><li>Click on the “+” icon next to “Channels” in the sidebar.</li><li>Choose whether you want the channel to be public or private.</li><li>Enter a name for your channel (e.g., slack-test-bot) and click “Create”.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*o3X1CvCwK8R_01Ra1CuPxA.png" /></figure><h3>Step 2: Set Up a Slack App</h3><ol><li>Navigate to the Slack API website: <a href="https://api.slack.com/apps">https://api.slack.com/apps</a>.</li><li>Log in with your Slack credentials if you haven’t already.</li><li>Click on “Create New App” in the top-right corner.</li><li>Select “From Scratch” and enter an app name (e.g., bot-test).</li><li>Choose the workspace where you want to create the app and click “Create App”.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XdOvkpEDwAFgCrPfv2SV2Q.png" /></figure><h3>Step 3: Configure Basic Information</h3><ol><li>In the “Basic Information” section, click on “Add features and functionality”.</li><li>Under the “Bots” section, click on “Review Scopes to Add”.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XdOvkpEDwAFgCrPfv2SV2Q.png" /></figure><h3>Step 4: Add Required Scopes</h3><ol><li>You’ll be directed to the “OAuth &amp; Permissions” section.</li><li>In the “Scopes” section, click on “Add an OAuth Scope”.</li><li>Select the permission “chat:write” from the list.</li><li>Click on “Install to Workspace” in the “OAuth Tokens for Your Workspace” section.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jAyYvZ-_PgnKCROPq_5eig.png" /></figure><h3>Step 5: Install the App to Your Workspace</h3><ol><li>After installing, you’ll see the bot added to your Slack workspace.</li><li>Note down the bot token provided.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fiyk8c12v-IWaM54mOL1rw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-sQ7hyZvRguoS_JDC1Exwg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2tlmTU9qg8NCBxpMZVcB0g.png" /></figure><h3>Step 6: Add the App to Your Channel</h3><ol><li>Go back to your Slack workspace.</li><li>Click on the name of the bot dropdown.</li><li>Select “Add this app to a channel”.</li><li>Choose the channel you created earlier (e.g., slack-test-bot) and click “Add”.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Hu7fkH4gg3Oza67JLCW0zg.png" /></figure><h3>Step 7: Write the Python Script</h3><ol><li>Open a Code Editor and Install Below python Libery</li></ol><pre>pip install slack_sdk</pre><p>2. Now, let’s write a Python script to send messages to Slack. Here’s a basic example:</p><pre>from slack_sdk import WebClient<br>from slack_sdk.errors import SlackApiError<br><br># Initialize a WebClient instance with your OAuth token<br>client = WebClient(token=&quot;YOUR_OAUTH_TOKEN&quot;)<br><br># The channel ID or name where you want to send the message<br>channel_id = &quot;slack-test-bot&quot;<br><br># The bot name <br>bot_name = &quot;bot-test&quot;<br><br># The message you want to send<br>message = &quot;Hi i am Slack bot&quot;<br><br>try:<br>    # Use the chat.postMessage method to send a message to the channel<br>    response = client.chat_postMessage(channel=channel_id, text=message,username=bot_name)<br>    print(&quot;Message sent successfully!&quot;)<br>except SlackApiError as e:<br>    # Error handling in case the message fails to send<br>    print(f&quot;Error sending message: {e}&quot;)</pre><p>Replace &#39;YOUR_OAUTH_TOKEN&#39; with the OAuth token obtained in Step 5</p><h3>Step 4: Run the Script</h3><p>Save the Python script and run it from your terminal or command prompt. If everything is set up correctly, you should see the message appear in the specified Slack channel.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KD9VSzXN_8twciQxJcD3ew.png" /></figure><h3>Conclusion</h3><p>Automating Slack notifications with Python opens up endless possibilities for enhancing collaboration and productivity within your team. Whether it’s sending alerts for system events, notifying team members about task updates, or simply sending motivational messages, the ability to programmatically send messages to Slack channels provides a powerful tool for streamlining communication workflows.</p><p>By following the steps outlined in this blog post, you can quickly get started with automating Slack notifications and tailor them to suit your team’s unique requirements. So why not give it a try and see how automation can revolutionize the way your team communicates and collaborates on Slack?</p><p>Drop your comments, feedback, or suggestions below — or connect with me directly on LinkedIn @<a href="https://www.linkedin.com/in/siddharth-satpute/">https://www.linkedin.com/in/siddharth-satpute/</a></p><p>Happy learning !!!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2beb6c16cd8c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Automating Infrastructure as Code with Terraform and GitHub Actions in AWS]]></title>
            <link>https://medium.com/@sid2631/automating-infrastructure-as-code-with-terraform-and-github-actions-in-aws-e6f1751be339?source=rss-22f4ef672231------2</link>
            <guid isPermaLink="false">https://medium.com/p/e6f1751be339</guid>
            <category><![CDATA[terraform]]></category>
            <category><![CDATA[github]]></category>
            <category><![CDATA[aws]]></category>
            <dc:creator><![CDATA[Siddharth Satpute]]></dc:creator>
            <pubDate>Mon, 15 Jan 2024 09:18:37 GMT</pubDate>
            <atom:updated>2024-01-15T10:18:09.994Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ICIkYASrHz0sOi-ujymtfQ.png" /></figure><h3>Introduction</h3><p>Contemporary software development relies on automation for effective and consistent processes. GitHub Actions is an automated tool designed by GitHub to make CI and CD processes easier. In this blog post, we will look at how GitHub Actions can be used along with Terraform to automate infrastructure tasks.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wqh_qNypMEIPFXffYdBGDQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*o5kJyHw9smuzZAvdiODASg.png" /><figcaption>Jet brain Link- <a href="https://blog.jetbrains.com/teamcity/2023/07/best-ci-tools/">https://blog.jetbrains.com/teamcity/2023/07/best-ci-tools/</a></figcaption></figure><h3>GitHub Actions Components</h3><p>GitHub Actions consists of several components:</p><ol><li><strong>Workflows</strong>: Automated procedures added to your repository, comprising one or more jobs triggered by events.</li><li><strong>Events</strong>: Specific activities that trigger workflows, such as pushing commits or creating pull requests.</li><li><strong>Jobs</strong>: Sets of steps that execute on the same runner. Jobs can run sequentially or in parallel.</li><li><strong>Steps</strong>: Individual tasks that run commands in a job, which can be either actions or shell commands.</li><li><strong>Actions</strong>: Standalone commands combined into steps to create a job, providing a modular and reusable way to define tasks.</li><li><strong>Runners</strong>: Servers with the GitHub Actions runner application installed, responsible for executing jobs and reporting progress back to GitHub.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*s9MNIJ0D1DWQuqh_d8WI2g.png" /></figure><h3>GitHub Actions and Terraform</h3><p>Terraform, an Infrastructure as Code (IAC) tool, can be seamlessly integrated with GitHub Actions. Additionally, tools like Terraform Linter (TfLint) and TFSec can enhance the development process by identifying syntax errors and security misconfigurations.</p><h3>Terraform Linter (TfLint)</h3><p>TfLint is an additional plugin for Terraform that analyzes and displays syntax errors that may not be caught by terraform validate. To use TfLint, install it using brew install tflint and initialize the plugin with a .tflint.hcl file.</p><p>For example, to enable the AWS ruleset:</p><pre>plugin &quot;aws&quot; {<br>  enabled = true<br>  version = &quot;0.24.0&quot;<br>  source  = &quot;github.com/terraform-linters/tflint-ruleset-aws&quot;<br>}</pre><h3>TfSec — Terraform Security Scanner</h3><p>TfSec is a static analysis tool for Terraform code where it analyzes security misconfiguration and identifies potential risks. Install the TfSec using brew install tfsec.</p><p>To show only medium severity errors, create a tfsec.yml file with the following content:</p><pre>minimum_severity: MEDIUM</pre><h3>GitHub Actions Workflow</h3><p>To integrate Terraform and related tools into your GitHub Actions workflow, create a GitHub Actions YAML file (e.g., .github/workflows/terraform-ci-cd.yml). Define the workflow to trigger on pull requests and merge events.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*68kTSfH9Hto3OrJAbpjCmw.png" /></figure><pre>name: AWS S3 Bucket CI/CD<br><br>on:<br>  pull_request:<br>    branches:<br>      - main<br><br>jobs:<br>  terraform-ci:<br>    runs-on: ubuntu-latest<br><br>    steps:<br>    - name: Checkout Repository<br>      uses: actions/checkout@v2<br><br>    - name: Run TFSec<br>      run: tfsec --config-file tfsec.yml<br><br>    - name: Run TFLint<br>      run: tflint<br><br>    - name: Terraform Plan<br>      run: terraform plan<br><br>  terraform-cd:<br>    runs-on: ubuntu-latest<br><br>    steps:<br>    - name: Checkout Repository<br>      uses: actions/checkout@v2<br><br>    - name: Terraform Apply<br>      run: terraform apply -var &quot;aws_credentials=$AWS_CREDENTIALS&quot; --auto-approve</pre><p>This is a simplified example of a GitHub Actions workflow for Continuous Integration and Continuous Deployment (CI/CD) for managing infrastructure using Terraform. The workflow is triggered on pull requests to the main branch. It consists of two jobs: terraform-ci for Continuous Integration and terraform-cd for Continuous Deployment.</p><p>This is a straightforward demonstration of an automated deployment workflow with the help of GitHubActions for CI/CD in the contexts where infra structure management would be via providing Terraform some code. Thec workflow executes on pull requests made to the main branch. It consists of two jobs: CI using terraform-ci and CD through the use of terraform-cd for Continuous Deployment.</p><h3>Continuous Integration (terraform-ci):</h3><ol><li><strong>Trigger</strong>: The CI job is triggered when there is a pull request targeting the <strong>main</strong> branch.</li><li><strong>Job Environment</strong>: The job runs on an Ubuntu-based latest environment.</li><li><strong>Steps</strong>:</li></ol><ul><li><strong>Checkout Repository</strong>: This step fetches the latest version of the repository.</li><li><strong>Run TFSec</strong>: This step runs <strong>tfsec</strong>, a static analysis tool for Terraform security issues, using a configuration file (<strong>tfsec.yml</strong>).</li><li><strong>Run TFLint</strong>: This step runs <strong>tflint</strong>, a Terraform linting tool, to check for best practices and potential errors.</li><li><strong>Terraform Plan</strong>: This step runs <strong>terraform plan</strong> to generate an execution plan for the infrastructure changes. It doesn’t actually apply the changes but checks what changes would be made.</li></ul><h3>Continuous Deployment (terraform-cd):</h3><ol><li><strong>Trigger</strong>: The CD job is also triggered on pull requests to the <strong>main</strong> branch.</li><li><strong>Job Environment</strong>: Similar to the CI job, it runs on an Ubuntu-based latest environment.</li><li><strong>Steps</strong>:</li></ol><ul><li><strong>Checkout Repository</strong>: Fetches the latest version of the repository.</li><li><strong>Terraform Apply</strong>: This step runs <strong>terraform apply -auto-approve</strong> to apply the changes to the infrastructure automatically. The <strong>-auto-approve</strong> flag skips the interactive approval prompt.</li></ul><p><em>main.tf</em></p><pre>provider &quot;aws&quot; {<br>  region = &quot;us-east-1&quot;<br>  credentials = var.aws_credentials<br>}<br><br>resource &quot;aws_s3_bucket&quot; &quot;example_bucket&quot; {<br>  bucket = &quot;example-bucket-name&quot;<br>  acl    = &quot;private&quot;<br>}<br><br>terraform {<br>  required_providers {<br>    aws = {<br>      source  = &quot;hashicorp/aws&quot;<br>      version = &quot;5.31.0&quot;<br>    }<br>  }<br>}</pre><p><em>variable.tf</em></p><pre>variable &quot;aws_credentials&quot; {<br>  type = string<br>}</pre><p><em>Best practices</em></p><p>To enhance security, consider storing sensitive information like service account credentials in GitHub Secrets. For example, if using AWS create a secret named AWS_SERVICE_ACCOUNT and reference it in your Terraform configuration</p><h3>Navigate to Repository Settings:</h3><ul><li>Go to the main page of your GitHub repository.</li><li>Under the repository name, click on “Settings.”</li><li>If you can’t find the “Settings” tab, check the dropdown menu and select “Settings.”</li></ul><p><strong>Access Security Settings:</strong></p><ul><li>In the sidebar, find the “Security” section.</li><li>Select “Secrets and variables” under the “Security” section.</li><li>Click on the “Actions” tab.</li></ul><p><strong>Go to Variables:</strong></p><ul><li>Click on the “Variables” tab.</li></ul><p><strong>Add New Repository Variable:</strong></p><ul><li>Click on “New repository variable.”</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KTV6JYjajKIhUkpV7o5qlA.png" /></figure><p><strong>Enter Name and Value:</strong></p><ul><li>In the “Name” field, enter a name for your variable. This is the identifier you’ll use in your workflows.</li><li>In the “Value” field, enter the actual value for your variable. This could be a secret key, password, or any sensitive information.</li></ul><p><strong>Add Variable:</strong></p><ul><li>Click on “Add variable” to save the repository variable.</li></ul><h3>Conclusion</h3><p>Automating infrastructure tasks using Terraform and GitHub Actions, in AWS has benefits. It not makes the development process more efficient and reliable. Also contributes to a streamlined software development lifecycle in the cloud. By integrating CI/CD workflows utilizing Terraform linting and security tools and adhering to practices for securing information development teams can establish a robust and automated infrastructure deployment pipeline. This approach facilitates agility and scalability, in software development within the cloud environment.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e6f1751be339" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Cloud Infrastructure Automation using Terraform & Atlassian Bitbucket]]></title>
            <link>https://medium.com/google-cloud/cloud-infrastructure-automation-using-terraform-atlassian-bitbucket-837a0b1d4e4?source=rss-22f4ef672231------2</link>
            <guid isPermaLink="false">https://medium.com/p/837a0b1d4e4</guid>
            <category><![CDATA[atlassian]]></category>
            <category><![CDATA[gcp-security-operations]]></category>
            <category><![CDATA[bitbucket]]></category>
            <category><![CDATA[terraform]]></category>
            <category><![CDATA[google-cloud-platform]]></category>
            <dc:creator><![CDATA[Siddharth Satpute]]></dc:creator>
            <pubDate>Mon, 25 Sep 2023 13:01:09 GMT</pubDate>
            <atom:updated>2023-09-25T13:01:09.236Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_qFUgg2sUegzj2kSbORCQA.jpeg" /></figure><h3><em>What is Bitbucket ?</em></h3><p><em>Bitbucket stands as a Git-driven source code repository hosting platform that falls under the ownership of Atlassian. Bitbucket provides a platform for teams to collaborate on code, manage repositories, and track changes made to source code over time. Developers can use Bitbucket to store, manage, and share their code repositories privately or publicly, and collaborate with team members on code reviews, bug tracking, and continuous integration and deployment.</em></p><h3><em>Features of Bitbucket</em></h3><ol><li><strong><em>Version control</em></strong><em>: Bitbucket serves as a platform designed to empower developers in managing their code effectively. It facilitates the tracking of code changes, the maintenance of version history, and fosters seamless collaboration among team members, promoting efficient development workflows..</em></li><li><strong><em>Distributed architecture</em></strong><em>: Bitbucket utilizes a distributed architecture, enabling developers to work on their local code copies and synchronize changes with the main repository for efficient collaboration</em></li><li><strong><em>Integration with other tools: </em></strong><em>Bitbucket seamlessly integrates with an extensive range of development tools, including Jira, Trello, Slack, and more. This integration facilitates smooth collaboration and project management throughout the entire development lifecycle, enhancing efficiency and coordination among team members.</em></li><li><strong><em>Security</em></strong><em>: Bitbucket offers enterprise-grade security features such as two-factor authentication, IP whitelisting, and encryption of data at rest and in transit.</em></li><li><strong><em>Pricing</em></strong><em>: Bitbucket presents a diverse pricing model, offering both free and paid subscription plans. The paid options grant users access to extra features, including expanded storage capacity and heightened access controls. This enables developers to select the plan that suits their individual preferences and project demands, ensuring a tailored experience for each user.</em></li></ol><h3><em>Bitbucket Vs Github</em></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qofbb6D95R1n10ceVfrDdA.png" /><figcaption>ref- <a href="https://www.geeksforgeeks.org/difference-between-bitbucket-and-github">https://www.geeksforgeeks.org/difference-between-bitbucket-and-github</a></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Z6r-8uvzKwlujEVpJcTzbw.png" /></figure><h3><strong><em>Terraform</em></strong></h3><p><em>Terraform is an open-source infrastructure as code (IaC) tool developed and maintained by HashiCorp. It enables users to define and manage their cloud infrastructure, including servers, networks, and other resources, in a declarative manner. The primary purpose of Terraform is to automate the provisioning and management of cloud resources, making it easier for developers and operations teams to collaborate and maintain infrastructure in a consistent state.</em></p><h3>TFsec</h3><p><em>Terraform has revolutionised the way we manage infrastructure as code (IaC) and has become an integral part of modern cloud deployments. However, as our infrastructures grow in complexity, ensuring security and compliance becomes increasingly challenging. That’s where TFSec comes into play. TFSec, a powerful open-source tool, to enhance the security of your Terraform code without compromising on efficiency. TFSec is a security scanner designed specifically for Terraform codebases. It evaluates your infrastructure-as-code files to identify potential security vulnerabilities and compliance issues. By analysing your Terraform configurations, TFSec provides valuable feedback on best practices and security flaws, helping you mitigate risks before deploying your infrastructure.<br>TFSec operates by comparing your Terraform code against a set of pre-defined rules and policies. These rules are continuously updated by the open-source community, ensuring that TFSec remains up-to-date with the latest security standards and best practices.</em></p><h3>TFLint</h3><p><em>TFLint is an open-source linter specifically designed to analyze Terraform code and identify potential issues and best-practice violations. Much like how traditional linters work for programming languages, TFLint inspects Terraform configuration files and provides actionable feedback to developers. It not only helps identify syntax errors but also detects patterns that could lead to runtime errors or security vulnerabilities.</em></p><h3>Infrastructure Automation using Terraform &amp; Bitbucket</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JEVcgM-ZkDakhqRTeaPRqw.png" /></figure><p><strong>Step 1</strong>:- Create a Project in Bitbucket</p><p><strong>Step 2:</strong>- Create a repository from project in bitbucket</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*jpIYymmvYLo7wkUv" /></figure><p><strong>Step 3:</strong>- create a repository variable “GOOGLE_CREDENTIALS” and store the service account</p><p><strong>Step 5</strong>:- add the file</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/0*mwDLjE2no-X2HBX1" /></figure><h4><strong>1. Main.tf</strong></h4><pre>terraform {<br>  required_version = &quot;&gt;= 0.13&quot;<br>  required_providers {<br>    google = {<br>      source  = &quot;hashicorp/google&quot;<br>      version = &quot;~&gt; 4.0&quot;<br>    }<br>  }<br>}<br><br>provider &quot;google&quot; {<br>  credentials = var.google_credentials<br>  project     = &quot;your-project&quot;<br>  region      = &quot;us-central1&quot; # Replace with your desired region<br>}<br><br>#tfsec:ignore:google-storage-bucket-encryption-customer-key<br>#tfsec:ignore:google-storage-enable-ubla <br>resource &quot;google_storage_bucket&quot; &quot;crate_storage&quot; {<br>  name          = &quot;bucket-name&quot;<br>  location      = &quot;us-central1&quot;<br>  storage_class = &quot;STANDARD&quot; # or choose other storage classes if needed<br>  versioning {<br>    enabled = true<br>  }<br><br><br>}</pre><p>This Terraform configuration file contains the main infrastructure code using the Google Cloud provider. Here’s a summary of its contents:</p><ul><li>The terraform block specifies the required Terraform version and Google provider version.</li><li>The provider “google” block configures the Google Cloud provider with the specified project and region and uses the credentials provided in the google_credentials variable.</li><li>The resource “google_storage_bucket” block defines a Google Cloud Storage bucket named “terraform-sid-test-23456” in the “us-central1” region with the “STANDARD” storage class and versioning enabled.</li></ul><h4><strong>2. Variable.tf</strong></h4><pre>variable &quot;google_credentials&quot; {<br>  type = string<br>}</pre><p>This file defines a Terraform variable called google_credentials of type string. Variables allow you to parameterize your Terraform code, enabling flexibility and reusability.</p><h4><strong>3. .tflint.hcl</strong></h4><pre>plugin &quot;google&quot; {<br>    enabled = true<br>    version = &quot;0.23.1&quot;<br>    source  = &quot;github.com/terraform-linters/tflint-ruleset-google&quot;<br>}</pre><p>This file configures TFLint, a Terraform linter, with specific settings for checking Terraform code. Here’s what it does:</p><ul><li>The plugin “google” block enables the Google Cloud ruleset for TFLint and sets its version to “0.23.1” from the specified GitHub repository (terraform-linters/tflint-ruleset-google).</li></ul><h4>4. bitbucket-pipelines.yml</h4><pre>pipelines:<br>  branches:<br>    master:<br>      - step:<br>          name: Terraform fmt<br>          image: hashicorp/terraform<br>          script:<br>            - terraform fmt<br>      - step:<br>          trigger: manual<br>          name: Terraform Apply<br>          image: hashicorp/terraform<br>          script:<br>            - terraform init -input=false<br>            - terraform apply -var &quot;google_credentials=$GOOGLE_CREDENTIALS&quot; -auto-approve<br>          services:<br>            - docker<br><br>    &#39;**&#39;:<br>      - step:<br>          name: tfsec and tflint <br>          image: ubuntu:latest <br>          script:<br>            - apt-get update &amp;&amp; apt-get install -y wget unzip<br>            - wget &quot;https://releases.hashicorp.com/terraform/0.12.31/terraform_0.12.31_linux_amd64.zip&quot; -O terraform.zip<br>            - unzip terraform.zip<br>            - mv terraform /usr/local/bin/<br>            - terraform --version<br>            - wget &quot;https://github.com/terraform-linters/tflint/releases/latest/download/tflint_linux_amd64.zip&quot; -O tflint.zip<br>            - unzip tflint.zip<br>            - mv tflint /usr/local/bin/<br>            - tflint --version<br>            - wget &quot;https://github.com/liamg/tfsec/releases/latest/download/tfsec-linux-amd64&quot; -O tfsec<br>            - chmod +x tfsec<br>            - mv tfsec /usr/local/bin/<br>            - tfsec --version<br>            - tflint --init<br>            - tflint<br>            - tfsec .<br>      - step:<br>          name: Terraform Apply<br>          image: hashicorp/terraform<br>          script:<br>            - terraform init -input=false<br>            - terraform apply -var &quot;google_credentials=$GOOGLE_CREDENTIALS&quot; -auto-approve<br>          services:<br>            - docker<br><br>  pull-requests:<br>    &#39;**&#39;:<br>      - step:<br>          name: tfsec and tflint <br>          image: ubuntu:latest <br>          script:<br>            - apt-get update &amp;&amp; apt-get install -y wget unzip<br>            - wget &quot;https://releases.hashicorp.com/terraform/0.12.31/terraform_0.12.31_linux_amd64.zip&quot; -O terraform.zip<br>            - unzip terraform.zip<br>            - mv terraform /usr/local/bin/<br>            - terraform --version<br>            - wget &quot;https://github.com/terraform-linters/tflint/releases/latest/download/tflint_linux_amd64.zip&quot; -O tflint.zip<br>            - unzip tflint.zip<br>            - mv tflint /usr/local/bin/<br>            - tflint --version<br>            - wget &quot;https://github.com/liamg/tfsec/releases/latest/download/tfsec-linux-amd64&quot; -O tfsec<br>            - chmod +x tfsec<br>            - mv tfsec /usr/local/bin/<br>            - tfsec --version<br>            - tflint --init<br>            - tflint<br>            - tfsec .</pre><ol><li>The pipeline is triggered when changes are pushed to the master branch or when pull requests are created or updated (in any branch)</li><li>For the master branch</li></ol><ul><li>The first step is named “Terraform fmt.” It uses the official hashicorp/terraform Docker image and runs the terraform fmt command to format the Terraform configuration files.</li><li>The second step is named “Terraform Apply.” It uses the same Docker image and runs Terraform commands to initialise the workspace (terraform init) and apply the changes (terraform apply). The -var flag is used to pass a Google Cloud credentials variable to the Terraform configuration. The auto-approve flag is used to automatically approve the changes without manual confirmation. Additionally, the service docker is specified, which means the pipeline will have access to Docker during the execution of this step. this part is manually triggered</li></ul><p>3. For all other branches (including pull requests):</p><ul><li>The first step is named “tfsec and tflint.” It uses the ubuntu:latest Docker image and performs the following tasks:</li><li>Installs necessary packages (wget and unzip) to download and extract files.</li><li>Downloads the specified versions of terraform, tflint, and tfsec.</li><li>Moves these binaries to the /usr/local/bin/ directory so that they can be accessed globally.</li><li>Checks the versions of Terraform, TFLint, and tfsec.</li><li>Initializes TFLint with tflint --init.</li><li>Runs TFLint and tfsec to perform static analysis on the Terraform configuration files.</li><li>The second step is similar to the “Terraform Apply” step for the master branch. It initialises the Terraform workspace and applies the changes using the provided Google Cloud credentials. The docker service is also available in this step.this part is automatic triggered</li></ul><p><strong>Step 7</strong>:- pushed into repo</p><p>Git add .</p><p>Git commit -m “added code”</p><p>Git push</p><p><strong>Step 8:</strong>- Pipeline triggered</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/312/1*YCYs0gxTTPLK5zX8myUtRg.jpeg" /><figcaption>When developers push the code in test branch</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/309/1*5e0Zqrw0SxxnG4coUvELfQ.jpeg" /><figcaption>When developers raise a pull request from test branch to master</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/309/1*HBfWHz9m1sDqD-XXrh9reQ.jpeg" /><figcaption>When pull request merge to master branch</figcaption></figure><h3>Conclusion</h3><p><em>In conclusion, leveraging Terraform for cloud infrastructure automation in conjunction with Atlassian Bitbucket offers developers a powerful and efficient way to manage code repositories and provision cloud resources. Bitbucket, as a Git-driven source code repository hosting platform, provides teams with a collaborative environment to track changes, conduct code reviews, and manage code securely. On the other hand, Terraform, an open-source infrastructure as code (IaC) tool, simplifies the process of defining and managing cloud infrastructure in a declarative manner, ensuring consistency and scalability.</em></p><p><em>By integrating Bitbucket with Terraform, developers can seamlessly manage their infrastructure code and collaborate effectively. The defined steps for setting up a Bitbucket project, creating repositories, and adding repository variables for credentials ensure secure handling of sensitive information. Additionally, the Bitbucket Pipelines configuration enables automated testing of Terraform code, utilizing tools like TFLint and TFSec to identify potential issues and vulnerabilities.</em></p><p><em>Using Bitbucket and Terraform together streamlines the development and deployment workflows, leading to enhanced productivity and reduced errors. Developers can work on their local code copies and synchronize changes efficiently, thanks to Bitbucket’s distributed architecture. The seamless integration of Bitbucket with other tools like Jira, Trello, and Slack further enhances team collaboration and project management capabilities.</em></p><p><em>With Bitbucket offering a range of pricing plans, teams can choose the most suitable option based on their project requirements and budget constraints. Meanwhile, Terraform’s open-source nature ensures that developers have access to a vast community constantly improving the tool and providing up-to-date security standards.</em></p><p><em>In conclusion, the combination of Bitbucket and Terraform empowers development teams to streamline their infrastructure management processes, ensure security and compliance, and achieve greater efficiency in their cloud deployments. Embracing this powerful duo allows teams to focus more on innovation and delivering value to customers while leaving the heavy lifting of infrastructure automation to these reliable and effective tools.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=837a0b1d4e4" width="1" height="1" alt=""><hr><p><a href="https://medium.com/google-cloud/cloud-infrastructure-automation-using-terraform-atlassian-bitbucket-837a0b1d4e4">Cloud Infrastructure Automation using Terraform &amp; Atlassian Bitbucket</a> was originally published in <a href="https://medium.com/google-cloud">Google Cloud - Community</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to install Minikube in Google Cloud Vm Instance]]></title>
            <link>https://medium.com/google-cloud/how-to-install-minikube-in-google-cloud-vm-instance-b5ea57cb2204?source=rss-22f4ef672231------2</link>
            <guid isPermaLink="false">https://medium.com/p/b5ea57cb2204</guid>
            <category><![CDATA[minikube]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[gcp-app-dev]]></category>
            <category><![CDATA[google-cloud-platform]]></category>
            <dc:creator><![CDATA[Siddharth Satpute]]></dc:creator>
            <pubDate>Thu, 30 Mar 2023 10:04:24 GMT</pubDate>
            <atom:updated>2023-03-30T15:11:39.016Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vbUAyC13YY6ue_P9fwhGbQ.jpeg" /></figure><h3>Introduction</h3><p>Minikube is a lightweight tool that enables you to run a single-node Kubernetes cluster on your local machine. This can be useful for developers who want to test their applications in a Kubernetes environment before deploying them to production. In this article, we will walk you through the steps to install Minikube on a Google Cloud VM instance.</p><h3>Demo on Installing minikube on Google Cloud</h3><p><strong><em>Step 1</em></strong><em> : </em>Create a new GCP VM</p><p>Follow the instructions on the GCP documentation to create a new VM. Make sure to select an appropriate machine type and operating system.</p><p><a href="https://cloud.google.com/compute/docs/instances/create-start-instance">Create and start a Compute Engine instance | Compute Engine Documentation | Google Cloud</a></p><p><strong><em>Step 2</em></strong><em>: Install Docker as a part of vm automation script</em></p><pre>sudo apt install docker.io</pre><pre>docker --version</pre><p><strong><em>Step 3</em></strong><em>: Run the bellow command which installs all the other </em>dependencies <em>to run minikube</em></p><pre>sudo apt-get update &amp;&amp; sudo apt-get install -y apt-transport-https gnupg2 curl<br>curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -<br>sudo add-apt-repository &quot;deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable&quot;<br>sudo apt-get update &amp;&amp; sudo apt-get install -y docker-ce docker-ce-cli containerd.io<br>sudo curl -Lo /usr/local/bin/kubectl https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl &amp;&amp; sudo chmod +x /usr/local/bin/kubectl<br>sudo apt-get update &amp;&amp; sudo apt-get install -y qemu-kvm libvirt-daemon-system libvirt-clients bridge-utils virt-manager</pre><p>Overall, these commands install the necessary dependencies for running Minikube on a Ubuntu-based system, including kubectl, and a hypervisor.</p><p><strong><em>Step 4</em></strong><em>: Install the minikube using curl command</em></p><pre>curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64<br>sudo install minikube-linux-amd64 /usr/local/bin/minikube</pre><p><strong><em>Step 5: </em></strong>This command is used to start a Kubernetes cluster using Minikube with the Docker container runtime as the drive</p><pre>minikube start --driver=docker</pre><p><strong><em>Step 6: </em></strong>This command is used to add the current user to the docker group and start a new shell with the updated group membership.</p><pre>sudo usermod -aG docker $USER &amp;&amp; newgrp docker</pre><p><strong><em>Step 7: </em></strong>rerun this command</p><pre>minikube start --driver=docker</pre><p><strong><em>Step 8: </em></strong>This command is used to list all the pods in all namespaces of a Kubernetes cluster.</p><pre>kubectl get po -A</pre><p><strong><em>Step 9: </em></strong>to check minikube status</p><pre>minikube status</pre><p><strong><em>Step 10: </em></strong>This command is used to list all the nodes in a Kubernetes cluster.</p><pre>kubectl get node</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vWCzxT1nvCMdjn9o7nA-_g.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*Pn-sMO6UckETF3wwWgCmqg.png" /></figure><h3>Final Verdict :</h3><p>In conclusion, Minikube offers a convenient and easy-to-use solution for testing and developing Kubernetes applications locally. Its simple setup process, compatibility with various operating systems, and extensive documentation make it a popular choice for developers and organizations looking to experiment with Kubernetes without investing in expensive infrastructure. However, it may not be suitable for large-scale production deployments, and users may need to consider other Kubernetes solution</p><p>Drop your comments, feedback, or suggestions below — or connect with me directly on Linked @<a href="https://www.linkedin.com/in/siddharth-satpute/">https://www.linkedin.com/in/siddharth-satpute/</a></p><p>Happy learning !!!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b5ea57cb2204" width="1" height="1" alt=""><hr><p><a href="https://medium.com/google-cloud/how-to-install-minikube-in-google-cloud-vm-instance-b5ea57cb2204">How to install Minikube in Google Cloud Vm Instance</a> was originally published in <a href="https://medium.com/google-cloud">Google Cloud - Community</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Deploying CI/CD for Google Cloud Serverless Cloud Functions]]></title>
            <link>https://medium.com/google-cloud/deploying-ci-cd-for-google-cloud-serverless-cloud-functions-bd106a52e044?source=rss-22f4ef672231------2</link>
            <guid isPermaLink="false">https://medium.com/p/bd106a52e044</guid>
            <category><![CDATA[gcp-security-operations]]></category>
            <category><![CDATA[google-cloud-functions]]></category>
            <category><![CDATA[google-cloud-platform]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[cicd-pipeline]]></category>
            <dc:creator><![CDATA[Siddharth Satpute]]></dc:creator>
            <pubDate>Thu, 16 Feb 2023 05:39:05 GMT</pubDate>
            <atom:updated>2023-03-30T15:11:56.460Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9Hh3R3gMuIQmhZXcD8d92Q.jpeg" /></figure><h3>Introduction</h3><p>As the demand for scalable and efficient cloud solutions grows, serverless computing has emerged as a popular option among developers. Google Cloud Functions is one such serverless computing platform that allows developers to build and deploy event-driven applications and microservices without worrying about infrastructure management. Additionally, Google Cloud Build offers a continuous integration and delivery platform that automates the entire development workflow, from building and testing to deploying code changes.</p><p>In this blog post, we’ll explore how to deploy CI/CD for Google Cloud Serverless Cloud Functions by integrating Google Cloud Functions with Google Cloud Build. This integration allows developers to streamline the process of building, testing, and deploying their Cloud Functions code, enabling them to release changes more quickly and with greater confidence. So, whether you’re a seasoned developer or just getting started with serverless computing, this post is for you!</p><h3>What is Google Cloud Function ?</h3><p>Google Cloud Functions is a service that lets you run code in response to events such as a new HTTP request, an upload to a storage bucket, an invocation from a Google service, and more.</p><p>Cloud Functions lets you run code in response to one of these events without having to provision any servers or manage any infrastructure. You can write code in languages such as Python, Go, Java,.NET and Ruby</p><p>You can use Cloud Functions to event-driven computing, where the function is triggered in response to an event. For example, you can use Cloud Functions to respond to new images uploaded to a Google Cloud Storage bucket or process a payment from a web hook that your e-commerce store receives from a payment processor.</p><h3>What is Cloud Build?</h3><p>Cloud Build is a service that executes your builds on Google Cloud Platform infrastructure.</p><p>Cloud Build can import source code from Google Cloud Storage, Cloud Source Repositories, GitHub, or Bitbucket, execute a build to your specifications, and produce artifacts.</p><p>Cloud Build executes your build as a series of build steps, where each build step is run in a Docker container by a builder image.</p><h3>Why Cloud build + Cloud functions</h3><p>Google Cloud Functions is a serverless computing platform that allows developers to build and deploy event-driven applications and microservices. It provides a cost-effective way to run code without having to manage servers, and automatically scales based on incoming requests.</p><p>On the other hand, Google Cloud Build is a continuous integration and delivery platform that automates the process of building, testing, and deploying code changes. By integrating Cloud Build with Cloud Functions, developers can automate the entire process of building, testing, and deploying their code changes to Cloud Functions, enabling them to release changes more quickly and with greater confidence.</p><p>This integration helps developers to speed up the development process and improve the quality of their code by automating repetitive tasks and allowing them to focus on writing and testing code. With the help of Cloud Build, developers can easily configure and automate their build, test, and deployment pipelines, and with Cloud Functions, they can build and deploy serverless applications that scale automatically based on incoming requests.</p><p>Therefore, the combination of Cloud Build and Cloud Functions provides a powerful toolset for building, testing, and deploying serverless applications on the Google Cloud Platform.</p><h3>Implementing CI/CD with Cloud function</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rw5SFR9NaDa1HeI3XEXwtA.jpeg" /></figure><p>Write the Cloud Function code and push it to the Git repository.</p><p>Set up Cloud Build by creating a cloudbuild.yaml file in the root directory of your Git repository. This file defines the build steps and triggers for Cloud Build.</p><p>Define the build steps in the cloudbuild.yaml file. For example, you may want to run tests, build the function, and deploy it to a development environment.</p><p>Configure triggers for Cloud Build. You can trigger a build when new code is pushed to the Git repository or on a schedule.</p><p>Set up a development environment for your Cloud Function. This could be a Cloud Function deployed to a development project or a virtual machine.</p><p>Set up the production environment for your Cloud Function.</p><p>Configure Cloud Build to deploy the Cloud Function to the development environment when the build is successful.</p><p>Test the Cloud Function in the development environment and make any necessary changes.</p><p>Configure Cloud Build to deploy the Cloud Function to devlopment envierment</p><h3>Overview</h3><p>Here’s an overview of how the integration works:</p><ol><li>Clone the source code containing cloud build configuration files.</li><li>Configure cloudbuild.yaml file with gcloud builder and define the build steps.</li><li>Compress the file containing main.py and requirements.txt as cloud-function-source.zip and submit it to Cloud Build using gcloud builds submit command.</li><li>Create a trigger in Cloud Build to invoke the build process whenever changes are made to the repository in GitHub.</li><li>Modify the main.py file in the GitHub repository to update the Hello World message.</li><li>As soon as changes are made in the repository, a new build will automatically trigger in Cloud Build and the new function will be deployed.</li><li>Test the deployed function to verify the changes made to the code.</li></ol><h3>Demo on the CI/CD Using Cloud Function &amp; Cloud build</h3><p>Step 1 : Clone the source code containing cloud build configuration files</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*emf02SXSELuhlQIy.png" /><figcaption>Contents of main.py</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Ie7vKTU5V1rWlSpX.png" /><figcaption>Configuration of cloudbuild.yaml file with gcloud builder</figcaption></figure><pre>steps:<br>- name: &#39;gcr.io/cloud-builders/gcloud&#39;<br>  args:<br>  - functions<br>  - deploy<br>  - hello_world<br>  - --source=.<br>  - --trigger-http<br>  - --runtime=python37<br>  - --allow-unauthenticated</pre><p>Cloud build is a serverless CI/CD platform on google cloud it has a build configuration which consists of build steps and each step is run into a docker container</p><p>Cloud builders are nothing but a bunch of Docker container images, so we are going to use the gCloud image here.</p><p>Below are the sample builders from the documentation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*B6mbzyypgmMKj6sp.png" /></figure><p>Step 2 : Compress the file which contains main.py and the dependencies file requirements.txt and give it the name cloud-function-source.zip and run the following gcloud commands</p><pre>gcloud builds submit - config cloudbuild.yaml cloud-function-source.zip</pre><pre>gcloud config set project PROJECT_ID</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*xBMrXBPP7Fk_BtvF.png" /><figcaption>cloud build history</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*0GPoF1onYD7KYtTN.png" /><figcaption>cloud function deploy</figcaption></figure><p><strong>Now lets jump into the demo</strong></p><p>So now we will trigger the deployed function as soon as there are changes made to the repository in this case, which is GitHub. Go to the triggers section in CloudBuild and create a new trigger. Assume you don’t already have a repository; you’ll need to create one (on GitHub), then connect your GitHub account. (Because your GitHub needs permission to send a hook whenever a new commit is made to the branch)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*DKHc-vXB9dGtDftA.png" /><figcaption>Connect the Github Repository</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*d6g_t9Q1eq_BUO2w.png" /><figcaption>edit the trigger</figcaption></figure><p>Once the above step is done, you will have the trigger created. Now, go to the triggers under the “cloud build” section and configure them in such a way that if I make any change in any branch, this trigger will be invoked. What this does is find the build configuration file, cloudbuild.yaml.</p><p>Now, I will go to my GitHub account and update the main.py file and edit the Hello World message.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*kKJVPvSPaPOonVG9.jpeg" /><figcaption>modified code</figcaption></figure><pre><br><br>def hello_world(request):<br>    &quot;&quot;&quot;Responds to any HTTP request.<br>    Args:<br>        request (flask.Request): HTTP request object.<br>    Returns:<br>        The response text or any set of values that can be turned into a<br>        Response object using<br>        `make_response &lt;http://flask.pocoo.org/docs/1.0/api/#flask.Flask.make_response&gt;`.<br>    &quot;&quot;&quot;<br>    request_json = request.get_json()<br>    if request.args and &#39;message&#39; in request.args:<br>        return request.args.get(&#39;message&#39;)<br>    elif request_json and &#39;message&#39; in request_json:<br>        return request_json[&#39;message&#39;]<br>    else:<br>        return f&#39;Hello World!!!&#39;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*5W_8kr1ki5tZTD9Q.png" /></figure><p>Once I Committed the code a new build will trigger automatically along with that you also get a commit id which will redirect to the GitHub page where the commit was made</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*cyBI8J4Ktt-Do03_.jpeg" /><figcaption>The New Function got successfully deployed</figcaption></figure><p><strong>Testing the deployed function</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*xseyupJltRgNqAha.jpeg" /><figcaption>Testing the deployed function</figcaption></figure><p>we can see the modified changes of main.py in the output section in the console</p><h3>Final Verdict :</h3><p>Cloud Functions on Google Cloud Platform (GCP) is a powerful and flexible serverless computing platform that allows developers to easily create and deploy code without having to worry about the underlying infrastructure. In this blog, we have explored various aspects of Google Cloud Functions, including its features, use cases, and benefits.</p><p>One of the main benefits of Cloud Functions is its pay-per-use pricing model, which allows developers to pay only for the resources they consume, with no upfront costs or long-term commitments. This makes it a cost-effective option for both small and large-scale applications.</p><p>In addition, Google Cloud Functions offers robust security features, including isolation of customer data and resources, automatic security updates, and built-in encryption. This makes it a secure platform for building and deploying critical applications.</p><p>Overall, Google Cloud Functions provides a simple and efficient way for developers to build and deploy serverless applications. With its ease of use, flexibility, and cost-effectiveness, it is a compelling option for any developer looking to build modern, event-driven applications on the cloud.</p><p><strong>References</strong>: <a href="https://cloud.google.com/functions/docs/testing/test-cicd">https://cloud.google.com/functions/docs/testing/test-cicd</a></p><p>Drop your comments, feedback, or suggestions below — or connect with me directly on Linked @<a href="https://www.linkedin.com/in/siddharth-satpute/">https://www.linkedin.com/in/siddharth-satpute/</a></p><p>Happy learning !!!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bd106a52e044" width="1" height="1" alt=""><hr><p><a href="https://medium.com/google-cloud/deploying-ci-cd-for-google-cloud-serverless-cloud-functions-bd106a52e044">Deploying CI/CD for Google Cloud Serverless Cloud Functions</a> was originally published in <a href="https://medium.com/google-cloud">Google Cloud - Community</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>