Skip to content

Commit

Permalink
feat: CognitoUserPoolDomain mapping (#42)
Browse files Browse the repository at this point in the history
* feat: CognitoUserPoolDomain mapping

* docs(changeset): Added mapping for CognitoUserPoolDomain

* refactor: add new unsupported props for user pool

* fix: touch all DomainValidationOptions HostedZoneIds for ACM Cert
  • Loading branch information
semcc authored Oct 15, 2024
1 parent 6e947b3 commit 90e4e7c
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 150 deletions.
5 changes: 5 additions & 0 deletions .changeset/honest-eggs-drive.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@nrfcloud/cdktf-aws-adaptor": patch
---

Added mapping for CognitoUserPoolDomain
41 changes: 41 additions & 0 deletions src/__tests__/mappings/__snapshots__/cognito.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -367,3 +367,44 @@ exports[`Cognito mappings > Should map AWS::Cognito::UserPoolClient 1`] = `
}
}"
`;

exports[`Cognito mappings > Should map AWS::Cognito::UserPoolDomain 1`] = `
"{
"provider": {
"aws": [
{
"alias": "us_east_1",
"region": "us-east-1"
}
]
},
"resource": {
"aws_cognito_user_pool_domain": {
"resource_22C949BF": {
"certificate_arn": "SomeArn",
"domain": "auth.example.com",
"user_pool_id": "userPoolId"
}
}
},
"terraform": {
"backend": {
"local": {
"path": "/terraform.test-stack.tfstate"
}
},
"required_providers": {
"aws": {
"source": "aws",
"version": "5.65.0"
}
}
},
"variable": {
"resource_refs_CDA17697": {
"default": "\${join(\\"\\", [aws_cognito_user_pool_domain.resource_22C949BF.cloudfront_distribution, \\",\\", aws_cognito_user_pool_domain.resource_22C949BF.id])}",
"type": "string"
}
}
}"
`;
140 changes: 0 additions & 140 deletions src/__tests__/mappings/__snapshots__/lambda.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -345,143 +345,3 @@ exports[`Lambda mappings > should map CfnFunction to LambdaFunction 1`] = `
}
}"
`;

exports[`Lambda mappings > should map CfnFunction with inline zip file to LambdaFunction 1`] = `
"{
"provider": {
"archive": [
{
}
],
"aws": [
{
"alias": "us_east_1",
"region": "us-east-1"
}
]
},
"resource": {
"archive_file": {
"resource_inline-zip-archive_3EB43928": {
"output_path": "/var/folders/xq/d7cqhy255z12lx4c5kvwgrsm0000gn/T/c8f445aafa04b954f73da3e7bb70b92b9587014103.zip",
"provider": "archive",
"source": [
{
"content": "zipFile",
"filename": "index.js"
}
],
"type": "zip"
}
},
"aws_lambda_function": {
"resource_22C949BF": {
"architectures": [
"x86_64"
],
"code_signing_config_arn": "codeSigningConfigArn",
"dead_letter_config": {
"target_arn": "targetArn"
},
"description": "description",
"environment": {
"variables": {
"key": "value"
}
},
"ephemeral_storage": {
"size": 1
},
"file_system_config": {
"arn": "arn",
"local_mount_path": "localMountPath"
},
"function_name": "functionName",
"handler": "handler",
"image_config": {
"command": [
"command"
],
"entry_point": [
"entryPoint"
],
"working_directory": "workingDirectory"
},
"image_uri": "imageUri",
"kms_key_arn": "kmsKeyArn",
"layers": [
"layers"
],
"logging_config": {
"application_log_level": "applicationLogLevel",
"log_format": "logFormat",
"log_group": "logGroup",
"system_log_level": "systemLogLevel"
},
"memory_size": 1,
"package_type": "packageType",
"publish": true,
"reserved_concurrent_executions": 1,
"role": "role",
"runtime": "runtime",
"s3_bucket": "\${aws_s3_object.resource_inline-zip-object_57BC8C94.bucket}",
"s3_key": "\${aws_s3_object.resource_inline-zip-object_57BC8C94.key}",
"s3_object_version": "\${aws_s3_object.resource_inline-zip-object_57BC8C94.version_id}",
"snap_start": {
"apply_on": "1"
},
"tags": {
"key": "value"
},
"timeout": 1,
"tracing_config": {
"mode": "Active"
},
"vpc_config": {
"ipv6_allowed_for_dual_stack": true,
"security_group_ids": [
"securityGroupIds"
],
"subnet_ids": [
"subnetIds"
]
}
}
},
"aws_s3_bucket": {
"AssetBucket": {
}
},
"aws_s3_object": {
"resource_inline-zip-object_57BC8C94": {
"bucket": "\${aws_s3_bucket.AssetBucket.bucket}",
"key": "c8f445aafa04b954f73da3e7bb70b92b9587014103-inline-zip-object",
"source": "\${archive_file.resource_inline-zip-archive_3EB43928.output_path}"
}
}
},
"terraform": {
"backend": {
"local": {
"path": "/terraform.test-stack.tfstate"
}
},
"required_providers": {
"archive": {
"source": "hashicorp/archive",
"version": "2.6.0"
},
"aws": {
"source": "aws",
"version": "5.65.0"
}
}
},
"variable": {
"resource_refs_CDA17697": {
"default": "\${join(\\"\\", [aws_lambda_function.resource_22C949BF.arn, \\",\\", \\"[object Object]\\", \\",\\", aws_lambda_function.resource_22C949BF.snap_start[0].apply_on, \\",\\", aws_lambda_function.resource_22C949BF.snap_start[0].optimization_status])}",
"type": "string"
}
}
}"
`;
19 changes: 19 additions & 0 deletions src/__tests__/mappings/cognito.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ import {
} from "@cdktf/provider-aws/lib/cognito-identity-pool-roles-attachment/index.js";
import { CognitoIdentityPool } from "@cdktf/provider-aws/lib/cognito-identity-pool/index.js";
import { CognitoUserPoolClient } from "@cdktf/provider-aws/lib/cognito-user-pool-client/index.js";
import { CognitoUserPoolDomain } from "@cdktf/provider-aws/lib/cognito-user-pool-domain/index.js";
import { CognitoUserPool } from "@cdktf/provider-aws/lib/cognito-user-pool/index.js";
import {
CfnIdentityPool,
CfnIdentityPoolRoleAttachment,
CfnUserPool,
CfnUserPoolClient,
CfnUserPoolDomain,
} from "aws-cdk-lib/aws-cognito";
import { synthesizeElementAndTestStability } from "../helpers.js";

Expand Down Expand Up @@ -455,4 +457,21 @@ describe("Cognito mappings", () => {
["adminCreateUserConfig.unusedAccountValidityDays", "userPoolAddOns.advancedSecurityAdditionalFlows"],
);
});

it("Should map AWS::Cognito::UserPoolDomain", () => {
synthesizeElementAndTestStability(
CfnUserPoolDomain,
{
customDomainConfig: { certificateArn: "SomeArn" },
domain: "auth.example.com",
userPoolId: "userPoolId",
},
CognitoUserPoolDomain,
{
certificateArn: "SomeArn",
domain: "auth.example.com",
userPoolId: "userPoolId",
},
);
});
});
3 changes: 2 additions & 1 deletion src/mappings/services/certificate-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { deleteUndefinedKeys, registerMappingTyped } from "../utils.js";

export function registerCertificateManagerMappings() {
registerMappingTyped(CfnCertificate, AcmCertificate, {
resource(scope, id, props) {
resource(scope, id, props, proxy) {
const cert = new AcmCertificate(
scope,
id,
Expand All @@ -29,6 +29,7 @@ export function registerCertificateManagerMappings() {
);

if (props.ValidationMethod === "DNS") {
proxy.touchPath("DomainValidationOptions.*.HostedZoneId");
const hostedZoneId = props.DomainValidationOptions?.[0].HostedZoneId
?? new DataAwsRoute53Zone(scope, `${id}-zone-data`, {
name: props.DomainName,
Expand Down
34 changes: 25 additions & 9 deletions src/mappings/services/cognito.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,18 @@ import {
CognitoUserPoolClient,
CognitoUserPoolClientConfig,
} from "@cdktf/provider-aws/lib/cognito-user-pool-client/index.js";
import {
CognitoUserPoolDomain,
CognitoUserPoolDomainConfig,
} from "@cdktf/provider-aws/lib/cognito-user-pool-domain/index.js";
import { CognitoUserPool, CognitoUserPoolConfig } from "@cdktf/provider-aws/lib/cognito-user-pool/index.js";
import { Names } from "aws-cdk-lib";
import {
CfnIdentityPool,
CfnIdentityPoolRoleAttachment,
CfnUserPool,
CfnUserPoolClient,
CfnUserPoolDomain,
} from "aws-cdk-lib/aws-cognito";
import { deleteUndefinedKeys, registerMappingTyped } from "../utils.js";

Expand Down Expand Up @@ -175,8 +180,6 @@ export function registerCognitoMappings() {
configurationSet: userPool?.EmailConfiguration?.ConfigurationSet,
emailSendingAccount: userPool?.EmailConfiguration?.EmailSendingAccount,
},
// emailVerificationMessage: userPool?.EmailVerificationMessage,
// emailVerificationSubject: userPool?.EmailVerificationSubject,
lambdaConfig: {
createAuthChallenge: userPool?.LambdaConfig?.CreateAuthChallenge,
customMessage: userPool?.LambdaConfig?.CustomMessage,
Expand Down Expand Up @@ -262,20 +265,16 @@ export function registerCognitoMappings() {
},
};

const cleaned = deleteUndefinedKeys(mapped);

const pool = new CognitoUserPool(
scope,
id,
cleaned,
);
const pool = new CognitoUserPool(scope, id, deleteUndefinedKeys(mapped));

pool.name = mapped.name || Names.uniqueResourceName(pool, { maxLength: 64 });
return pool;
},
unsupportedProps: [
"AdminCreateUserConfig.UnusedAccountValidityDays",
"UserPoolAddOns.AdvancedSecurityAdditionalFlows",
"EmailAuthenticationMessage",
"EmailAuthenticationSubject",
],
attributes: {
Ref: resource => resource.id,
Expand All @@ -285,4 +284,21 @@ export function registerCognitoMappings() {
ProviderURL: resource => `https://${resource.endpoint}`,
},
});

registerMappingTyped(CfnUserPoolDomain, CognitoUserPoolDomain, {
resource(scope, id, userPoolDomain) {
const mapped: CognitoUserPoolDomainConfig = {
domain: userPoolDomain.Domain,
userPoolId: userPoolDomain.UserPoolId,
certificateArn: userPoolDomain.CustomDomainConfig?.CertificateArn,
};

return new CognitoUserPoolDomain(scope, id, deleteUndefinedKeys(mapped));
},
attributes: {
Ref: resource => resource.id,
Id: resource => resource.id,
CloudFrontDistribution: resource => resource.cloudfrontDistribution,
},
});
}

0 comments on commit 90e4e7c

Please sign in to comment.