Skip to main content

Create and deploy an Infrastructure

In this section, you will find an example of how to use Infrastructure Plugins to create an Infrastructure and deploy it.

Introduction

  • Beginner level

This is an example of how to create an Infrastructure. For more details to create your Infra, see the Infrastructure page.

This example assists you in creating and deploying an Infrastructure with StackSpot STK CLI. You will use:

  • The S3 CloudFront Stack you created in the Create Infra Plugins example to create an Infrastructure that can be used by an Application to be deployed.
  • The S3 CloudFront Stack includes Infra Plugins designed to construct the infrastructure required for deployment and accessibility of HTML content.

Now, follow the instructions below to accomplish this.

Before you begin

To use this example, first you need to:

  1. Develop two Infra Plugins to generate the infrastructure to deploy the HTML page. Use the Create Infra Plugins Guide.
  2. Create a Stack incorporating the Infra Plugins from the Infra Plugin example.
  3. You must add the Stack to a Workspace to create, register, and deploy the Infrastructure with StackSpot.

Prerequisites

stk login

Step 1. Create an empty directory

Generate a project directory by executing the following command in your terminal:

mkdir demo-infra

Access this directory in your preferred IDE, such as Visual Studio Code.

Step 2. Create the Infrastructure

  1. Access the Workspace where you performed the previous steps and added the S3 CloudFront Stack from the Create Infra Plugins example mentioned at the beginning.

You will use this Workspace to create and register the Infrastructure. In your IDE terminal, execute the command:

stk use workspace

Then, select the appropriate Workspace.

warning

You can only register and deploy an Infrastructure using Plugins inside a Workspace.

  1. To create the Infrastructure, execute the command:
stk create infra demo-infra
tip

What is the difference between creating an Application and an Infrastructure?

  • When you create an Application, you need a Starter within the Stack.
  • When you create an Infrastructure, there is no need for a Starter, only a Stack.

Then answer the questions on your terminal as follows:

? Name your Infrastructure demo-infra
? Do you want to init a git repository? No
? Infrastructure description: (Describe your Infrastructure explaining its purpose) Create bucket s3 with CloudFront distribution
? Select the studio: select the studio where you created the Stack
? Select the stack: s3-cloudfront-stack
? Select the stack version: 1.0.0
? Select the desired infra plugins: done (2 selections)
> Selected infra plugins to be applied:
- bucket-s3-plugin@0.0.1
- cloudfront-plugin@0.0.1

In the last question ? Select the desired infra plugins: both plugins will already be selected to be applied. Just press enter.
In other cases, you can select one Plugin at a time to apply.

  • Now, apply the Bucket S3 Plugin:

When the question ? Name the usage of the plugin appears, press enter.

  • Then, answer the questions on your terminal:
? Name the connector for 'bucket-s3-plugin-conn (aws-s3-conn)': demo-infra-tw-01-conn
? Type name of your bucket demo-infra-tw-01

When you name the connector, you are naming the Connection Interface.
When you name the Bucket S3, you are giving the Plugin an alias.

  • Now, apply the CloudFront Plugin and answer the questions on your terminal:

When the question ? Name the usage of the plugin appears, just press enter.

In this scenario, the CloudFront Plugin recognizes that a preceding Plugin generated a required Connection Interface. Select:

? Choose a connector for 'aws-s3-conn (bucket-s3-cloudfront-conn)': demo-infra-tw-01-conn (local)
? Type name of your resource (Client) > Press enter to keep the default
? Choose http method of new endpoint GET > Press enter to keep the default

You successfully created the demo-infra Infrastructure!

Within your project's folder, only the stk.yaml file will exist.

Step 3. Access your project’s directory and register your Infrastructure

Register your Infrastructure in a Workspace to make it available on StackSpot. Follow the instructions:

  1. Enter your project’s directory by running the command:
cd demo-infra
  1. Register your Infrastructure:
stk register infra

Answer the following questions:

? Repository URL: add your repository 
? Base branch: main

Infrastructure registered successfully.

info

Check if your Infrastructure was added to the Workspace:

  1. Access the StackSpot EDP Portal.
  2. Go to your Workspace.
  3. Click Infrastructure.
  4. Confirm that your Infrastructure is there.

Step 4. Deploy your Infrastructure

To deploy your Infrastructure, run the following command:

stk deploy infra -v <infra-version> -e <environment-name> -w

-v indicates the Infrastructure version.
-e indicates the environment you want to deploy to.
-w indicates that you want to watch the deployment.

Done! You started your Infrastructure deployment.

  • The deployment starts with the Bucket S3 Plugin because it generates a Connection Interface that the CloudFront Plugin will use.
  • StackSpot registers the deployment on the Infrastructure page in the Portal.
  • After the deployment, you will see the Connection Interfaces generated by your Infrastructure on the StackSpot EDP Portal.

What can you do next?