Skip to content

Commit

Permalink
Update EC2 pipelines and var names (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
cbruno10 authored Oct 16, 2023
1 parent cdbbb5c commit bd41aea
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 49 deletions.
69 changes: 40 additions & 29 deletions pipelines/ec2/describe_ec2_instances.hcl
Original file line number Diff line number Diff line change
@@ -1,52 +1,63 @@
pipeline "describe_ec2_instances" {
# Credentials
param "aws_region" {

param "region" {
type = string
description = "AWS Region"
default = var.aws_region
description = "The name of the Region."
default = var.region
}

param "aws_access_key_id" {
param "access_key_id" {
type = string
description = "AWS Access Key ID"
default = var.aws_access_key_id
description = "The ID for this access key."
default = var.access_key_id
}

param "aws_secret_access_key" {
param "secret_access_key" {
type = string
description = "AWS Secret Access Key"
default = var.aws_secret_access_key
description = "The secret key used to sign requests."
default = var.secret_access_key
}

param "instance_ids" {
type = list(string)
type = list(string)
description = "The instance IDs."
optional = true
}

param "instance_type" {
type = string
description = "The type of instance (for example, t2.micro)."
optional = true
}

param "filter" {
type = string
optional = true
param "ebs_optimized" {
type = bool
description = "A Boolean that indicates whether the instance is optimized for Amazon EBS I/O."
optional = true
}

step "container" "container_run_aws" {
image = "amazon/aws-cli"
step "container" "describe_ec2_instances" {
image = "amazon/aws-cli"

cmd = concat([
"ec2",
"describe-instances",
## TODO next step is to only include instance-ids if any are provided
"--instance-ids",
], param.instance_ids)
cmd = concat(
["ec2", "describe-instances"],
param.instance_ids != null && length(param.instance_ids) > 0 ? concat(["--instance-ids"], param.instance_ids) : [],
param.instance_type != null ? ["--filters", "Name=instance-type,Values=${param.instance_type}"] : [],
param.ebs_optimized != null ? ["--filters", "Name=ebs-optimized,Values=${param.ebs_optimized}"] : []
)

env = {
AWS_REGION = param.aws_region
AWS_ACCESS_KEY_ID = param.aws_access_key_id
AWS_SECRET_ACCESS_KEY = param.aws_secret_access_key
}
env = {
AWS_REGION = param.region
AWS_ACCESS_KEY_ID = param.access_key_id
AWS_SECRET_ACCESS_KEY = param.secret_access_key
}
}

output "stdout" {
value = jsondecode(step.container.container_run_aws.stdout)
value = jsondecode(step.container.container_run_aws.stdout)
}

output "stderr" {
value = jsondecode(step.container.container_run_aws.stderr)
value = jsondecode(step.container.container_run_aws.stderr)
}
}
31 changes: 17 additions & 14 deletions pipelines/ec2/start_ec2_instance.hcl
Original file line number Diff line number Diff line change
@@ -1,28 +1,29 @@
pipeline "start_ec2_instance" {
# Credentials
param "aws_region" {

param "region" {
type = string
description = "AWS Region"
default = var.aws_region
description = "The name of the Region."
default = var.region
}

param "aws_access_key_id" {
param "access_key_id" {
type = string
description = "AWS Access Key ID"
default = var.aws_access_key_id
description = "The ID for this access key."
default = var.access_key_id
}

param "aws_secret_access_key" {
param "secret_access_key" {
type = string
description = "AWS Secret Access Key"
default = var.aws_secret_access_key
description = "The secret key used to sign requests."
default = var.secret_access_key
}

param "instance_id" {
type = string
type = string
description = "The IDs of the instances."
}

step "container" "container_run_aws" {
step "container" "start_ec2_instance" {
image = "amazon/aws-cli"
cmd = ["ec2", "start-instances", "--instance-ids", param.instance_id]
env = {
Expand All @@ -31,10 +32,12 @@ pipeline "start_ec2_instance" {
AWS_SECRET_ACCESS_KEY = param.aws_secret_access_key
}
}
output "stdout_aws" {

output "stdout" {
value = step.container.container_run_aws.stdout
}
output "stderr_aws" {

output "stderr" {
value = step.container.container_run_aws.stderr
}
}
12 changes: 6 additions & 6 deletions variables.hcl
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
variable "aws_region" {
variable "region" {
type = string
description = "AWS Region"
description = "The name of the Region."
}

variable "aws_access_key_id" {
variable "access_key_id" {
type = string
description = "AWS Access Key ID"
description = "The ID for this access key."
}

variable "aws_secret_access_key" {
variable "secret_access_key" {
type = string
description = "AWS Secret Access Key"
description = "The secret key used to sign requests."
}

0 comments on commit bd41aea

Please sign in to comment.