Skip to content

Commit

Permalink
Adding DynamoDB table working composition and claim (#143)
Browse files Browse the repository at this point in the history
* dynamodb provisoned gsi lsi addition

* lsi xrd correction

* update dynamo definition and claim folder structure

* Apply suggestions from code review

removing region tablearn default namespace fields

Co-authored-by: candonov <25967713+candonov@users.noreply.github.com>

* updating config fields

---------

Co-authored-by: candonov <25967713+candonov@users.noreply.github.com>
  • Loading branch information
7navyasa and candonov authored Sep 7, 2023
1 parent d9fd2ac commit 7a7fc52
Show file tree
Hide file tree
Showing 7 changed files with 355 additions and 0 deletions.
141 changes: 141 additions & 0 deletions compositions/upbound-aws-provider/dynamodb/definition.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
# SPDX-License-Identifier: Apache-2.0

apiVersion: apiextensions.crossplane.io/v1
kind: CompositeResourceDefinition
metadata:
name: xdynamodbtables.awsblueprints.io
spec:
group: awsblueprints.io
names:
kind: XDynamoDBTable
plural: xdynamodbtables
claimNames:
kind: DynamoDBTable
plural: dynamodbtables
connectionSecretKeys:
- tableName
versions:
- name: v1alpha1
served: true
referenceable: true
schema:
openAPIV3Schema:
type: object
description: Table is the Schema for the tables API
properties:
spec:
type: object
properties:
resourceConfig:
properties:
providerConfigName:
type: string
default: aws-provider-config
region:
type: string
tags:
additionalProperties:
type: string
description: Key-value map of resource tags.
type: object
type: object
dynamoConfig:
properties:
attribute: #required for hashKey and/or rangeKey
items:
properties:
name: #name of the hashKey and/or rangeKey
type: string
type:
enum:
- B #binary
- N #number
- S #string
type: string
required:
- name
- type
type: object
type: array
hashKey:
type: string
rangeKey:
type: string
billingMode:
type: string
default: PAY_PER_REQUEST
readCapacity:
type: number
writeCapacity:
type: number
name:
type: string
globalSecondaryIndex:
items:
properties:
hashKey:
type: string
name:
type: string
rangeKey:
type: string
readCapacity:
type: number
writeCapacity:
type: number
projectionType:
type: string
nonKeyAttributes: #required for gsi
items:
type: string
type: array
type: object
required:
- hashKey
- name
- rangeKey
- readCapacity
- writeCapacity
- projectionType
- nonKeyAttributes
type: array
localSecondaryIndex:
items:
properties:
name:
type: string
rangeKey:
type: string
projectionType:
type: string
nonKeyAttributes: #required for lsi
items:
type: string
type: array
type: object
required:
- name
- rangeKey
- projectionType
- nonKeyAttributes
type: array
required:
- hashKey
- attribute
type: object
required:
- resourceConfig
- dynamoConfig
status:
type: object
description: TableStatus defines the observed state of Table
properties:
tableArn:
description: Indicates this table's ARN
type: string
tableName:
description: Indicates this table's Name
type: string
required:
- spec
89 changes: 89 additions & 0 deletions compositions/upbound-aws-provider/dynamodb/table.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
# SPDX-License-Identifier: Apache-2.0

apiVersion: apiextensions.crossplane.io/v1
kind: Composition
metadata:
name: table.dynamodb.awsblueprints.io
labels:
awsblueprints.io/provider: aws
awsblueprints.io/environment: dev
spec:
writeConnectionSecretsToNamespace: crossplane-system
compositeTypeRef:
apiVersion: awsblueprints.io/v1alpha1
kind: XDynamoDBTable
patchSets:
- name: common-fields
patches:
- type: FromCompositeFieldPath
fromFieldPath: spec.resourceConfig.providerConfigName
toFieldPath: spec.providerConfigRef.name
- type: FromCompositeFieldPath
fromFieldPath: spec.resourceConfig.region
toFieldPath: spec.forProvider.region
- type: FromCompositeFieldPath
fromFieldPath: spec.dynamoConfig.name
toFieldPath: metadata.annotations[crossplane.io/external-name]
resources:
- name: table
connectionDetails:
- type: FromFieldPath
name: tableName
fromFieldPath: status.atProvider.id
base:
apiVersion: dynamodb.aws.upbound.io/v1beta1
kind: Table
spec:
forProvider:
writeConnectionSecretToRef:
namespace: crossplane-system
patches:
- type: PatchSet
patchSetName: common-fields
- type: FromCompositeFieldPath
fromFieldPath: spec.dynamoConfig.attribute
toFieldPath: spec.forProvider.attribute
policy:
mergeOptions:
appendSlice: true
keepMapValues: true
- type: FromCompositeFieldPath
fromFieldPath: spec.resourceConfig.tags
toFieldPath: spec.forProvider.tags
policy:
mergeOptions:
keepMapValues: true
- type: FromCompositeFieldPath
fromFieldPath: spec.dynamoConfig.hashKey
toFieldPath: spec.forProvider.hashKey
- type: FromCompositeFieldPath
fromFieldPath: spec.dynamoConfig.billingMode
toFieldPath: spec.forProvider.billingMode
- type: FromCompositeFieldPath
fromFieldPath: spec.dynamoConfig.rangeKey
toFieldPath: spec.forProvider.rangeKey
- type: FromCompositeFieldPath
fromFieldPath: spec.dynamoConfig.readCapacity
toFieldPath: spec.forProvider.readCapacity
- type: FromCompositeFieldPath
fromFieldPath: spec.dynamoConfig.writeCapacity
toFieldPath: spec.forProvider.writeCapacity
- type: FromCompositeFieldPath
fromFieldPath: spec.dynamoConfig.globalSecondaryIndex
toFieldPath: spec.forProvider.globalSecondaryIndex
policy:
mergeOptions:
keepMapValues: true
- type: FromCompositeFieldPath
fromFieldPath: spec.dynamoConfig.localSecondaryIndex
toFieldPath: spec.forProvider.localSecondaryIndex
policy:
mergeOptions:
keepMapValues: true
- type: ToCompositeFieldPath
fromFieldPath: status.atProvider.id
toFieldPath: status.tableName
- type: ToCompositeFieldPath
fromFieldPath: status.atProvider.arn
toFieldPath: status.tableArn
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
apiVersion: awsblueprints.io/v1alpha1
kind: DynamoDBTable
metadata:
name: test-dynamodb-table-2
spec:
writeConnectionSecretToRef:
name: dynamo3
resourceConfig:
region: us-west-2
tags:
namespace: team-x
cluster: crossplane
dynamoConfig:
attribute:
- name: UserId
type: S
hashKey: UserId
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
apiVersion: awsblueprints.io/v1alpha1
kind: DynamoDBTable
metadata:
name: test-gsi-dynamodb-table
spec:
writeConnectionSecretToRef:
name: dynamogsi
resourceConfig:
region: us-west-2
tags:
namespace: team-x
cluster: crossplane
dynamoConfig:
attribute:
- name: UserId
type: S
- name: UserName
type: S
- name: Pass
type: B
billingMode: PROVISIONED
globalSecondaryIndex:
- hashKey: UserName
name: UserNameIndex
nonKeyAttributes:
- UserId
projectionType: INCLUDE
rangeKey: Pass
readCapacity: 10
writeCapacity: 10
readCapacity: 20
writeCapacity: 20
hashKey: UserId
rangeKey: UserName
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
apiVersion: awsblueprints.io/v1alpha1
kind: DynamoDBTable
metadata:
name: test-lsi2-dynamodb-table
spec:
writeConnectionSecretToRef:
name: dynamolsi
resourceConfig:
region: us-west-2
tags:
namespace: team-x
cluster: crossplane
dynamoConfig:
attribute:
- name: Artist
type: S
- name: SongTitle
type: S
- name: AlbumTitle
type: S
billingMode: PROVISIONED
localSecondaryIndex:
- name: AlbumTitleIndex
nonKeyAttributes:
- Genre
projectionType: INCLUDE
rangeKey: AlbumTitle
readCapacity: 20
writeCapacity: 20
hashKey: Artist
rangeKey: SongTitle
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
apiVersion: awsblueprints.io/v1alpha1
kind: DynamoDBTable
metadata:
name: test-pro-dynamodb-table
spec:
writeConnectionSecretToRef:
name: dynamopc
resourceConfig:
region: us-west-2
tags:
namespace: team-x
cluster: crossplane
dynamoConfig:
attribute:
- name: UserId
type: S
- name: UserName
type: S
billingMode: PROVISIONED
readCapacity: 2
writeCapacity: 2
hashKey: UserId
rangeKey: UserName
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
apiVersion: awsblueprints.io/v1alpha1
kind: DynamoDBTable
metadata:
name: test-pro-dynamodb-table
spec:
writeConnectionSecretToRef:
name: dynamo
resourceConfig:
region: us-west-2
tags:
namespace: team-x
cluster: crossplane
dynamoConfig:
attribute:
- name: UserId
type: S
billingMode: PROVISIONED
readCapacity: 2
writeCapacity: 2
hashKey: UserId

0 comments on commit 7a7fc52

Please sign in to comment.