Skip to content

Commit

Permalink
Added domainParts to StaticWeb
Browse files Browse the repository at this point in the history
  • Loading branch information
Kubenaut committed Jun 15, 2023
1 parent 2905ba9 commit 9b526be
Show file tree
Hide file tree
Showing 8 changed files with 200 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ describe("Minimal configuration", function () {
};

expect(throwError).toThrow(
/It's\snot\spossible\sto\sconfig\sthe\sdomain\.*/
/It's\snot\spossible\sto\sautomatically\sconfigure\sthe\sdomain\.*/
);
});
});
Original file line number Diff line number Diff line change
@@ -1,31 +1,41 @@
import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";
import defaultsDeep from "lodash.defaultsdeep";
import { StaticWebArgs, DNSRecordsArgs, defaultArgs } from "./staticwebArgs";
import {
StaticWebArgs,
DNSRecordsArgs,
DomainPartsArgs,
defaultArgs,
} from "./staticwebArgs";
import { Bucket, BucketArgs } from "../storage";

export { StaticWebArgs, DNSRecordsArgs };

export const TYPENAME_STATICWEB = "cloud-toolkit-aws:serverless:StaticWeb";

function getDomainAndSubdomain(domain: string): {
subdomain: string;
parentDomain: string;
} {
const parts = domain.split(".");
if (parts.length < 2) {
throw new Error(`No TLD found on ${domain}`);
}
if (parts.length === 2) {
return { subdomain: "", parentDomain: domain };
}
function getDomainAndSubdomain(
domain: string,
domainParts: DomainPartsArgs | undefined
): DomainPartsArgs {

if (domainParts === undefined) {
const parts = domain.split(".");
if (parts.length < 2) {
throw new Error(`No TLD found on ${domain}`);
}
if (parts.length === 2) {
return { subdomain: "", parentDomain: domain };
}

const subdomain = parts[0];
parts.shift();
return {
subdomain,
parentDomain: parts.join(".") + ".",
};
const subdomain = parts[0];
parts.shift();
return {
subdomain,
parentDomain: parts.join(".") + ".",
};
} else {
return domainParts;
}
}

export class StaticWeb extends pulumi.ComponentResource {
Expand Down Expand Up @@ -163,7 +173,13 @@ export class StaticWeb extends pulumi.ComponentResource {

if (config.domain != null && !config.configureDNS) {
throw new Error(
`It's not possible to config the domain ${args.domain} without configuring a DNS`
`It's not possible to automatically configure the domain ${config.domain} without configuring the DNS`
);
}

if (config.domainParts != null && !config.domain) {
throw new Error(
`The domain is required to configure the needed certificates. domainParts is used to manually configure the hosted zone and the DNS Records. Using domainParts requires setting domain as well`
);
}

Expand Down Expand Up @@ -279,9 +295,9 @@ export class StaticWeb extends pulumi.ComponentResource {
throw new Error("Domain validation options must be defined");
}

const domainParts = getDomainAndSubdomain(domain);
const domainParts = getDomainAndSubdomain(domain, args.domainParts);

var hostedZoneId: pulumi.Input<string> = "";
let hostedZoneId: pulumi.Input<string> = "";

if (args.dns === undefined || args.dns.hostedZoneId === undefined) {
hostedZoneId = aws.route53
Expand Down Expand Up @@ -363,9 +379,9 @@ export class StaticWeb extends pulumi.ComponentResource {
throw new Error("Domain field must be defined");
}

const domainParts = getDomainAndSubdomain(domain);
const domainParts = getDomainAndSubdomain(domain, args.domainParts);

var hostedZoneId: pulumi.Input<string> = "";
let hostedZoneId: pulumi.Input<string> = "";

if (args.dns === undefined || args.dns.hostedZoneId === undefined) {
hostedZoneId = aws.route53
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,18 @@ import * as aws from "@pulumi/aws";
*/
export interface StaticWebArgs {
/**
* Set to true to add an alias to wwww.<domain>
* Domain that will point to the Cloud Front distribution. The hosted zone is automatically extracted by removing the first subdomain.
* e.g. my.nice.website.com -> my - subdomain | nice.website.com - hosted zone.
* The subdomain is used as the name of the DNS Record that points to the Cloud Front distribution.
* configureDNS should be set to true.
*/
domain?: string;
/**
* Subdomain and parent domain of the DNS Record. The parent domain is used to determine the hosted zone that will hold the DNS Record.
* The subdomain is used as the name of the DNS Record that points to the Cloud Front distribution.
* Used alongside domain. configureDNS should be set to true.
*/
domainParts?: DomainPartsArgs
/**
* Set to true to add an alias to wwww.<domain>
*/
Expand Down Expand Up @@ -40,6 +49,20 @@ export interface CdnCacheArgs {
ttl: number;
}

/**
* Arguments to manually configure the domain of the DNS Record that points to the CloudFront distribution
*/
export interface DomainPartsArgs {
/**
* Subdomain part that will be the name of the DNS Record
*/
subdomain: string;
/**
* Domain used to extract the hosted zone id for the DNS Record
*/
parentDomain: string;
}

/**
* Arguments to configure the DNS
*/
Expand Down
37 changes: 36 additions & 1 deletion schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1510,6 +1510,15 @@ types:
domain:
description: Set to true to add an alias to wwww.<domain>
type: string
domainParts:
description: >-
Subdomain and parent domain of the DNS Record. The parent domain is
used to determine the hosted zone that will hold the DNS Record.
The subdomain is used as the name of the DNS Record that points to the Cloud Front distribution.
Used alongside domain. configureDNS should be set to true.
$ref: "#/types/cloud-toolkit-aws:serverless:DomainParts"
includeWWW:
description: Set to true to add an alias to wwww.<domain>
type: boolean
Expand All @@ -1535,6 +1544,15 @@ types:
type: object
required:
- ttl
cloud-toolkit-aws:serverless:DomainParts:
properties:
subdomain:
description: Subdomain part that will be the name of the DNS Record
type: string
parentDomain:
description: Domain used to extract the hosted zone id for the DNS Record
type: string
type: object
cloud-toolkit-aws:serverless:CdnDns:
properties:
ttl:
Expand Down Expand Up @@ -3343,8 +3361,25 @@ resources:
- distribution
inputProperties:
domain:
description: Set to true to add an alias to wwww.<domain>
description: >-
Domain that will point to the Cloud Front distribution. The hosted
zone is automatically extracted by removing the first subdomain.
e.g. my.nice.website.com -> my - subdomain | nice.website.com - hosted zone.
The subdomain is used as the name of the DNS Record that points to the Cloud Front distribution.
configureDNS should be set to true.
type: string
domainParts:
description: >-
Subdomain and parent domain of the DNS Record. The parent domain is
used to determine the hosted zone that will hold the DNS Record.
The subdomain is used as the name of the DNS Record that points to the Cloud Front distribution.
Used alongside domain. configureDNS should be set to true.
$ref: "#/types/cloud-toolkit-aws:serverless:DomainParts"
includeWWW:
description: Set to true to add an alias to wwww.<domain>
type: boolean
Expand Down
12 changes: 11 additions & 1 deletion sdk/nodejs/serverless/staticWeb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ export class StaticWeb extends pulumi.ComponentResource {
resourceInputs["configureDNS"] = args ? args.configureDNS : undefined;
resourceInputs["dns"] = args ? args.dns : undefined;
resourceInputs["domain"] = args ? args.domain : undefined;
resourceInputs["domainParts"] = args ? args.domainParts : undefined;
resourceInputs["includeWWW"] = args ? args.includeWWW : undefined;
resourceInputs["priceClass"] = args ? args.priceClass : undefined;
resourceInputs["DNSRecords"] = undefined /*out*/;
Expand Down Expand Up @@ -140,9 +141,18 @@ export interface StaticWebArgs {
*/
dns?: pulumi.Input<inputs.serverless.CdnDnsArgs>;
/**
* Set to true to add an alias to wwww.<domain>
* Domain that will point to the Cloud Front distribution. The hosted zone is automatically extracted by removing the first subdomain.
* e.g. my.nice.website.com -> my - subdomain | nice.website.com - hosted zone.
* The subdomain is used as the name of the DNS Record that points to the Cloud Front distribution.
* configureDNS should be set to true.
*/
domain?: pulumi.Input<string>;
/**
* Subdomain and parent domain of the DNS Record. The parent domain is used to determine the hosted zone that will hold the DNS Record.
* The subdomain is used as the name of the DNS Record that points to the Cloud Front distribution.
* Used alongside domain. configureDNS should be set to true.
*/
domainParts?: pulumi.Input<inputs.serverless.DomainPartsArgs>;
/**
* Set to true to add an alias to wwww.<domain>
*/
Expand Down
11 changes: 11 additions & 0 deletions sdk/nodejs/types/serverless/input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,17 @@ export interface DeadLetterQueueTypeArgs {
type: pulumi.Input<enums.serverless.DeadLetterQueueTypes>;
}

export interface DomainPartsArgs {
/**
* Domain used to extract the hosted zone id for the DNS Record
*/
parentDomain?: pulumi.Input<string>;
/**
* Subdomain part that will be the name of the DNS Record
*/
subdomain?: pulumi.Input<string>;
}

export interface QueueArgs {
/**
* Dead Letter Queue attached to the component to create.
Expand Down
40 changes: 40 additions & 0 deletions sdk/python/cloud_toolkit_aws/serverless/_inputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
'CdnCacheArgs',
'CdnDnsArgs',
'DeadLetterQueueTypeArgs',
'DomainPartsArgs',
'QueueArgs',
]

Expand Down Expand Up @@ -145,6 +146,45 @@ def message_retention_seconds(self, value: Optional[pulumi.Input[float]]):
pulumi.set(self, "message_retention_seconds", value)


@pulumi.input_type
class DomainPartsArgs:
def __init__(__self__, *,
parent_domain: Optional[pulumi.Input[str]] = None,
subdomain: Optional[pulumi.Input[str]] = None):
"""
:param pulumi.Input[str] parent_domain: Domain used to extract the hosted zone id for the DNS Record
:param pulumi.Input[str] subdomain: Subdomain part that will be the name of the DNS Record
"""
if parent_domain is not None:
pulumi.set(__self__, "parent_domain", parent_domain)
if subdomain is not None:
pulumi.set(__self__, "subdomain", subdomain)

@property
@pulumi.getter(name="parentDomain")
def parent_domain(self) -> Optional[pulumi.Input[str]]:
"""
Domain used to extract the hosted zone id for the DNS Record
"""
return pulumi.get(self, "parent_domain")

@parent_domain.setter
def parent_domain(self, value: Optional[pulumi.Input[str]]):
pulumi.set(self, "parent_domain", value)

@property
@pulumi.getter
def subdomain(self) -> Optional[pulumi.Input[str]]:
"""
Subdomain part that will be the name of the DNS Record
"""
return pulumi.get(self, "subdomain")

@subdomain.setter
def subdomain(self, value: Optional[pulumi.Input[str]]):
pulumi.set(self, "subdomain", value)


@pulumi.input_type
class QueueArgs:
def __init__(__self__, *,
Expand Down
Loading

0 comments on commit 9b526be

Please sign in to comment.