Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions .github/workflows/test_aws.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,37 @@ jobs:
tag-actor: never
tool: tofu

- name: Troubleshoot TF
if: ${{ failure() && github.event_name == 'merge_group' }}
uses: op5dev/prompt-ai@4cacb93e4a1e101f3a89650b31a3582321f2461d # v2.0.0
with:
model: openai/gpt-4.1-mini
system-prompt: You are a helpful DevOps assistant and expert at troubleshooting Terraform errors.
user-prompt: Troubleshoot the following Terraform output; ${{ steps.tf.outputs.result }}

- name: Clear directory
if: ${{ failure() && github.event_name == 'merge_group' }}
run: find ${{ github.workspace }} -mindepth 1 -delete

- name: Checkout main
if: ${{ failure() && github.event_name == 'merge_group' }}
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
ref: main
persist-credentials: false

- name: Rollback TF
if: ${{ failure() && github.event_name == 'merge_group' }}
uses: ./
with:
working-directory: tests/aws/targets/${{ matrix.target }}
command: apply
arg-auto-approve: true
arg-lock-timeout: 3m

comment-pr: false
tool: tofu

Notify:
runs-on: [ubuntu-24.04]
needs: [Target, TF]
Expand Down
8 changes: 4 additions & 4 deletions tests/aws/targets/dev/outputs.tf
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
output "s3" {
value = module.s3_bucket
}

output "ec2" {
value = module.ec2_instance
}

output "s3" {
value = module.s3_bucket
}
22 changes: 22 additions & 0 deletions tests/aws/targets/stg/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
module "vpc" {
source = "../../modules/vpc_default" # github.com/op5dev/tf-via-pr//tests/aws/modules/vpc_default?depth=1&ref=v13.5.0

context = var.context
}

module "ec2_instance" {
source = "../../modules/ec2_instance" # github.com/op5dev/tf-via-pr//tests/aws/modules/ec2_instance?depth=1&ref=v13.5.0
for_each = var.ec2_instance

context = var.context
instance = var.ec2_instance[each.key]
network = module.vpc
}

module "s3_bucket" {
source = "../../modules/s3_bucket" # github.com/op5dev/tf-via-pr//tests/aws/modules/s3_bucket?depth=1&ref=v13.5.0
for_each = var.s3_bucket

context = var.context
bucket = var.s3_bucket[each.key]
}
7 changes: 7 additions & 0 deletions tests/aws/targets/stg/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
output "ec2" {
value = module.ec2_instance
}

output "s3" {
value = module.s3_bucket
}
24 changes: 24 additions & 0 deletions tests/aws/targets/stg/providers.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
terraform {
required_version = ">= 1.5, < 2.0"

backend "s3" {
bucket = "tf-via-pr-813676077823"
key = "stg-tfstate.json"
region = "us-west-1"
use_lockfile = "true"
}

required_providers {
aws = {
source = "hashicorp/aws"
}
}
}

provider "aws" {
region = var.context.aws_region

default_tags {
tags = var.context
}
}
23 changes: 23 additions & 0 deletions tests/aws/targets/stg/terraform.tfvars
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
context = {
env_name = "platforms"
env_type = "stg"

aws_account_id = "813676077823"
aws_region = "us-west-2"
}

ec2_instance = {
rectangle = {
name_suffix = "reggie"
instance_type = "t2.micro"
ubuntu_type = "server"
ubuntu_version = "24.04"
}
}

s3_bucket = {
teal = {
name_suffix = "tyler"
retention_days = 5
}
}
14 changes: 14 additions & 0 deletions tests/aws/targets/stg/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
variable "context" {
type = any
default = {}
}

variable "ec2_instance" {
type = any
default = {}
}

variable "s3_bucket" {
type = any
default = {}
}