From bd41aeadc26c58431dd20da98dfc8eb797f47c5f Mon Sep 17 00:00:00 2001 From: cbruno10 Date: Mon, 16 Oct 2023 07:15:05 -0400 Subject: [PATCH] Update EC2 pipelines and var names (#1) --- pipelines/ec2/describe_ec2_instances.hcl | 69 ++++++++++++++---------- pipelines/ec2/start_ec2_instance.hcl | 31 ++++++----- variables.hcl | 12 ++--- 3 files changed, 63 insertions(+), 49 deletions(-) diff --git a/pipelines/ec2/describe_ec2_instances.hcl b/pipelines/ec2/describe_ec2_instances.hcl index c143bb4..e67e4de 100644 --- a/pipelines/ec2/describe_ec2_instances.hcl +++ b/pipelines/ec2/describe_ec2_instances.hcl @@ -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) } } diff --git a/pipelines/ec2/start_ec2_instance.hcl b/pipelines/ec2/start_ec2_instance.hcl index bc8ef33..586dca2 100644 --- a/pipelines/ec2/start_ec2_instance.hcl +++ b/pipelines/ec2/start_ec2_instance.hcl @@ -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 = { @@ -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 } } diff --git a/variables.hcl b/variables.hcl index 966cf0c..17ed0c4 100644 --- a/variables.hcl +++ b/variables.hcl @@ -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." }