Skip to content

Commit 81fd39f

Browse files
committed
end2end: include cloudformation example
1 parent 050af97 commit 81fd39f

File tree

2 files changed

+150
-0
lines changed

2 files changed

+150
-0
lines changed

tests/cloudformation/table.yml

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
AWSTemplateFormatVersion: "2010-09-09"
2+
3+
Description: 'AWS CloudFormation Sample Template DynamoDB_Table: This template demonstrates the creation of a DynamoDB table. **WARNING** This template creates an Amazon DynamoDB table. You will be billed for the AWS resources used if you create a stack from this template.'
4+
5+
Metadata:
6+
License: Apache-2.0
7+
8+
Parameters:
9+
HashKeyElementName:
10+
Description: HashType PrimaryKey Name
11+
Type: String
12+
AllowedPattern: '[a-zA-Z0-9]*'
13+
MinLength: "1"
14+
MaxLength: "2048"
15+
ConstraintDescription: must contain only alphanumberic characters
16+
17+
TableName:
18+
Description: TableName
19+
Type: String
20+
AllowedPattern: '[a-zA-Z0-9]*'
21+
MinLength: "1"
22+
MaxLength: "2048"
23+
ConstraintDescription: must contain only alphanumberic characters
24+
25+
HashKeyElementType:
26+
Description: HashType PrimaryKey Type
27+
Type: String
28+
Default: S
29+
AllowedPattern: '[S|N]'
30+
MinLength: "1"
31+
MaxLength: "1"
32+
ConstraintDescription: must be either S or N
33+
34+
ReadCapacityUnits:
35+
Description: Provisioned read throughput
36+
Type: Number
37+
Default: "5"
38+
MinValue: "5"
39+
MaxValue: "10000"
40+
ConstraintDescription: must be between 5 and 10000
41+
42+
WriteCapacityUnits:
43+
Description: Provisioned write throughput
44+
Type: Number
45+
Default: "10"
46+
MinValue: "5"
47+
MaxValue: "10000"
48+
ConstraintDescription: must be between 5 and 10000
49+
50+
Resources:
51+
myDynamoDBTable:
52+
Type: AWS::DynamoDB::Table
53+
Properties:
54+
AttributeDefinitions:
55+
- AttributeName: !Ref HashKeyElementName
56+
AttributeType: !Ref HashKeyElementType
57+
KeySchema:
58+
- AttributeName: !Ref HashKeyElementName
59+
KeyType: HASH
60+
ProvisionedThroughput:
61+
ReadCapacityUnits: !Ref ReadCapacityUnits
62+
WriteCapacityUnits: !Ref WriteCapacityUnits
63+
TableName: !Ref TableName
64+
65+
Outputs:
66+
TableName:
67+
Description: Table name of the newly created DynamoDB table
68+
Value: !Ref myDynamoDBTable
69+

tests/end2end_test.go

+81
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99

1010
"github.com/aws/aws-sdk-go/aws"
1111
"github.com/aws/aws-sdk-go/aws/session"
12+
"github.com/aws/aws-sdk-go/service/dynamodb"
1213
"github.com/aws/aws-sdk-go/service/organizations"
1314
"github.com/aws/aws-sdk-go/service/s3"
1415
"github.com/santiago-labs/telophasecli/cmd"
@@ -916,6 +917,86 @@ Organization:
916917
},
917918
Targets: []string{"stacks"},
918919
},
920+
{
921+
Name: "Cloudformation example",
922+
OrgYaml: `
923+
Organization:
924+
Name: root
925+
Accounts:
926+
- AccountName: master
927+
928+
Stacks:
929+
- Type: Cloudformation
930+
Path: cloudformation/table.yml
931+
Region: us-west-2
932+
CloudformationParameters:
933+
- "HashKeyElementName=Painter"
934+
- "TableName=test"
935+
- AccountName: test
936+
937+
`,
938+
FetchExpected: &resource.OrganizationUnit{
939+
OUName: "root",
940+
Accounts: []*resource.Account{
941+
{
942+
AccountName: "master",
943+
944+
ManagementAccount: true,
945+
},
946+
},
947+
},
948+
ParseExpected: &resource.OrganizationUnit{
949+
OUName: "root",
950+
ChildOUs: []*resource.OrganizationUnit{},
951+
Accounts: []*resource.Account{
952+
{
953+
AccountName: "master",
954+
955+
ManagementAccount: true,
956+
BaselineStacks: []resource.Stack{
957+
{
958+
Type: "Cloudformation",
959+
Path: "cloudformation/table.yml",
960+
Region: "us-west-2",
961+
CloudformationParameters: []string{
962+
"HashKeyElementName=Painter",
963+
"TableName=test",
964+
},
965+
},
966+
},
967+
},
968+
{
969+
AccountName: "test",
970+
971+
},
972+
},
973+
},
974+
ExpectedResources: func(t *testing.T) {
975+
sess, err := session.NewSession(&aws.Config{
976+
Region: aws.String("us-west-2"),
977+
Endpoint: aws.String("http://localhost:4566"),
978+
S3ForcePathStyle: aws.Bool(true),
979+
})
980+
if err != nil {
981+
t.Fatalf("Failed to create session: %v", err)
982+
}
983+
984+
svc := dynamodb.New(sess)
985+
986+
result, err := svc.ListTables(&dynamodb.ListTablesInput{})
987+
if err != nil {
988+
t.Fatalf("Failed to list buckets: %v", err)
989+
}
990+
991+
if len(result.TableNames) == 0 {
992+
t.Fatal("No tables created")
993+
}
994+
995+
fmt.Println("table name", *result.TableNames[0])
996+
assert.Equal(t, *result.TableNames[0], "test")
997+
},
998+
Targets: []string{"stacks"},
999+
},
9191000
}
9201001

9211002
func TestEndToEnd(t *testing.T) {

0 commit comments

Comments
 (0)