1008 test implementation

Signed-off-by: Guillaume de Rouville <guillaume.derouville@gmail.com>
This commit is contained in:
Guillaume de Rouville
2021-08-13 04:18:56 +02:00
parent 6744045ce7
commit dc865bf2be
12 changed files with 379 additions and 290 deletions

View File

@@ -0,0 +1,24 @@
package main
import (
"alpha.dagger.io/os"
"alpha.dagger.io/aws"
"alpha.dagger.io/dagger"
)
// Remove Cloudformation Stack
stackRemoval: {
// Cloudformation Stackname
stackName: string & dagger.#Input
ctr: os.#Container & {
image: aws.#CLI & {
config: awsConfig
}
always: true
env: STACK_NAME: stackName
command: """
aws cloudformation delete-stack --stack-name $STACK_NAME
"""
}
}

View File

@@ -0,0 +1,8 @@
package main
import (
"alpha.dagger.io/aws"
)
// AWS account: credentials and region
awsConfig: aws.#Config

View File

@@ -0,0 +1,26 @@
package main
import (
"alpha.dagger.io/aws"
"alpha.dagger.io/dagger"
"alpha.dagger.io/random"
"alpha.dagger.io/aws/cloudformation"
)
// AWS account: credentials and region
awsConfig: aws.#Config
// Create a random suffix
suffix: random.#String & {
seed: ""
}
// Query the Cloudformation stackname, or create one with a random suffix to keep unicity
cfnStackName: *"stack-\(suffix.out)" | string & dagger.#Input
// AWS Cloudformation stdlib
cfnStack: cloudformation.#Stack & {
config: awsConfig
stackName: cfnStackName
source: template
}

View File

@@ -0,0 +1,61 @@
package main
// inlined s3 cloudformation template as a string
template: """
{
"AWSTemplateFormatVersion": "2010-09-09",
"Resources": {
"S3Bucket": {
"Type": "AWS::S3::Bucket",
"Properties": {
"AccessControl": "PublicRead",
"WebsiteConfiguration": {
"IndexDocument": "index.html",
"ErrorDocument": "error.html"
}
},
"DeletionPolicy": "Retain"
},
"BucketPolicy": {
"Type": "AWS::S3::BucketPolicy",
"Properties": {
"PolicyDocument": {
"Id": "MyPolicy",
"Version": "2012-10-17",
"Statement": [
{
"Sid": "PublicReadForGetBucketObjects",
"Effect": "Allow",
"Principal": "*",
"Action": "s3:GetObject",
"Resource": {
"Fn::Join": [
"",
[
"arn:aws:s3:::",
{
"Ref": "S3Bucket"
},
"/*"
]
]
}
}
]
},
"Bucket": {
"Ref": "S3Bucket"
}
}
}
},
"Outputs": {
"Name": {
"Value": {
"Fn::GetAtt": ["S3Bucket", "Arn"]
},
"Description": "Name S3 Bucket"
}
}
}
"""

View File

@@ -0,0 +1,5 @@
package main
import "encoding/json"
s3Template: json.Unmarshal(template)

View File

@@ -0,0 +1,75 @@
package main
#Deployment: {
// Bucket's output description
description: string
// index file
indexDocument: *"index.html" | string
// error file
errorDocument: *"error.html" | string
// Bucket policy version
version: *"2012-10-17" | string
// Retain as default deletion policy. Delete is also accepted but requires the s3 bucket to be empty
deletionPolicy: *"Retain" | "Delete"
// Canned access control list (ACL) that grants predefined permissions to the bucket
accessControl: *"PublicRead" | "Private" | "PublicReadWrite" | "AuthenticatedRead" | "LogDeliveryWrite" | "BucketOwnerRead" | "BucketOwnerFullControl" | "AwsExecRead"
// Modified copy of s3 value in `todoapp/cloudformation/template.cue`
template: {
AWSTemplateFormatVersion: "2010-09-09"
Outputs: Name: {
Description: description
Value: "Fn::GetAtt": [
"S3Bucket",
"Arn",
]
}
Resources: {
BucketPolicy: {
Properties: {
Bucket: Ref: "S3Bucket"
PolicyDocument: {
Id: "MyPolicy"
Statement: [
{
Action: "s3:GetObject"
Effect: "Allow"
Principal: "*"
Resource: "Fn::Join": [
"",
[
"arn:aws:s3:::",
{
Ref: "S3Bucket"
},
"/*",
],
]
Sid: "PublicReadForGetBucketObjects"
},
]
Version: version
}
}
Type: "AWS::S3::BucketPolicy"
}
S3Bucket: {
DeletionPolicy: deletionPolicy
Properties: {
AccessControl: "PublicRead"
WebsiteConfiguration: {
ErrorDocument: errorDocument
IndexDocument: indexDocument
}
}
Type: "AWS::S3::Bucket"
}
}
}
}

View File

@@ -0,0 +1,60 @@
// Add this line, to make it part to the cloudformation template
package main
import "encoding/json"
// Wrap exported Cue in previous point inside the `s3` value
s3: {
AWSTemplateFormatVersion: "2010-09-09"
Outputs: Name: {
Description: "Name S3 Bucket"
Value: "Fn::GetAtt": [
"S3Bucket",
"Arn",
]
}
Resources: {
BucketPolicy: {
Properties: {
Bucket: Ref: "S3Bucket"
PolicyDocument: {
Id: "MyPolicy"
Statement: [
{
Action: "s3:GetObject"
Effect: "Allow"
Principal: "*"
Resource: "Fn::Join": [
"",
[
"arn:aws:s3:::",
{
Ref: "S3Bucket"
},
"/*",
],
]
Sid: "PublicReadForGetBucketObjects"
},
]
Version: "2012-10-17"
}
}
Type: "AWS::S3::BucketPolicy"
}
S3Bucket: {
DeletionPolicy: "Retain"
Properties: {
AccessControl: "PublicRead"
WebsiteConfiguration: {
ErrorDocument: "error.html"
IndexDocument: "index.html"
}
}
Type: "AWS::S3::Bucket"
}
}
}
// Template contains the marshalled value of the s3 template
template: json.Marshal(s3)

View File

@@ -0,0 +1,10 @@
package main
import "encoding/json"
s3: #Deployment & {
description: "Name S3 Bucket"
}
// Template contains the marshalled value of the s3 template
template: json.Marshal(s3.template)