1"use strict";(self.webpackChunkmy_website=self.webpackChunkmy_website||[]).push([[3086],{63123:(e,n,s)=>{s.r(n),s.d(n,{assets:()=>l,contentTitle:()=>r,default:()=>u,frontMatter:()=>t,metadata:()=>o,toc:()=>c});var i=s(74848),a=s(28453);const t={title:"Pulumi - RDS",authors:["nick"],date:new Date("2024-09-27T03:00:00.000Z"),description:"Using Pulumi to create and manage AWS RDS Databases.",image:"../../static/img/pulumi.svg",slug:"pulumi-rds",group:"devops",tags:["Pulumi","IAC","AWS","RDS"],draft:!1},r=void 0,o={permalink:"/posts/pulumi-rds",source:"@site/blog/pulumi-rds/index.mdx",title:"Pulumi - RDS",description:"Using Pulumi to create and manage AWS RDS Databases.",date:"2024-09-27T03:00:00.000Z",tags:[{label:"Pulumi",permalink:"/posts/tags/pulumi"},{label:"IAC",permalink:"/posts/tags/iac"},{label:"AWS",permalink:"/posts/tags/aws"},{label:"RDS",permalink:"/posts/tags/rds"}],readingTime:2.97,hasTruncateMarker:!1,authors:[{name:"Nick Coughlin",title:"[email protected]",url:"https://github.com/ncoughlin",imageURL:"https://github.com/ncoughlin.png",key:"nick"}],frontMatter:{title:"Pulumi - RDS",authors:["nick"],date:"2024-09-27T03:00:00.000Z",description:"Using Pulumi to create and manage AWS RDS Databases.",image:"../../static/img/pulumi.svg",slug:"pulumi-rds",group:"devops",tags:["Pulumi","IAC","AWS","RDS"],draft:!1}
1,unlisted:!1,prevItem:{title:"AWS RDS Basics",permalink:"/posts/aws-rds-basics"},nextItem:{title:"Pulumi - API Gateway",permalink:"/posts/pulumi-api-gateway"}},l={authorsImageUrls:[void 0]},c=[{value:"Resources",id:"resources",level:2},{value:"Why use IAC for Databases?",id:"why-use-iac-for-databases",level:2},{value:"Sample",id:"sample",level:2}];function d(e){const n={a:"a",code:"code",h2:"h2",li:"li",ol:"ol",p:"p",pre:"pre",ul:"ul",...(0,a.R)(),...e.components};return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(n.h2,{id:"resources",children:"Resources"}),"\n",(0,i.jsx)(n.p,{children:(0,i.jsx)(n.a,{href:"https://www.pulumi.com/registry/packages/aws/api-docs/rds/",children:"\ud83d\udcd8 Pulumi Docs > aws.rds "})}),"\n",(0,i.jsx)(n.h2,{id:"why-use-iac-for-databases",children:"Why use IAC for Databases?"}),"\n",(0,i.jsx)(n.p,{children:"One of the things that initially confused me about using IAC for databases is the following. Why would we use IAC to create a database in the first place? It's not like other resources that can be generated and deleted on the fly, like API's and Lambdas. Databases need to be persistent."}),"\n",(0,i.jsx)(n.p,{children:"Here's why provisioning databases with code is beneficial, even when data persistence is a requirement:"}),"\n",(0,i.jsxs)(n.ol,{children:["\n",(0,i.jsxs)(n.li,{children:["\n",(0,i.jsx)(n.p,{children:"Consistency and Reproducibility:"}),"\n",(0,i.jsxs)(n.ul,{children:["\n",(0,i.jsx)(n.li,{children:"Eliminate Human Error: Manual creation is prone to mistakes. With IaC, you ensure that the infrastructure is set up the same way every time."}),"\n",(0,i.jsx)(n.li,{children:"Environment Parity: Easily replicate the same database setup across development, staging, and production environments."}),"\n"]}),"\n"]}),"\n",(0,i.jsxs)(n.li,{children:["\n",(0,i.jsx)(n.p,{children:"Version Control and Auditing:"}),"\n",(0,i.jsxs)(n.ul,{children:["\n",(0,i.jsx)(n.li,{children:"Track Changes: IaC allows you to keep your infrastructure configurations in version control systems like Git. This makes it easy to track changes over time."}),"\n",(0,i.jsx)(n.li,{children:"Audit Trails: You can see who changed what and when, aiding in compliance and auditing processes."}),"\n"]}),"\n"]}),"\n",(0,i.jsxs)(n.li,{children:["\n",(0,i.jsx)(n.p,{children:"Automation and Efficiency:"}),"\n",(0,i.jsxs)(n.ul,{children:["\n",(0,i.jsx)(n.li,{children:"Rapid Deployment: Automate the provisioning process, reducing the time it takes to set up or scale your infrastructure."}),"\n",(0,i.jsx)(n.li,{children:"Integration with CI/CD Pipelines: Incorporate infrastructure changes into your deployment pipelines for seamless updates."}),"\n"]}),"\n"]}),"\n",(0,i.jsxs)(n.li,{children:["\n",(0,i.jsx)(n.p,{children:"Disaster Recovery and High Availability:"}),"\n",(0,i.jsxs)(n.ul,{children:["\n",(0,i.jsx)(n.li,{children:"Automated Recovery: In the event of a failure, you can quickly recreate your infrastructure in a different region or account using the same code."}),"\n",(0,i.jsx)(n.li,{children:"Backup and Restore Automation: While the data is persistent, IaC can manage automated backups and restorations as part of the provisioning process."}),"\n"]}),"\n"]}),"\n",(0,i.jsxs)(n.li,{children:["\n",(0,i.jsx)(n.p,{children:"Scalability:"}),"\n",(0,i.jsxs)(n.ul,{children:["\n",(0,i.jsx)(n.li,{children:"Easily Modify Resources: Need a bigger database instance? Change a parameter in your code and re-run it to update the infrastructure."}),"\n",(0,i.jsx)(n.li,{children:"Parameterization: Use variables to adjust configurations dynamically across different environments or scales."}),"\n"]}),"\n"]}),"\n",(0,i.jsxs)(n.li,{children:["\n",(0,i.jsx)(n.p,{children:"Prevent Configuration Drift:"}),"\n",(0,i.jsxs)(n.ul,{children:["\n",(0,i.jsx)(n.li,{children:"Maintain Alignment: Over time, manually managed resources can drift from their intended configurations. IaC ensures the infrastructure stays aligned with the codebase."}),"\n",(0,i.jsx)(n.li,{children:"Validation: Tools often provide ways to validate that the actual infrastructure matches the code, alerting you to discrepancies."}),"\n"]}),"\n"]}),"\n",(0,i.jsxs)(n.li,{children:["\n",(0,i.jsx)(n.p,{children:"Collaboration:"}),"\n",(0,i.jsxs)(n.ul,{children:["\n",(0,i.jsx)(n.li,{children:"Shared Knowledge Base: Teams can collaborate on infrastru
1cture code just like application code, improving overall team efficiency."}),"\n",(0,i.jsx)(n.li,{children:"Onboarding: New team members can get up to speed faster by reading the code rather than sifting through manual setup documents."}),"\n"]}),"\n"]}),"\n",(0,i.jsxs)(n.li,{children:["\n",(0,i.jsx)(n.p,{children:"Security and Compliance:"}),"\n",(0,i.jsxs)(n.ul,{children:["\n",(0,i.jsx)(n.li,{children:"Defined Security Posture: Security groups, network configurations, and access controls are all defined in code, reducing the risk of misconfigurations."}),"\n",(0,i.jsx)(n.li,{children:"Compliance Automation: Easier to enforce compliance standards programmatically."}),"\n"]}),"\n"]}),"\n",(0,i.jsxs)(n.li,{children:["\n",(0,i.jsx)(n.p,{children:"Cost Management:"}),"\n",(0,i.jsxs)(n.ul,{children:["\n",(0,i.jsx)(n.li,{children:"Resource Tracking: Keep track of all resources provisioned, making it easier to identify and eliminate unused or underutilized resources."}),"\n",(0,i.jsx)(n.li,{children:"Automated Teardown: For non-production environments, automate the teardown of resources when they're no longer needed to save costs."}),"\n"]}),"\n"]}),"\n",(0,i.jsxs)(n.li,{children:["\n",(0,i.jsx)(n.p,{children:"Flexibility in Data Management:"}),"\n",(0,i.jsxs)(n.ul,{children:["\n",(0,i.jsx)(n.li,{children:"Data Persistence Strategies: While the database instance is provisioned with IaC, data migration and seeding scripts can be integrated into the deployment process."}),"\n",(0,i.jsx)(n.li,{children:"Separate Concerns: Manage the lifecycle of the database schema and data independently from the database infrastructure."}),"\n"]}),"\n"]}),"\n"]}),"\n",(0,i.jsx)(n.h2,{id:"sample",children:"Sample"}),"\n",(0,i.jsx)(n.p,{children:"Here is a sample instantiation for a PostgreSQL database."}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-ts",children:"import * as pulumi from '@pulumi/pulumi';\nimport * as aws from '@pulumi/aws';\n\nconst config = new pulumi.Config();\n\n// these values should be moved to a secret manager\nconst db_username = config.require('db_username');\nconst db_password = config.require('db_password');\nconst db_name = config.require('db_name');\n\nexport const sampleDataDB = new aws.rds.Instance('sample-data-postgre-sql', {\n allocatedStorage: 10,\n dbName: db_name,\n engine: 'postgres',\n engineVersion: '16.3',\n instanceClass: aws.rds.InstanceType.T4G_Micro,\n username: db_username,\n password: db_password,\n parameterGroupName: 'default.postgres16',\n skipFinalSnapshot: true,\n publiclyAccessible: true,\n port: 5432,\n});\n"})})]})}function u(e={}){const{wrapper:n}={...(0,a.R)(),...e.components};return n?(0,i.jsx)(n,{...e,children:(0,i.jsx)(d,{...e})}):d(e)}},28453:(e,n,s)=>{s.d(n,{R:()=>r,x:()=>o});var i=s(96540);const a={},t=i.createContext(a);function r(e){const n=i.useContext(t);return i.useMemo((function(){return"function"==typeof e?e(n):{...n,...e}}),[n,e])}function o(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(a):e.components||a:r(e.components),i.createElement(t.Provider,{value:n},e.children)}}}]);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.