Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DBClusterEndpoint] Create new resource #200

Merged
merged 46 commits into from
Jun 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
de8d79b
DBClusterEndpoint resource dummy added
Jun 1, 2022
0a0d0f4
[DBClusterEndpoint] Resource definition added, happy path for read ha…
Jun 1, 2022
56a7c72
[DBClusterEndpoint] Add error handling for read handler
Jun 1, 2022
cdebee6
[DBClusterEndpoint] Implement Create Handler
Jun 1, 2022
aa9cb1b
[DBClusterEndpoint] Implemented List and Update Handlers
Jun 1, 2022
e29e70f
[DBClusterEndpoint] Updated inputs
Jun 1, 2022
1c3ab38
[DBClusterEndpoint] Fix schema, deletes and imports
Jun 1, 2022
65ae33e
[DBClusterEndpoint] Fix Create Handler, add some tests
Jun 1, 2022
fea259b
[DBClusterEndpoint] Fix build
Jun 1, 2022
5392d6c
[DBClusterEndpoint] Basic test implementation
Jun 1, 2022
240ca07
[DBClusterEndpoint] Safe create, Modify tags on update
Jun 1, 2022
33d5f82
Ran pre-commit to fix formatting
Jun 1, 2022
a2737a1
[DBClusterEndpoint] Add git workflow, fix build error for cfn-common
Jun 1, 2022
1bb1c0e
[DBClusterEndpoint] Fix git workflow definition
Jun 1, 2022
6f12e88
[DBClusterEndpoint] Remove condition on Resource Role
Jun 1, 2022
28a07dd
[DBClusterEndpoint] Convert Primary Identifier to lowercase. Make pro…
Jun 2, 2022
0b1c6c4
[DBClusterEndpoint] Convert Primary identifier to lowercase, add unit…
Jun 2, 2022
a538c9f
[DBClusterEndpoint] Add config for handlers, rework List handler
Jun 2, 2022
f8dde20
[DBClusterEndpoint] Raise test coverage
Jun 3, 2022
90ab5b8
[DBClusterEndpoint] Add more tagging-related tests
Jun 3, 2022
b405a6f
[DBClusterEndpoint] Add more tests, make resource compliant with CFN …
Jun 4, 2022
4b91809
[DBClusterEndpoint] Make all contract tests pass
Jun 4, 2022
95a2ef6
[DBClusterEndpoint] Make DBClusterIdentifier create-only, set replace…
Jun 4, 2022
57627db
[DBClusterEndpoint] Update uses modify call
Jun 5, 2022
32477c4
[DBClusterEndpoint] Update README.md
Jun 5, 2022
52e1ac5
[DBClusterEndpoint] Update README.md wording
Jun 5, 2022
8be2d28
[DBClusterEndpoint] Formatting, permission change
Jun 7, 2022
e9644ee
[DBClusterEndpoint] Remove extra invocation of DescribeDBClusterEndpoint
Jun 7, 2022
3ac38c8
[DBClusterEndpoint] Code style fixes
Jun 7, 2022
ab76ccd
[DBClusterEndpoint] Added ARN and Endpoint Address as readonly proper…
Jun 7, 2022
780d2ce
Merge branch 'master' into db-cluster-endpoint
khebul Jun 7, 2022
a29623d
Merge branch 'master' into db-cluster-endpoint
khebul Jun 8, 2022
cb1fad9
[DBClusterEndpoint] Fix nits
Jun 7, 2022
e8b7b0c
[DBClusterEndpoint] fix copy-paste remnants, fix one nit
Jun 7, 2022
203ee95
[DBClusterEndpoint] Move tagging to common. Save ARN in context to re…
Jun 8, 2022
a16ded1
[DBClusterEndpoint] Use common Tagging class for tagging
Jun 8, 2022
0a54f44
[DBClusterEndpoint] Remove usage of CfnNotFoundException
Jun 8, 2022
3de2fe7
Merge branch 'master' into db-cluster-endpoint
khebul Jun 9, 2022
f727d37
Merge branch 'master' into db-cluster-endpoint
khebul Jun 9, 2022
35fff4c
Merge branch 'master' into db-cluster-endpoint
khebul Jun 9, 2022
33a124b
Merge branch 'master' into db-cluster-endpoint
khebul Jun 13, 2022
fd4424c
Revert "[DBClusterEndpoint] Use common Tagging class for tagging"
Jun 13, 2022
9265d13
Revert "[DBClusterEndpoint] Move tagging to common. Save ARN in conte…
Jun 13, 2022
510988a
[DBClusterEndpoint] Revert changes to tagging
Jun 13, 2022
e8446ce
[DBClusterEndpoint] update contract tests template to work with Outputs
Jun 13, 2022
a9b7557
[DBClusterEndpoint] Add .pre-commit-config.yaml to root directory as …
Jun 14, 2022
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
5 changes: 5 additions & 0 deletions .github/workflows/maven-verify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,8 @@ jobs:
cd "${GITHUB_WORKSPACE}/aws-rds-optiongroup"
mvn clean verify --no-transfer-progress
cat rpdk.log
- name: Verify AWS::RDS::DBClusterEndpoint
run: |
cd "${GITHUB_WORKSPACE}/aws-rds-dbclusterendpoint"
mvn clean verify --no-transfer-progress
cat rpdk.log
21 changes: 4 additions & 17 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,19 +1,6 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.4.0
- repo: https://github.com/aws-cloudformation/cfn-python-lint
rev: v0.61.0 # The version of cfn-lint to use
hooks:
- id: check-case-conflict
- id: detect-private-key
- id: end-of-file-fixer
- id: mixed-line-ending
args:
- --fix=lf
- id: trailing-whitespace
- id: pretty-format-json
args:
- --autofix
- --indent=2
- --no-sort-keys
- id: check-merge-conflict
- id: check-yaml
exclude: codebuild-ci.yaml
- id: cfn-python-lint
files: aws-rds-dbclusterendpoint/contract-test-required-resources.template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -74,24 +74,24 @@ protected Consumer<ProgressEvent<ModelT, CallbackT>> expectFailed(final HandlerE

protected ProgressEvent<ModelT, CallbackT> test_handleRequest_base(
final CallbackT context,
final Supplier<ResourceT> dbInstanceSupplier,
final Supplier<ResourceT> resourceSupplier,
osdrv marked this conversation as resolved.
Show resolved Hide resolved
final Supplier<ModelT> desiredStateSupplier,
final Consumer<ProgressEvent<ModelT, CallbackT>> expect
) {
return test_handleRequest_base(context, dbInstanceSupplier, null, desiredStateSupplier, expect);
return test_handleRequest_base(context, resourceSupplier, null, desiredStateSupplier, expect);
}

protected ProgressEvent<ModelT, CallbackT> test_handleRequest_base(
final CallbackT context,
final Supplier<ResourceT> dbInstanceSupplier,
final Supplier<ResourceT> resourceSupplier,
final Supplier<ModelT> previousStateSupplier,
final Supplier<ModelT> desiredStateSupplier,
final Consumer<ProgressEvent<ModelT, CallbackT>> expect
) {
return test_handleRequest_base(
context,
ResourceHandlerRequest.<ModelT>builder(),
dbInstanceSupplier,
resourceSupplier,
previousStateSupplier,
desiredStateSupplier,
expect
Expand All @@ -101,13 +101,13 @@ protected ProgressEvent<ModelT, CallbackT> test_handleRequest_base(
protected ProgressEvent<ModelT, CallbackT> test_handleRequest_base(
final CallbackT context,
final ResourceHandlerRequest.ResourceHandlerRequestBuilder<ModelT> builder,
final Supplier<ResourceT> dbInstanceSupplier,
final Supplier<ResourceT> resourceSupplier,
final Supplier<ModelT> previousStateSupplier,
final Supplier<ModelT> desiredStateSupplier,
final Consumer<ProgressEvent<ModelT, CallbackT>> expect
) {
if (dbInstanceSupplier != null) {
expectResourceSupply(dbInstanceSupplier);
if (resourceSupplier != null) {
expectResourceSupply(resourceSupplier);
}

builder.desiredResourceState(desiredStateSupplier.get());
Expand Down
20 changes: 20 additions & 0 deletions aws-rds-dbclusterendpoint/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# macOS
.DS_Store
._*

# Maven outputs
.classpath

# IntelliJ
*.iml
.idea
out.java
out/
.settings
.project

# auto-generated files
target/

# our logs
rpdk.log
6 changes: 6 additions & 0 deletions aws-rds-dbclusterendpoint/.pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
repos:
- repo: https://github.com/aws-cloudformation/cfn-python-lint
rev: v0.61.0 # The version of cfn-lint to use
hooks:
- id: cfn-python-lint
files: contract-test-required-resources.template.yaml
28 changes: 28 additions & 0 deletions aws-rds-dbclusterendpoint/.rpdk-config
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"artifact_type": "RESOURCE",
"typeName": "AWS::RDS::DBClusterEndpoint",
"language": "java",
"runtime": "java8",
"entrypoint": "software.amazon.rds.dbclusterendpoint.HandlerWrapper::handleRequest",
"testEntrypoint": "software.amazon.rds.dbclusterendpoint.HandlerWrapper::testEntrypoint",
"settings": {
"version": false,
"subparser_name": null,
"verbose": 0,
"force": false,
"type_name": null,
"artifact_type": null,
"endpoint_url": null,
"region": null,
"target_schemas": [],
"namespace": [
"software",
"amazon",
"rds",
"dbclusterendpoint"
],
"codegen_template_path": "guided_aws",
"protocolVersion": "2.0.0"
},
"executableEntrypoint": "software.amazon.rds.dbclusterendpoint.HandlerWrapperExecutable"
}
17 changes: 17 additions & 0 deletions aws-rds-dbclusterendpoint/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# AWS::RDS::DBClusterEndpoint

Congratulations on starting development! Next steps:

1. Write the JSON schema describing your resource, `aws-rds-dblcusterendpoint.json`
1. Implement your resource handlers.

The RPDK will automatically generate the correct resource model from the schema whenever the project is built via Maven. You can also do this manually with the following command: `cfn generate`.

> Please don't modify files under `target/generated-sources/rpdk`, as they will be automatically overwritten.

The code uses [Lombok](https://projectlombok.org/), and [you may have to install IDE integrations](https://projectlombok.org/) to enable auto-complete for Lombok-annotated classes.

To run contract tests locally, make sure to register required resources stack:
```shell
aws cloudformation --region <region> create-stack --stack-name dbclusterendpoint-contract-test-resources --template-body 'file://./contract-test-required-resources.template.yaml'
```
151 changes: 151 additions & 0 deletions aws-rds-dbclusterendpoint/aws-rds-dbclusterendpoint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
{
"typeName": "AWS::RDS::DBClusterEndpoint",
"description": "The AWS::RDS::DBClusterEndpoint resource allows you to create custom Aurora Cluster endpoint. For more information, see Using custom endpoints in the Amazon RDS Aurora Guide.",
"sourceUrl": "https://github.com/aws-cloudformation/aws-cloudformation-resource-providers-rds",
"tagging": {
"taggable": true
},
"replacementStrategy": "delete_then_create",
"definitions": {
"Tag": {
"description": "A key-value pair to associate with a resource.",
"type": "object",
"properties": {
"Key": {
"type": "string",
"description": "The key name of the tag. You can specify a value that is 1 to 128 Unicode characters in length and cannot be prefixed with aws:. You can use any of the following characters: the set of Unicode letters, digits, whitespace, _, ., /, =, +, and -.",
"minLength": 1,
"maxLength": 128
},
"Value": {
"type": "string",
"description": "The value for the tag. You can specify a value that is 0 to 256 Unicode characters in length and cannot be prefixed with aws:. You can use any of the following characters: the set of Unicode letters, digits, whitespace, _, ., /, =, +, and -.",
"minLength": 0,
"maxLength": 256
}
},
"required": [
"Key",
"Value"
],
"additionalProperties": false
}
},
"properties": {
osdrv marked this conversation as resolved.
Show resolved Hide resolved
"DBClusterIdentifier": {
"description": "The DB cluster identifier of the DB cluster associated with the endpoint. This parameter is stored as a lowercase string.",
"type": "string",
"pattern": "^[a-zA-Z]{1}(?:-?[a-zA-Z0-9]){0,62}$",
"minLength": 1,
"maxLength": 63
},
"DBClusterEndpointIdentifier": {
"description": "The identifier to use for the new endpoint. This parameter is stored as a lowercase string.",
"type": "string",
"pattern": "^[a-z]{1}(?:-?[a-z0-9]){0,62}$",
"minLength": 1,
"maxLength": 63
},
"EndpointType": {
osdrv marked this conversation as resolved.
Show resolved Hide resolved
"description": "The type of the endpoint, one of: READER , WRITER , ANY",
"type": "string",
"enum": [
"READER",
"WRITER",
"ANY"
osdrv marked this conversation as resolved.
Show resolved Hide resolved
]
},
"DBClusterEndpointArn": {
"type": "string",
"description": "The Amazon Resource Name (ARN) for the endpoint."
},
"Endpoint": {
"type": "string",
"description": "The DNS address of the endpoint."
},
"StaticMembers": {
"description": "List of DB instance identifiers that are part of the custom endpoint group.",
"type": "array",
"uniqueItems": true,
"insertionOrder": false,
"items": {
"type": "string"
}
},
"ExcludedMembers": {
"description": "List of DB instance identifiers that aren't part of the custom endpoint group. All other eligible instances are reachable through the custom endpoint. This parameter is relevant only if the list of static members is empty.",
"type": "array",
"uniqueItems": true,
"insertionOrder": false,
"items": {
"type": "string"
}
},
"Tags": {
"description": "An array of key-value pairs to apply to this resource.",
"type": "array",
"maxItems": 50,
"uniqueItems": true,
"insertionOrder": false,
"items": {
"$ref": "#/definitions/Tag"
}
}
},
"additionalProperties": false,
"required": [
"DBClusterIdentifier",
"DBClusterEndpointIdentifier",
"EndpointType"
],
"createOnlyProperties": [
"/properties/DBClusterEndpointIdentifier",
"/properties/DBClusterIdentifier"
],
"primaryIdentifier": [
"/properties/DBClusterEndpointIdentifier"
],
"readOnlyProperties": [
"/properties/Endpoint",
"/properties/DBClusterEndpointArn"
],
"handlers": {
"create": {
"permissions": [
"rds:AddTagsToResource",
"rds:RemoveTagsFromResource",
"rds:CreateDBClusterEndpoint",
"rds:DescribeDBClusterEndpoints",
"rds:ListTagsForResource"
]
},
"read": {
"permissions": [
"rds:DescribeDBClusterEndpoints",
"rds:ListTagsForResource"
]
},
"update": {
"permissions": [
"rds:AddTagsToResource",
"rds:RemoveTagsFromResource",
"rds:DescribeDBClusterEndpoints",
"rds:ModifyDBClusterEndpoint",
"rds:ListTagsForResource"
]
},
"delete": {
"permissions": [
"rds:DeleteDBClusterEndpoint",
"rds:DescribeDBClusterEndpoints",
"rds:ListTagsForResource"
]
},
"list": {
"permissions": [
"rds:DescribeDBClusterEndpoints",
"rds:ListTagsForResource"
]
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
Resources:
ContractTestSecret:
Type: AWS::SecretsManager::Secret
Properties:
Description: Superuser credentials for the DBCluster
GenerateSecretString:
SecretStringTemplate: '{"username": "admin"}'
GenerateStringKey: password
PasswordLength: 16
ExcludeCharacters: '"''@/\ ,'

DBClusterEndpointContractCluster:
Type: AWS::RDS::DBCluster
DependsOn:
- ContractTestSecret
Properties:
Engine: aurora-mysql
MasterUsername: !Sub '{{resolve:secretsmanager:${ContractTestSecret}:SecretString:username}}'
MasterUserPassword: !Sub '{{resolve:secretsmanager:${ContractTestSecret}:SecretString:password}}'

DBClusterEndpointContractInstance:
Type: AWS::RDS::DBInstance
Properties:
DBClusterIdentifier: !Ref DBClusterEndpointContractCluster
DBInstanceClass: db.t3.small
Engine: "aurora-mysql"

Outputs:
DBClusterIdentifier:
Value:
Ref: DBClusterEndpointContractCluster
Export:
Name: DBClusterEndpointContractCluster
DBInstanceIdentifier:
Value:
Ref: DBClusterEndpointContractInstance
Export:
Name: DBClusterEndpointContractInstance
Loading