Harnessing Infrastructure as Code (IaC Generator) with AWS CloudFormation: Automating Previously Manual Resources
Introduction:
Do you ever feel like you’re spending more time manually configuring AWS resources than building your actual applications? If you’ve got a collection of AWS resources that you created by hand, you’re not alone. But there’s a better way! This guide will show you how to leverage the power of Infrastructure as Code (IaC) with AWS CloudFormation to automate the management of your existing resources, saving you time and headaches. We’ll explore the benefits of IaC, how CloudFormation works, and the steps to bring your manually created resources under the control of this powerful tool. Get ready to streamline your workflow and unleash the magic of IaC with CloudFormation!
What is Aws Cloudformation:
AWS CloudFormation is an infrastructure automation service that lets you define and deploy your AWS resources using code templates. Instead of manually provisioning and configuring each resource, you write a template that describes your infrastructure. CloudFormation then takes care of creating and managing all the resources you specify, ensuring consistency and repeatability. This frees you up from tedious tasks and lets you focus on building your applications.
Challenges we are facing in the Cloud:
The cloud’s allure is undeniable, but maximizing its benefits requires a shift in mindset. While cost, time, and recovery objectives (RTO/RPO) are crucial, many overlook the hidden time-suck and risk of manual infrastructure provisioning and management. This manual approach not only drives up costs but also introduces inconsistencies and potential errors.
This highlights a critical gap — optimizing team efficiency within the cloud environment.
Solution:
This is where Infrastructure as Code (IaC) comes in. By automating infrastructure management through IaC, we can unleash a new level of efficiency, freeing teams to focus on higher-value activities and innovation.
IAC Generator:
The IaC generator in AWS CloudFormation is a time-saving tool that helps you bring existing, manually created resources under IaC management. It scans your account, identifies your resources, and generates a CloudFormation template that represents them. This template becomes the code for provisioning and managing those resources.
Think of it like creating a blueprint of your existing infrastructure. The IaC generator automates the blueprint creation, saving you the effort of writing the template by hand. While some manual adjustments might be needed, it provides a solid foundation for IaC with CloudFormation.
Excited? Let Deep Dive into the HandsOn
Environment Details:
- We have an existing Aws Account.
- A VPC is manually Created.
Generating and using a template
This section describes how to create a template, add resources to your template, and import resources from the template into a stack using the IaC generator feature.
To open a new template using the IaC generator
- Sign in to the AWS Management Console and open the AWS CloudFormation console at https://console.aws.amazon.com/cloudformation.
- From the navigation pane, choose IaC generator.

3. From the Scans panel, choose Start a new scan. Scans discover the resources provisioned in your account and the relationship between resources. The more resources you have in your account in the Region, the longer the scan takes.


4. From the Templates panel, choose Create template.


- Select Start from a new template.
- In the Template name panel, enter a name for your generated template.
- (Optional) Configure your Deletion policy and Update replace policy.
- Choose Next to add scanned resources to the template.
To add scanned resources to your template
- From the list of scanned resources, browse the list of scanned resources. You can filter the resources by resource identifier, resource type, or tags. The filters are mutually inclusive.
- Select the resource or resources you want to add.
- Repeat Steps 1 and 2, until you’ve added all needed resources to your template.


5. Choose Next to exit the Add scanned resources page and proceed to the Add related resources page.



6. Review a recommended list of related resources. Related resources, such as Amazon EC2 instances and security groups, are interdependent and typically belong to the same workload. Select the related resources that you want to include in the generated template.
7. Review the template details, scanned resources, and related resources. Choose Edit to make any changes.

8. Choose to Create a template to exit the Review and create a page and create the template.

9. Wait for the Cloudformation template to be created via IAC generator.

10. Review the Cloudfromation Template Definition and Template Resources from the console.


11. Download the Cloud formation template and make changes if required.

12. Import the Template. Click on the import to stack option and provide the details as described below








Conclusion:
With the successful import of your entire networking stack, it’s time to level up your infrastructure management! For enhanced collaboration and future updates, consider storing this CloudFormation template in a version control system like Git.Remember, to prevent configuration drift (where the actual state differs from the defined configuration), always make changes through CloudFormation going forward.
Documentation Links: