Skip to content

Commit

Permalink
feat: more more
Browse files Browse the repository at this point in the history
  • Loading branch information
acrois committed Jan 26, 2024
1 parent 051fa9e commit 2e24562
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 7 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Consolidated IaC with LocalStack Demo

This repository demonstrates how to use Pulumi, Terraform, and AWS CloudFormation with LocalStack for local AWS infrastructure testing.
[![Dynamic Test Execution](https://github.com/KinetechSolutions/iac-patterns/actions/workflows/test.yaml/badge.svg)](https://github.com/KinetechSolutions/iac-patterns/actions/workflows/test.yaml)

This repository demonstrates how to use Pulumi, Terraform, and AWS CloudFormation with LocalStack for testing patterns for AWS infrastructure.

## Prerequisites

Expand Down
14 changes: 13 additions & 1 deletion cloudformation/template.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,20 @@
AWSTemplateFormatVersion: '2010-09-09'
Description: CloudFormation LocalStack Demo

Parameters:
BucketName:
Type: String
Description: Name of the S3 bucket to create

Resources:
MyBucket:
Type: AWS::S3::Bucket
Properties:
BucketName: my-cloudformation-bucket
BucketName: !Ref BucketName

Outputs:
S3BucketName:
Description: "Name of the S3 bucket"
Value: !Ref MyBucket
Export:
Name: !Sub "${AWS::StackName}-S3BucketName"
8 changes: 8 additions & 0 deletions pulumi/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Pulumi

## Setup

```sh
pip install -r requirements.txt
pulumi up
```
19 changes: 19 additions & 0 deletions tests/cloudformation_bucket.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/env bun

import { $ } from "bun"
console.log('Running CloudFormation resource check...')

const awsCliVersion = (await $`aws --version`.text()).trim()
console.log(`AWS CLI: ${awsCliVersion}`)

if (!awsCliVersion) throw 'Invalid AWS CLI version.';

await $`pwd`.cwd("/cloudformation")

const bucketName = 'my-cloudformation-bucket'
await $`aws cloudformation create-stack --stack-name my-stack --template-body file://template.yaml --parameters ParameterKey=BucketName,ParameterValue=${bucketName}`
await $`aws cloudformation describe-stacks --stack-name my-stack`

console.log(`Checking if S3 bucket ${bucketName} exists...`)

await $`aws s3 ls s3://${bucketName}`
4 changes: 4 additions & 0 deletions tests/pulumi_bucket.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ console.log(`AWS CLI: ${awsCliVersion}`)

if (!awsCliVersion) throw 'Invalid AWS CLI version.';

await $`pwd`.cwd("/pulumi")
const installRequirements = (await $`pip install -r requirements.txt`.text()).trim()


const bucketName = (await $`pulumi stack output bucket_name`.text()).trim()
console.log(`Checking if S3 bucket ${bucketName} exists...`)

Expand Down
12 changes: 7 additions & 5 deletions tests/terraform_bucket.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
#!/usr/bin/env bun

import { $ } from "bun"
console.log('Running Pulumi resource check...')
console.log('Running Terraform resource check...')

const pulumiVersion = (await $`pulumi version`.text()).trim()
console.log(`Pulumi: ${pulumiVersion}`)
const terraformVersion = (await $`terraform version`.text()).trim()
console.log(`Terraform: ${terraformVersion}`)

if (!pulumiVersion) throw 'Invalid Pulumi version.';
if (!terraformVersion) throw 'Invalid Terraform version.';

const awsCliVersion = (await $`aws --version`.text()).trim()
console.log(`AWS CLI: ${awsCliVersion}`)

if (!awsCliVersion) throw 'Invalid AWS CLI version.';

const bucketName = (await $`pulumi stack output bucket_name`.text()).trim()
await $`pwd`.cwd("/terraform")

const bucketName = (await $`terraform output bucket_name`.text()).trim()
console.log(`Checking if S3 bucket ${bucketName} exists...`)

await $`aws s3 ls s3://${bucketName}`

0 comments on commit 2e24562

Please sign in to comment.