Bringing Manually Created Resources Into CloudFormation Management: AWS Global Accelerator
Tags: devops, cloudformation, aws, automation
Published: 2020-07-20 08:54:31

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/ulo41f5yzttmcvzbtl17.png)

## Introduction

If you want to learn more about CloudFormation, or have an existing AWS resources that you want to be managed by CloudFormation. **Go ahead and read on!**

In this post, we’ll be covering how to bring manually created resources of AWS Global Accelerator service into CloudFormation management using Resource Import feature of CloudFormation.

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/8l6qomcmwsthej9p3k8t.png)

> **Q. Why not just re-create it from scratch using CloudFormation?**
Unfortunately, when Global Accelerator is provisioned it associates a set of Static IPs.

> If we re-create it then a set of new Static IPs will be associated, and we’ll have to update DNS in the process, which we do not want.

If you are unfamiliar with AWS Global Accelerator. Learn more about it [here](https://aws.amazon.com/global-accelerator/).

---

## Bringing Into CloudFormation Management

AWS CloudFormation provides following Global Accelerator Resource Types:

1. [AWS::GlobalAccelerator::Accelerator](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-globalaccelerator-accelerator.html)
2. [AWS::GlobalAccelerator::Listener](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-globalaccelerator-listener.html)
3. [AWS::GlobalAccelerator::EndpointGroup](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-globalaccelerator-endpointgroup.html)

In other to bring existing resources under CloudFormation management, we need:

1. **A template that describes the resource we are importing.** For us, we will be creating a new template using above resources.
2. **Identifiers for the resources to import.** For us, we’ll be using ARN as identifiers of our existing resources.

Let’s connect each resource type to our existing Global Accelerator resources and bring them together as a part of one CloudFormation stack.

---

## AWS::GlobalAccelerator::Accelerator

Let’s start-off by importing the following manually created Accelerator resource into a new CloudFormation stack.

![Fig: Global Accelerator resource created outside of CloudFormation](https://dev-to-uploads.s3.amazonaws.com/i/je3nldusok2dnwk87a6a.png)

### 1) Create new template
Save the following template content as **global-accelerator.yaml**. The resource properties values must be identical to existing resource.

> **NOTE:** Import operation doesn’t allow adding new resources, deleting existing resources or changes to resources properties.

* **In line #13:** Setting “DeletionPolicy” is mandatory when importing resource.

{% gist https://gist.github.com/tuladhar-p/d5a23f63db0f2704067b487364ecd706 %}

### 2) Create new stack
Goto AWS CloudFormation Dashboard and click on **Create stack / With existing resources (import resources)**

> **NOTE:** AWS Global Accelerator is currently only supported in us-west-2 region.

![Fig: Create a new stack with existing resources](https://dev-to-uploads.s3.amazonaws.com/i/xi4jh47ek9ffy1gp3mnu.png)

### 3) Upload the template
Let’s upload the new template containing Accelerator resource.

![Fig: Upload new template](https://dev-to-uploads.s3.amazonaws.com/i/gafxqwgfzqgtdtdg7o8f.png)

### 4) Specify the ARN

Copy the ARN of existing Global Accelerator resource from Global Accelerator Dashboard and paste it here.

![Fig: Provide ARN of existing Global Accelerator resource](https://dev-to-uploads.s3.amazonaws.com/i/i8k5gaebb3dehyjptqth.png)

### 5) Stack name and Parameters

Let’s name the new stack and provide stack parameters, eg:

* **Stack name:** frontend-production-accelerator
* **Environment Label:** frontend
* **Environment Type:** production

![Fig: Provide stack name and parameters](https://dev-to-uploads.s3.amazonaws.com/i/cuq6dg9cl1majhux3t5o.png)

### 6) Review and Import

AWS CloudFormation will look up the specified ARN, and lists them in the **“Changes”** section. Go ahead and click **“Import resources”**.

![Fig: Review and Import resources](https://dev-to-uploads.s3.amazonaws.com/i/pdri2zl57o9rhcqjs9yo.png)

After a couple of minutes, Stack Status will show **IMPORT_COMPLETE** as shown below.

![Fig: Resource import complete](https://dev-to-uploads.s3.amazonaws.com/i/tgtfa1onylb2rs20nfpc.png)

> **NOTE:** CloudFormation doesn’t yet support Drift detection for AWS Global Accelerator resources.

---

## AWS::GlobalAccelerator::Listener

Let’s now import the following Listener resource into an existing CloudFormation stack.

![Fig: Listener resource created outside of CloudFormation](https://dev-to-uploads.s3.amazonaws.com/i/jq39vhop10hbhtbho23p.png)

### 1) Update existing template

Add the new Listener resource as shown below. The resource properties values must be identical to existing resource.

* **In line #26:** Setting “DeletionPolicy” is mandatory when importing resource.

{% gist https://gist.github.com/tuladhar-p/11aafc188cc13766cac88dd7a9fa31ef %}

### 2) Modify the stack

Goto AWS CloudFormation Dashboard and select the newly created stack and then click on **Stack action / import resources into stack.**

![Fig 1: Import resources into existing stack](https://dev-to-uploads.s3.amazonaws.com/i/wn06oiasrw2m9t0a0t22.png)

### 3) Upload the template

Let’s upload the updated template with Listener resource.

![Fig: Upload new template](https://dev-to-uploads.s3.amazonaws.com/i/bgdfozw2cnd5zbpg7q5y.png)

### 4) Specify the ARN

Copy the ARN of existing Listener resource from Global Accelerator Dashboard and paste it here.

![Fig: Provide ARN of existing Global Accelerator Listener resource](https://dev-to-uploads.s3.amazonaws.com/i/th0c97ywrupbkbdr0gl1.png)

### 5) Review and Import

Go ahead and click **“Import resources”.**

![Fig: Review and Import resources](https://dev-to-uploads.s3.amazonaws.com/i/vlpukwe58ks0bh6uqcfy.png)

After a couple of minutes, Stack Status will show **IMPORT_COMPLETE** as shown below.

![Fig: Resource import complete](https://dev-to-uploads.s3.amazonaws.com/i/o0bohg6n5ivnit72sgo9.png)

---

## AWS::GlobalAccelerator::EndpointGroup

Finally. Let’s wrap up by importing Endpoint Group resource into an existing CloudFormation stack.

![Fig: Global Accelerator Endpoint Group created outside of CloudFormation](https://dev-to-uploads.s3.amazonaws.com/i/zdbtww56ws77ra65emtv.png)

### 1) Update existing template

Add the new EndpointGroup resource as shown below. The resource properties values must be identical to existing resource.

* **In line #39:** Setting “DeletionPolicy” is mandatory when importing resource.
* **In line #44:** Replace “EndpointId” with an ARN of AWS ALB, NLB or EC2 as configured in the existing resource.

> **NOTE:** CloudFormation doesn’t yet support importing AWS ALB/NLB resource.

{% gist https://gist.github.com/tuladhar-p/29a21ba360a3a4446bbed9cb28a6894e %}

### 2) Modify the stack

Goto AWS CloudFormation Dashboard and select the previously created stack and then click on **Stack action / import resources into stack.**

![Fig 1: Import resource into stack](https://dev-to-uploads.s3.amazonaws.com/i/1lo5gn291c92883xh3ks.png)

### 3) Upload the template

Let’s upload the updated template with EndpointGroup resource.

![Fig: Upload new template](https://dev-to-uploads.s3.amazonaws.com/i/feh3u5z9spie2pr7l3j7.png)

### 4) Specify the ARN

Copy the ARN of existing EndpointGroup resource from Global Accelerator Dashboard and paste it here.

![Fig: Provide ARN of existing Global Accelerator EndpointGroup resource](https://dev-to-uploads.s3.amazonaws.com/i/dx6sgp6iipubvjje51er.png)

### 5) Review and Import

Go ahead and click **“Import resources”.**

![Fig: Review and Import resources](https://dev-to-uploads.s3.amazonaws.com/i/x6zfsaq3n5ruzbsuyrg5.png)

After a couple of minutes, Stack Status will show **IMPORT_COMPLETE** as shown below.

![](https://dev-to-uploads.s3.amazonaws.com/i/ji4cx554bdu23rl2oglm.png)

---

## Yay!

All of the existing manually created resources has been imported into CloudFormation. Clicking on the “Resources” tab will list all of the resources currently managed by this CloudFormation stack.

![Fig 1: List of Resources managed by CloudFormation](https://dev-to-uploads.s3.amazonaws.com/i/9aqj3ek4s58zczyo3epl.png)

## Summary

In this post, we used AWS Global Accelerator as an example. And, there are many other resources that supports Resource Imports. [Click here to see the full list](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/resource-import-supported-resources.html).

However, not all resources are supported by CloudFormation Resource Import. If you still have manually created resources that aren’t yet supported, then there’s no way to manage it via CloudFormation other than to re-create it from scratch or wait for AWS to announce it’s support.

#### Resources:

- https://docs.aws.amazon.com/cloudformation/index.html
- https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/resource-import.html