Create Infrastructure and deploy via Plugins in STK CLI
In this section, you will find an example of creating an Infrastructure in the STK CLI by applying one Plugin at a time.
Introduction
- Intermediate level.
This example shows:
- How to create an Infrastructure by applying one Plugin at a time;
- How to register an Infrastructure;
- How to deploy an Infrastructure.
Requirements
-
STK CLI installed;
-
Logged in your StackSpot account. To do this, execute the command below your terminal:
stk login
-
You need to be in a Workspace. In this example, the Workspace name is Runtimes.
-
You need an infrastructure Stack added to the Workspace. This example will use a Stack with the following Infrastructure Plugins:
- s3-bucket: this plugin generates a s3 bucket.
Click here to check the Plugin and Terraform files
- plugin.yaml
- .tf
schema-version: v2
kind: plugin
metadata:
name: s3-bucket
display-name: s3-bucket
description: aws s3 bucket
version: 0.0.1
spec:
type: infra
runtime:
environment:
- terraform-1-3
about: docs/about.md
implementation: docs/implementation.md
release-notes: docs/release-notes-0.0.1.md
requirements: docs/requirements.md
technologies: # Ref: https://docs.stackspot.com/content-creator/studio/yaml-files/plugin-yaml/#technologies
- AWS S3
generates:
connections:
- type: aws-s3-conn
alias: created-s3-bucket
outputs:
- from: aws-s3-arn
to: arn
- from: aws-s3-bucket-name
to: bucket_name
inputs:
- label: Name
name: name
type: text
required: true
help: 'Inform your resource name'
resource "aws_s3_bucket" "{{ name }}" {
bucket = "{{ name }}-bucket"
acl = "private"
}
output "aws-s3-bucket-name" {
value = aws_s3_bucket.{{ name }}.id
}
output "aws-s3-arn" {
value = aws_s3_bucket.{{ name }}.arn
}
- s3-create-and-publish: This Plugin requires the following Connection Interfaces types:
SQS
andS3
The Plugin uses thearn
ofsqs
to create a file with the content of thearn
ofsqs
. It also uploads this file to the S3 used.
Click here to check the Plugin and Terraform files
- plugin.yaml
- .tf
schema-version: v2
kind: plugin
metadata:
name: s3-create-and-publish
display-name: s3-create-and-publish
description: create a file and publish file on s3
version: 0.0.1
spec:
type: infra
runtime:
environment:
- terraform-1-3
about: docs/about.md
implementation: docs/implementation.md
release-notes: docs/release-notes-0.0.1.md
requirements: docs/requirements.md
technologies: # Ref: https://docs.stackspot.com/content-creator/studio/yaml-files/plugin-yaml/#technologies
- AWS S3
requires:
connections:
- type: aws-s3-conn
alias: my-s3
- type: aws-sqs-conn
alias: my-sqs
generates:
connections: []
inputs:
- label: Name
name: name
type: text
required: true
help: 'Inform your resource name'
- label: File Path
name: path
type: text
required: true
help: 'Inform file path'
resource "local_file" "{{ name }}" {
content = "{{ connections['my-sqs'].arn }}"
filename = "{{ path }}"
}
resource "aws_s3_bucket_object" "{{ name }}_create_and_publish" {
bucket = "{{ connections['my-s3'].bucket_name }}"
key = "{{ path }}"
source = "{{ path }}"
depends_on = [ local_file.{{ name }} ]
}
- **sqs-queues:**It's a simple
sqs
. This plugin generates twosqs
Connection Interfaces types, simulating the creation of a queue and the DLQ Undelivered Message Queue associated with it.
Click here to check the Plugin and Terraform files
- plugin.yaml
- .tf
schema-version: v2
kind: plugin
metadata:
name: sqs-queues
display-name: sqs-queues
description: aws sqs queue and dlq
version: 0.0.2
spec:
type: infra
runtime:
environment:
- terraform-1-3
about: docs/about.md
implementation: docs/implementation.md
release-notes: docs/release-notes-0.0.1.md
requirements: docs/requirements.md
technologies: # Ref: https://docs.stackspot.com/content-creator/studio/yaml-files/plugin-yaml/#technologies
- AWS SNS
generates:
connections:
- type: aws-sqs-conn
alias: created-queue
outputs:
- from: sqs-arn
to: arn
- from: sqs-url
to: url
- from: sqs-queue-name
to: queue_name
- type: aws-sqs-conn
alias: created-queue-dlq
outputs:
- from: sqs-dlq-arn
to: arn
- from: sqs-dlq-url
to: url
- from: sqs-dlq-queue-name
to: queue_name
inputs:
- label: Name
name: name
type: text
required: true
help: 'Inform your resource name'
resource "aws_sqs_queue" "{{ name }}" {
name = "{{ name }}_queue"
receive_wait_time_seconds = 20
message_retention_seconds = 43200
visibility_timeout_seconds = 900
}
resource "aws_sqs_queue" "{{ name }}_dlq" {
name = "{{ name }}_queue_dlq"
receive_wait_time_seconds = 20
message_retention_seconds = 43200
visibility_timeout_seconds = 900
}
output "sqs-queue-name" {
value = "{{ name }}_queue"
}
output "sqs-arn" {
value = aws_sqs_queue.{{ name }}.arn
}
output "sqs-url" {
value = aws_sqs_queue.{{ name }}.id
}
output "sqs-dlq-queue-name" {
value = "{{ name }}_queue_dlq"
}
output "sqs-dlq-arn" {
value = aws_sqs_queue.{{ name }}_dlq.arn
}
output "sqs-dlq-url" {
value = aws_sqs_queue.{{ name }}_dlq.id
}
Steps to create, register, and deploy the Infrastructure
Create Shared Infra and deploy Plugins
Step 1. In the terminal, access the Workspace to create the Infrastructure. Execute the command below:
stk use workspace runtimes
Step 2. Now, create the Infrastructure. To do this, execute the command below in the terminal:
stk create infra
After that, answer the STK CLI questions with the following data:
-
? Name your Infrastructure: example-infra-1
-
? Do you want to init a git repository? No
-
? Infrastructure description: Example of deployment with Plugins
-
? Select the studio: studio-name
Select the studio where your Stack is.
- ? Select the Stack: example-stack
Select the Stack described in the requirements above.
- ? Select the desired infra plugins: [s3-bucket@0.0.1]
Select only
bucket-s3
. It is to apply one Plugin at a time.
- ? Name de usage of the plugin (runtime-demo-dbp/deploy-by-plugin/s3-bucket): bucket-1
This is the Plugin's application
alias
. It is the name you give to the Plugin usage in your Infrastructure, you can apply more than once.
- ? Name the connector for 'created-s3-bucket (aws-s3-conn)': deploy-by-plugin-s3-example
Connection Interface name. It will be created in the StackSpot Platform.
- ? Name: deploy-by-plugin-s3-example
Name of the resource; it is created in AWS.
After answering all the questions, press enter. The first Plugin was applied and the Infrastructure created.
Now, apply the second Plugin in this example. It is the sqs
Plugin.
Step 3. Access the Infrastructure project folder again. Execute the command:
cd example-infra-1
Step 4. Execute the command below to apply the sqs-queues
Plugin:
stk apply plugin studio-name/example-stack/sqs-queues
After that, answer the STK CLI questions with the following data:
- ? Name de usage of the plugin (studio-name/example-stack/sqs-queues): sqs-1
This is the Plugin's application
alias
. It is the name you give to the Plugin usage in your Infrastructure, as it can be applied more than once.
? Name de connector for 'created-queue (aws-sqs-conn)': sqs-example
Connection Interface name. It will be created in the StackSpot Platform.
? Name de connector for 'created-queue-dlq (aws-sqs-conn)': sqs-dlq-example
Connection Interface name. It will be created in the StackSpot Platform.
? Name sqs-example: sqs-example
Name of the resource. It will be created in AWS.
The second Plugin was applied.
Step 5. Now, apply the s3-create-and-publish
Plugin.
Execute the command:
stk apply plugin studio-name/example-stack/s3-create-and-publish
Then answer the questions:
- ? Name the usage of the plugin (studio-name/example-stack/s3-create-and-publish): s3-publish
This is the Plugin's application
alias
. It is the name you give to the Plugin usage in your Infrastructure, as it can be applied more than once.
- ? Choose a connector for 'aws-s3-conn (my-s3)': deploy-by-plugin-s3-example
select: s3-example
- ? Choose a connector for 'aws-sqs-conn (my-sqs)': sqs-example
In this example, only one sns Connection Interface is available. STK CLI has automatically chosen this option.
-
? Name: s3-publish
-
? File Path: create_files/deploy_by_plugin_file.txt
This is a Plugin parameter that indicates where you want to place the file that will be created.
The last plugin was applied. And the Infrastructure was created.
The stk.yaml file generated by the Infrastructure must be the same as this one:
Click here to view the Shared Infra stk.yaml file
schema-version: v2
kind: manifest
metadata:
name: example-infra-1
description: example of deployment by plugin
stack-version-id: 01H96ESKYYGVW18V90CNM196MC
stack: example-stack
spec:
type: infra
infra-id: 01H96FE739PKBVJFZ9TA2P6JDD
plugins:
- name: studio-name/example-stack@0.1.0/s3-bucket@0.0.1
alias: bucket-1
plugin-version-id: 01H96ENMCGRSTTZ9F70Q7R3GKZ
stack-version-id: 01H96ESKYYGVW18V90CNM196MC
type: infra
inputs:
name: deploy-by-plugin-s3-exempl
inputs-envs: {}
connections:
generates:
- type: aws-s3-conn
selected: deploy-by-plugin-s3-example
alias: created-s3-bucket
requires: []
links:
generates: []
- name: studio-name/example-stack@0.2.0/sqs-queues@0.0.2
alias: sqs-1
plugin-version-id: 01H96FQ6HS3HRAMXPNF3JFKWVC
stack-version-id: 01H96FR353X94TJTFTCYHHJ6NB
type: infra
inputs:
name: sqs-example
inputs-envs: {}
connections:
generates:
- type: aws-sqs-conn
selected: sqs-example
alias: created-queue
- type: aws-sqs-conn
selected: sqs-dlq-example
alias: created-queue-dlq
requires: []
links:
generates: []
- name: studio-name/example-stack@0.1.0/s3-create-and-publish@0.0.1
alias: s3-publish
plugin-version-id: 01H96EPFS2N0176PHG1SB0SQY9
stack-version-id: 01H96ESKYYGVW18V90CNM196MC
type: infra
inputs:
name: s3-publish
path: create_files/deploy_by_plugin_file.txt
inputs-envs: {}
connections:
generates: []
requires:
- type: aws-s3-conn
selected: deploy-by-plugin-s3-example
alias: my-s3
- type: aws-sqs-conn
selected: sqs-example
alias: my-sqs
links:
generates: []
global-inputs: {}
global-computed-inputs: {}
repository: https://github.com/repository
With the alias
spec, it is possible to make a connection between the name that the creator of the Plugin (or Plugins) put on the Connection Interface when creating it. And the type of Connection Interface that exists within the Workspace that the developer will use to create the Infrastructure.
Register an Infrastructure
After creating your Infrastructure, you need to register. Execute the command below:
stk register infra
After that, answer two questions in the terminal:
? Repository URL: Link to the repository where the Infrastructure should be. ? Base branch: main
The Infrastructure was registered.
You can check the Infrastructure in the Workspace within the StackSpot Platform. Go where the Infrastructure was created. Then, access the ' Infrastructure' section in the left side menu.
Deploy Infrastructure
After registering, it's time to deploy the Infrastructure.
Execute the command:
stk deploy infra –version v1 –env qastaging
-
The
-version
flag indicates the version of the Infrastructure. -
The
-env
flag indicates the environment the deployment will take place.
Deployment tracking now shows the individual status per Plugin. To track, execute the command:
stk deploy status <Shared Infra's Id> --watch
See below:

