<?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 Rovin D&#39;Souza on Medium]]></title>
        <description><![CDATA[Stories by Rovin D&#39;Souza on Medium]]></description>
        <link>https://medium.com/@rovinabi?source=rss-d0ae7001fc17------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*zHJ7c4QZ8jqUFiYT.jpg</url>
            <title>Stories by Rovin D&amp;#39;Souza on Medium</title>
            <link>https://medium.com/@rovinabi?source=rss-d0ae7001fc17------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 15:11:30 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@rovinabi/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[Can we un-taint a resource using terraform import blocks?]]></title>
            <link>https://medium.com/@rovinabi/can-we-un-taint-a-resource-using-terraform-import-blocks-b6d3e6023852?source=rss-d0ae7001fc17------2</link>
            <guid isPermaLink="false">https://medium.com/p/b6d3e6023852</guid>
            <category><![CDATA[terraform]]></category>
            <dc:creator><![CDATA[Rovin D'Souza]]></dc:creator>
            <pubDate>Thu, 20 Aug 2026 05:23:17 GMT</pubDate>
            <atom:updated>2026-08-20T05:23:17.848Z</atom:updated>
            <content:encoded><![CDATA[<h4>The short answer is <strong>NO</strong>.</h4><p>At first glance, this might look like a very dumb article topic. Why write a whole post about a simple “no”? The reason is simple: if you do a quick Google search with this exact question today, the AI-generated summaries and some top results will likely tell you that <em>yes</em>, it is supported.</p><p>I’m writing this to save you from the embarrassment of going to your peers, your team, or your customers and confidently claiming you can un-taint a resource with an import block, just because a search summary told you so. Let’s set the record straight.</p><h3>The Danger of Tainted Resources</h3><p>If you approve a terraform apply with a resource marked as tainted, Terraform will perform a destructive action: the resource will be <strong>deleted and recreated</strong>.</p><p>If you are dealing with a standard, stateless resource (like a simple compute instance or a load balancer rule), this might be fine. But if you are dealing with critical infrastructure like a <strong>GCP Project</strong>, a <strong>KMS Keyring</strong>, or a <strong>Database</strong> — essentially any resource holding production data — this will absolutely not work for you. Recreating a keyring, for example, is not only catastrophic but in many cloud providers, it’s virtually impossible to recreate with the exact same name immediately.</p><h3>The Real Solution: terraform untaint</h3><p>The actual solution to this problem is using the terraform untaint command.</p><p>I know what you’re thinking: in an enterprise environment, providers and credentials are injected directly during deployment by a CI/CD pipeline. The state files are locked away tightly, accessible only by specific service accounts, and developers don’t have local access.</p><p>While these strict security measures are best practice, you <strong>must</strong> plan a break-glass option. When production state is on the line and a critical resource is accidentally tainted, you need a secure, audited pipeline or break-glass role that allows you to run terraform untaint against the remote state.</p><h3>How to Fix Your State</h3><p>If you find yourself needing to manually manipulate state, here is how you do it correctly.</p><h4>1. Finding the Terraform Resource Address</h4><p>Before you can run any state manipulation commands, you need to know the exact address of the resource in your Terraform state. There are two primary ways to find this:</p><ul><li><strong>Review your Terraform Plan:</strong> When you run terraform plan, Terraform will explicitly tell you which resource is tainted and slated for replacement.</li><li><strong>List the State:</strong> You can list all resources currently tracked in your state file using the following command:</li></ul><pre>terraform state list</pre><ul><li><em>Output example:</em></li></ul><pre>google_compute_network.vpc_network<br>google_kms_key_ring.my_key_ring<br>google_project.my_project</pre><ul><li>Locate the exact string for the resource you need to fix (e.g., google_kms_key_ring.my_key_ring).</li></ul><h4>2. Using the terraform untaint command</h4><p>Once you have the resource address, you can tell Terraform that the resource is actually perfectly fine and doesn’t need to be recreated.</p><p><em>Note: In Terraform v1.5.0 and later, the </em><em>untaint command is considered deprecated in favor of </em><em>terraform apply -replace, but </em><em>untaint is still the only direct way to manually remove a taint flag from the state file without running an apply.</em></p><p><strong>Syntax:</strong></p><pre>terraform untaint &lt;resource_address&gt;</pre><p><strong>Example:</strong></p><pre>terraform untaint google_kms_key_ring.my_key_ring</pre><p>After running this, Terraform removes the tainted status. Your next terraform plan will show that the resource is in-sync (assuming the code matches the actual cloud configuration), rather than slated for destruction.</p><h4>3. Using the terraform import command</h4><p>If the resource was accidentally deleted from the state file entirely (but still exists in the cloud), you will need to import it. The traditional way to do this is via the CLI command.</p><p><strong>Syntax:</strong></p><pre>terraform import &lt;resource_address&gt; &lt;cloud_resource_id&gt;</pre><p><strong>Example:</strong><br>Let’s say a GCP project was removed from state, but the project my-prod-project-123 still exists.</p><pre>terraform import google_project.my_project my-prod-project-123</pre><p>This tells Terraform to map the existing cloud resource to the google_project.my_project block in your code. <strong>However, this does not &quot;un-taint&quot; a resource that is already in the state file as tainted.</strong></p><h4>4. Using the Terraform import block (Terraform 1.5+)</h4><p>Terraform 1.5 introduced config-driven imports. Instead of running a CLI command, you can write an import block directly into your Terraform code. This is fantastic for bringing unmanaged resources into Terraform via your standard CI/CD pipeline.</p><p><strong>Example:</strong><br>Add this block to your .tf files:</p><pre>import {<br>  to = google_project.my_project<br>  id = &quot;my-prod-project-123&quot;<br>}</pre><p>When you run terraform plan, Terraform will see the block and automatically plan to import the resource into your state.</p><p><strong>Why this won’t un-taint a resource:</strong><br>The import block is strictly for adding a <em>new</em> resource to the state file that Terraform isn&#39;t currently tracking. If the resource is <em>already</em> in the state file but marked as tainted, the import block will conflict and fail. It cannot overwrite or un-taint an existing state entry.</p><h3>Key Takeaway</h3><p>Don’t trust everything the search AI tells you. If your critical resource is tainted, an import block will not save you. Set up a break-glass procedure in your enterprise environments to safely run terraform untaint when disaster strikes.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b6d3e6023852" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The “Easy Mode” for Generating Google Docs: Using the Drive API and HTML]]></title>
            <link>https://medium.com/@rovinabi/the-easy-mode-for-generating-google-docs-using-the-drive-api-and-html-01eb7976df29?source=rss-d0ae7001fc17------2</link>
            <guid isPermaLink="false">https://medium.com/p/01eb7976df29</guid>
            <dc:creator><![CDATA[Rovin D'Souza]]></dc:creator>
            <pubDate>Thu, 18 Dec 2025 03:33:30 GMT</pubDate>
            <atom:updated>2025-12-18T03:33:30.993Z</atom:updated>
            <content:encoded><![CDATA[<p>If you have ever tried to generate a Google Doc programmatically using the official <strong>Google Docs API</strong>, you know the pain. You often end up wrestling with a complex JSON structure, manually defining startIndex, endIndex, and managing a massive array of insertText and updateParagraphStyle requests.</p><p>But there is a better way for many use cases.</p><p>Instead of constructing the document paragraph by paragraph, you can use the <strong>Google Drive API</strong> to upload standard HTML text and ask Google to convert it into a Google Doc on the fly. This article explains how to bypass the complexity of the Docs API by leveraging MIME type conversion.</p><h3>The Concept: MIME Type Conversion</h3><p>Google Drive has a built-in “import” feature that happens automatically when you upload files with specific parameters.</p><ul><li><strong>Source:</strong> Your content is standard HTML (text/html). This allows you to use familiar tags like &lt;h1&gt;, &lt;b&gt;, and standard CSS for formatting.</li><li><strong>Target:</strong> You tell Google Drive the target file type is a Google Doc (application/vnd.google-apps.document).</li></ul><p>The API handles the translation between your HTML tags and the internal Google Docs format, saving you from writing hundreds of lines of schema-compliant JSON.</p><h3>The Code Solution</h3><p>Below is a Node.js implementation using express and the googleapis library. This endpoint accepts an HTML string and a token, then creates a new Google Doc.</p><pre>const { google } = require(&#39;googleapis&#39;);<br>const { Readable } = require(&#39;stream&#39;);<br>const express = require(&#39;express&#39;);<br>const app = express();<br><br>app.post(&#39;/api/export/doc&#39;, async (req, res) =&gt; {<br>    const { token, html: htmlText, title } = req.body;<br><br>    // 1. Basic Validation<br>    if (!token || !htmlText) {<br>        res.status(400).send(&#39;Missing token or htmlText in the request body&#39;);<br>        return;<br>    }<br><br>    const docTitle = title &amp;&amp; typeof title === &#39;string&#39; ? title : &#39;Article Generated using Muse&#39;;<br><br>    // 2. Setup Authentication<br>    const oAuth2Client = new google.auth.OAuth2();<br>    oAuth2Client.setCredentials({<br>        access_token: token<br>    });<br><br>    const drive = google.drive({ version: &#39;v3&#39;, auth: oAuth2Client });<br><br>    // Optional: Set User Project headers if required by your GCP configuration<br>    google.options({<br>        headers: {<br>            &#39;X-Goog-User_project&#39;: &#39;gsd-dentsu-umang&#39;,<br>        }<br>    });<br><br>    // 3. Define Metadata (The Target)<br>    // This tells Drive: &quot;The resulting file should be a Google Doc&quot;<br>    const fileMetadata = {<br>        name: docTitle,<br>        mimeType: &#39;application/vnd.google-apps.document&#39;,<br>    };<br><br>    // 4. Define Media (The Source)<br>    // This tells Drive: &quot;I am sending you HTML text&quot;<br>    const media = {<br>        mimeType: &#39;text/html&#39;,<br>        body: Readable.from(htmlText),<br>    };<br><br>    try {<br>        // 5. Create the file with conversion<br>        const createResponse = await drive.files.create({<br>            requestBody: fileMetadata,<br>            media,<br>            fields: &#39;id, name, webViewLink, webContentLink&#39;,<br>        });<br><br>        const file = createResponse.data;<br><br>        res.status(200).send({<br>            message: &#39;Google Doc created successfully&#39;,<br>            id: file.id,<br>            name: file.name,<br>            webViewLink: file.webViewLink,<br>            webContentLink: file.webContentLink,<br>        });<br><br>    } catch (error) {<br>        console.error(&#39;Error creating doc:&#39;, error);<br>        res.status(500).send(&#39;Failed to create document&#39;);<br>    }<br>});</pre><h3>Key Technical Details</h3><h4>1. The fileMetadata Object</h4><p>This object defines what the file <strong>will become</strong> once it lands in Google Drive.</p><pre>const fileMetadata = {<br>    name: docTitle,<br>    mimeType: &#39;application/vnd.google-apps.document&#39;, // Crucial line<br>};</pre><p>By setting the MIME type to application/vnd.google-apps.document, you are explicitly instructing the Drive API to convert the incoming stream rather than just saving it as an .html file.</p><h4>2. The media Object</h4><p>This object defines what you are <strong>sending</strong>.</p><pre>const media = {<br>    mimeType: &#39;text/html&#39;,<br>    body: Readable.from(htmlText),<br>};</pre><p>Using Readable.from(htmlText) converts your raw string into a stream, which is the format the Google APIs Node.js client expects for file uploads.</p><h3>When to use this approach?</h3><p>This method is not a universal solution, but it excels in specific contexts. The choice between the two APIs largely depends on the trade-off between simplicity and control. The <strong>Google Docs API</strong> is complex, requiring a strict JSON schema where formatting is explicit — you must define styles for every text range. This makes it the better choice for high-precision tasks like complex templates or automated invoices where pixel-perfect positioning is required.</p><p>In contrast, the <strong>Drive API (HTML Conversion)</strong> offers a low-complexity alternative. It relies on a “best-effort” translation where formatting is implicit; for example, an &lt;h1&gt; tag automatically becomes a &quot;Heading 1&quot; in the doc. This makes it ideal for generating articles, reports, and rich-text exports where ease of implementation is prioritized over granular layout control.</p><blockquote><strong>Note:</strong> While this method handles standard formatting (bold, italics, lists, tables, headers) very well, complex CSS layouts (like flexbox or grid) will likely be stripped out or simplified during the conversion process.</blockquote><h3>Conclusion</h3><p>If your goal is to get text, basic tables, and images from your application into a Google Doc quickly, stop building complex JSON payloads. By leveraging the mimeType conversion in the Google Drive API, you can treat Google Docs generation just like rendering a simple web page.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=01eb7976df29" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>