{"id":124777,"date":"2026-07-31T13:44:15","date_gmt":"2026-07-31T08:14:15","guid":{"rendered":"https:\/\/www.guvi.in\/blog\/?p=124777"},"modified":"2026-07-31T13:44:17","modified_gmt":"2026-07-31T08:14:17","slug":"how-to-deploy-infrastructure-programmatically-with-pulumi-automation-api","status":"publish","type":"post","link":"https:\/\/www.guvi.in\/blog\/how-to-deploy-infrastructure-programmatically-with-pulumi-automation-api\/","title":{"rendered":"How to Deploy Infrastructure Programmatically with Pulumi Automation API"},"content":{"rendered":"\n<p>Modern cloud teams need faster and safer ways to manage infrastructure beyond manual CLI commands. Pulumi Automation API helps developers run Pulumi programs directly from code and control workflows like preview, deploy, refresh, and destroy. This makes it useful for CI\/CD pipelines, internal platforms, and automated cloud provisioning.<\/p>\n\n\n\n<p>Read this Pulumi Automation API tutorial to understand how it works, why developers use it, and how to create infrastructure through a simple code-driven workflow.<\/p>\n\n\n\n<p><strong>TL;DR:<\/strong><\/p>\n\n\n\n<ul>\n<li><em>Pulumi Automation API lets developers run infrastructure workflows directly from application code.<\/em><\/li>\n<\/ul>\n\n\n\n<ul>\n<li><em>It helps automate Pulumi operations like preview, deploy, refresh, destroy, and stack output reading.<\/em><\/li>\n\n\n\n<li><em>Teams can use it to build CI\/CD workflows, internal developer platforms, and self-service cloud tools.<\/em><\/li>\n\n\n\n<li><em>The tutorial shows how to create an inline Pulumi program, select a stack, configure AWS, and deploy an S3 bucket.<\/em><\/li>\n\n\n\n<li><em>Pulumi Automation API is useful when infrastructure deployment needs to be repeatable, programmable, and closely connected with application workflows.<\/em><\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>What is Pulumi Automation API?<\/strong><\/h2>\n\n\n\n<p>Pulumi Automation API is a programmable interface that lets you run Pulumi infrastructure operations from your own application code.<\/p>\n\n\n\n<p>Normally, developers use Pulumi through CLI commands such as:<\/p>\n\n\n\n<p>pulumi preview<\/p>\n\n\n\n<p>pulumi up<\/p>\n\n\n\n<p>pulumi refresh<\/p>\n\n\n\n<p>pulumi destroy<\/p>\n\n\n\n<p>With Automation API, these actions can be handled inside a Node.js, TypeScript, Python, Go, or <a href=\"https:\/\/www.guvi.in\/hub\/cpp\/\">C# <\/a>application. This means your program can create stacks, set configurations, run previews, deploy resources, read outputs, and clean up infrastructure automatically.<\/p>\n\n\n\n<p>Pulumi Automation API is useful when teams want to build:<\/p>\n\n\n\n<ul>\n<li>Internal developer platforms<\/li>\n\n\n\n<li>Self-service cloud provisioning tools<\/li>\n\n\n\n<li><a href=\"https:\/\/www.guvi.in\/blog\/ci-cd-for-full-stack-applications\/\" target=\"_blank\" rel=\"noreferrer noopener\">CI\/CD deployment workflows<\/a><\/li>\n\n\n\n<li>Preview environments for pull requests<\/li>\n\n\n\n<li>Temporary test infrastructure<\/li>\n\n\n\n<li>Automated cleanup systems<\/li>\n<\/ul>\n\n\n\n<p>In simple terms, Pulumi Automation API helps teams treat infrastructure deployment as part of their application logic.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Pulumi Automation API Tutorial: Deploy Infrastructure Programmatically<\/strong><\/h2>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>1. Install Pulumi and Set Up Your Project<\/strong><\/h3>\n\n\n\n<p>Start by installing Pulumi and creating a new Node.js or TypeScript project. Automation API works with Pulumi SDKs, so your project needs the Pulumi package and the required cloud provider package.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>mkdir pulumi-automation-demo\n\ncd pulumi-automation-demo\n\nnpm init -y\n\nnpm install @pulumi\/pulumi @pulumi\/pulumi\/automation @pulumi\/aws<\/code><\/pre>\n\n\n\n<p>This setup gives your application access to Pulumi resources and Automation API methods.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>2. Create an Inline Pulumi Program<\/strong><\/h3>\n\n\n\n<p>An inline program defines infrastructure inside the same application file. This is useful when you want infrastructure creation to be controlled by a script, backend service, internal dashboard, or CI\/CD workflow.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import * as aws from \"@pulumi\/aws\";\n\nconst pulumiProgram = async () =&gt; {\n\n&nbsp;&nbsp;const bucket = new aws.s3.Bucket(\"automation-api-bucket\");\n\n&nbsp;&nbsp;return {\n\n&nbsp;&nbsp;&nbsp;&nbsp;bucketName: bucket.id,\n\n&nbsp;&nbsp;};\n\n};<\/code><\/pre>\n\n\n\n<p>The program above creates an AWS S3 bucket and exports the bucket name as stack output.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>3. Create or Select a Stack<\/strong><\/h3>\n\n\n\n<p>A stack is an isolated environment for your infrastructure. Teams usually create separate stacks for development, staging, and production. Pulumi Automation API exposes stack lifecycle methods such as up, preview, refresh, and destroy.&nbsp;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import * as auto from \"@pulumi\/pulumi\/automation\";\n\nconst stack = await auto.LocalWorkspace.createOrSelectStack({\n\n&nbsp;&nbsp;stackName: \"dev\",\n\n&nbsp;&nbsp;projectName: \"automation-api-demo\",\n\n&nbsp;&nbsp;program: pulumiProgram,\n\n});<\/code><\/pre>\n\n\n\n<p>This code creates the stack if it does not exist. It selects the stack if it already exists.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>4. Install Required Plugins<\/strong><\/h3>\n\n\n\n<p>Pulumi providers need plugins to communicate with cloud platforms. Install the <a href=\"https:\/\/www.guvi.in\/blog\/guide-for-amazon-web-services\/\" target=\"_blank\" rel=\"noreferrer noopener\">AWS plugin<\/a> before running the deployment.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>await stack.workspace.installPlugin(\"aws\", \"v6.0.0\");<\/code><\/pre>\n\n\n\n<p>This step prepares the workspace to create AWS resources.<\/p>\n\n\n\n<p><em>Build strong Python programming skills with HCL GUVI\u2019s <\/em><a href=\"https:\/\/www.guvi.in\/courses\/programming\/python\/?utm_source=blog&amp;utm_medium=hyperlink&amp;utm_campaign=how-to-deploy-infrastructure-programmatically-with-pulumi-automation-api\" target=\"_blank\" rel=\"noreferrer noopener\"><em>Python Course<\/em><\/a><em>. Learn Python fundamentals, automation logic, scripting workflows, and real-world programming applications through 100% online self-paced learning, industry-recognised certification, lifetime content access, dedicated forum support, and 4 gamified practice platforms.<\/em><\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>5. Configure Cloud Region<\/strong><\/h3>\n\n\n\n<p>Set stack configuration before deployment. Configuration values are stored against the selected stack.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>await stack.setConfig(\"aws:region\", {\n\n&nbsp;&nbsp;value: \"us-east-1\",\n\n});<\/code><\/pre>\n\n\n\n<p>This tells Pulumi where AWS resources should be created.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>6. Run a Preview Before Deployment<\/strong><\/h3>\n\n\n\n<p>The preview step shows what Pulumi plans to create, update, or delete. This helps catch mistakes before applying infrastructure changes.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>const previewResult = await stack.preview({\n\n&nbsp;&nbsp;onOutput: console.info,\n\n});<\/code><\/pre>\n\n\n\n<p>Use preview in <a href=\"https:\/\/www.guvi.in\/blog\/understanding-ci-cd\/\" target=\"_blank\" rel=\"noreferrer noopener\">CI\/CD pipelines<\/a> to review infrastructure changes before production deployment.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>7. Deploy Infrastructure with <\/strong><strong>up<\/strong><\/h3>\n\n\n\n<p>Run the up method to apply the infrastructure changes.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>const upResult = await stack.up({\n\n&nbsp;&nbsp;onOutput: console.info,\n\n});\n\nconsole.log(\"Deployment complete\");\n\nconsole.log(upResult.outputs);<\/code><\/pre>\n\n\n\n<p>This command provisions the resources defined in the Pulumi program and returns stack outputs.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>8. Read Stack Outputs<\/strong><\/h3>\n\n\n\n<p>Stack outputs help pass infrastructure values to other systems. For example, you can use the S3 bucket name in backend code, frontend configuration, or another deployment workflow.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>const outputs = await stack.outputs();\n\nconsole.log(\"Bucket Name:\", outputs.bucketName.value);<\/code><\/pre>\n\n\n\n<p>This makes <a href=\"https:\/\/www.guvi.in\/blog\/api-response-structure-best-practices\/\" target=\"_blank\" rel=\"noreferrer noopener\">Automation API<\/a> useful for internal developer platforms and deployment portals.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>9. Refresh Stack State<\/strong><\/h3>\n\n\n\n<p>Use refresh when you want Pulumi to compare the stack state with the real cloud environment.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>await stack.refresh({\n\n&nbsp;&nbsp;onOutput: console.info,\n\n});<\/code><\/pre>\n\n\n\n<p>This is helpful when resources were changed outside Pulumi.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>10. Destroy Resources When Needed<\/strong><\/h3>\n\n\n\n<p>The destroy step removes resources managed by the stack.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>await stack.destroy({\n\n&nbsp;&nbsp;onOutput: console.info,\n\n});<\/code><\/pre>\n\n\n\n<p>Use this carefully in production environments. It is useful for temporary environments, test infrastructure, preview deployments, and cleanup workflows.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>11. Add Error Handling<\/strong><\/h3>\n\n\n\n<p>Production workflows should include error handling around stack operations.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>try {\n\n&nbsp;&nbsp;await stack.up({\n\n&nbsp;&nbsp;&nbsp;&nbsp;onOutput: console.info,\n\n&nbsp;&nbsp;});\n\n} catch (error) {\n\n&nbsp;&nbsp;console.error(\"Deployment failed:\", error);\n\n}<\/code><\/pre>\n\n\n\n<p>This helps prevent silent deployment failures and makes debugging easier.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>12. Use Automation API in CI\/CD or Internal Tools<\/strong><\/h3>\n\n\n\n<p>Pulumi Automation API is most powerful when used inside custom workflows. You can use it to build self-service deployment tools, preview environments, testing pipelines, cloud provisioning dashboards, and automated cleanup scripts.<\/p>\n\n\n\n<p>Instead of asking developers to run Pulumi commands manually, your application can control infrastructure changes through code.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Conclusion<\/strong><\/h2>\n\n\n\n<p>Pulumi Automation API makes infrastructure deployment more flexible and developer-friendly. It gives teams a way to control Pulumi operations directly from code instead of depending only on manual CLI workflows.<\/p>\n\n\n\n<p>This is especially useful for teams building internal tools, automated deployment systems, and cloud provisioning platforms. Developers can create stacks, configure cloud regions, preview changes, deploy infrastructure, read outputs, and destroy resources from one controlled workflow.<\/p>\n\n\n\n<p>Pulumi Automation API is a strong choice when your infrastructure needs to work closely with your application, CI\/CD pipeline, or platform engineering setup.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>FAQs<\/strong><\/h2>\n\n\n<div id=\"rank-math-faq\" class=\"rank-math-block\">\n<div class=\"rank-math-list \">\n<div id=\"faq-question-1784585438235\" class=\"rank-math-list-item\">\n<h3 class=\"rank-math-question \"><strong>What is Pulumi Automation API?<\/strong><\/h3>\n<div class=\"rank-math-answer \">\n\n<p>Pulumi Automation API lets developers run Pulumi infrastructure operations directly from application code.<\/p>\n\n<\/div>\n<\/div>\n<div id=\"faq-question-1784585441230\" class=\"rank-math-list-item\">\n<h3 class=\"rank-math-question \"><strong>Why use Pulumi Automation API?<\/strong><\/h3>\n<div class=\"rank-math-answer \">\n\n<p>Pulumi Automation API helps automate infrastructure deployment, stack management, preview workflows, and cleanup tasks.<\/p>\n\n<\/div>\n<\/div>\n<div id=\"faq-question-1784585456047\" class=\"rank-math-list-item\">\n<h3 class=\"rank-math-question \"><strong>Is Pulumi Automation API used in CI\/CD?<\/strong><\/h3>\n<div class=\"rank-math-answer \">\n\n<p>Yes, Pulumi Automation API is commonly used in CI\/CD pipelines to preview and deploy infrastructure changes.<\/p>\n\n<\/div>\n<\/div>\n<div id=\"faq-question-1784585489763\" class=\"rank-math-list-item\">\n<h3 class=\"rank-math-question \"><strong>Does Pulumi Automation API replace Pulumi CLI?<\/strong><\/h3>\n<div class=\"rank-math-answer \">\n\n<p>Pulumi Automation API does not fully replace the CLI. It uses Pulumi programmatically to control infrastructure workflows from code.<\/p>\n\n<\/div>\n<\/div>\n<div id=\"faq-question-1784585492481\" class=\"rank-math-list-item\">\n<h3 class=\"rank-math-question \"><strong>Which languages support Pulumi Automation API?<\/strong><\/h3>\n<div class=\"rank-math-answer \">\n\n<p>Pulumi Automation API supports popular languages such as TypeScript, JavaScript, <a href=\"https:\/\/www.guvi.in\/blog\/guide-to-python-web-development\/\">Python<\/a>, Go, and C#.<\/p>\n\n<\/div>\n<\/div>\n<\/div>\n<\/div>","protected":false},"excerpt":{"rendered":"<p>Modern cloud teams need faster and safer ways to manage infrastructure beyond manual CLI commands. Pulumi Automation API helps developers run Pulumi programs directly from code and control workflows like preview, deploy, refresh, and destroy. This makes it useful for CI\/CD pipelines, internal platforms, and automated cloud provisioning. Read this Pulumi Automation API tutorial to [&hellip;]<\/p>\n","protected":false},"author":60,"featured_media":128512,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[294],"tags":[],"views":"28","authorinfo":{"name":"Vaishali","url":"https:\/\/www.guvi.in\/blog\/author\/vaishali\/"},"thumbnailURL":"https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2026\/07\/Pulumi-Automation-API-300x116.webp","_links":{"self":[{"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/posts\/124777"}],"collection":[{"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/users\/60"}],"replies":[{"embeddable":true,"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/comments?post=124777"}],"version-history":[{"count":3,"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/posts\/124777\/revisions"}],"predecessor-version":[{"id":128516,"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/posts\/124777\/revisions\/128516"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/media\/128512"}],"wp:attachment":[{"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/media?parent=124777"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/categories?post=124777"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/tags?post=124777"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}