@intentius/behold 0.30.2 → 0.32.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +791 -16
- package/README.md +78 -23
- package/THIRD_PARTY.md +6 -5
- package/demos.json +14 -9
- package/dist/cli.js +51926 -20221
- package/example-carve/README.md +19 -23
- package/example-carve/app/package.json +1 -1
- package/example-carve/app/src/carved.ts +3 -3
- package/example-carve/carve-report.json +1 -1
- package/example-carve/{legacy-tf → tf-root}/terraform.tfstate +1 -1
- package/example-choudoufu-estate/README.md +7 -0
- package/example-choudoufu-estate/chant.workspace.json +1 -1
- package/example-choudoufu-estate/scripts/choudoufu-down.sh +2 -1
- package/example-choudoufu-estate/scripts/choudoufu-up.sh +10 -3
- package/example-terraform-estate/README.md +32 -5
- package/example-terraform-estate/chant.workspace.json +1 -1
- package/example-terraform-estate/recorded/adoption/platform.json +72 -0
- package/example-terraform-estate/recorded/adoption/prod.json +224 -0
- package/example-three-cloud/README.md +111 -18
- package/example-three-cloud/aws/Pulumi.yaml +15 -0
- package/example-three-cloud/aws/index.ts +174 -0
- package/example-three-cloud/aws/package-lock.json +2725 -0
- package/example-three-cloud/aws/package.json +14 -0
- package/example-three-cloud/aws/tsconfig.json +17 -0
- package/example-three-cloud/azure/main.tf +48 -0
- package/example-three-cloud/azure/site.tf +104 -0
- package/example-three-cloud/chant.config.json +9 -0
- package/example-three-cloud/chant.workspace.json +30 -4
- package/example-three-cloud/dns/chant.config.ts +26 -1
- package/example-three-cloud/dns/src/records.component.ts +32 -6
- package/example-three-cloud/package-lock.json +48 -27
- package/example-three-cloud/package.json +8 -6
- package/example-three-cloud/scripts/emulators-up.sh +28 -1
- package/example-three-cloud/scripts/front-door.ts +679 -86
- package/package.json +26 -8
- package/schemas/graph/v1/graph.schema.json +140 -0
- package/web/adopt-pulumi.js +114 -0
- package/web/adopt-pulumi.test.js +28 -0
- package/web/adopt.js +203 -0
- package/web/adopt.test.js +27 -0
- package/web/app.js +367 -14
- package/web/boot-motion.js +6 -0
- package/web/carve-steps.js +1 -1
- package/web/carve-steps.test.js +2 -2
- package/web/change-set-overlay.js +12 -5
- package/web/change-set-overlay.test.js +22 -0
- package/web/cut-around.d.ts +30 -0
- package/web/cut-around.js +138 -0
- package/web/drift-stream.js +241 -0
- package/web/drift-stream.test.js +146 -0
- package/web/edge-weight.d.ts +8 -2
- package/web/edge-weight.js +38 -4
- package/web/edge-weight.test.js +55 -1
- package/web/graph-query.js +180 -0
- package/web/graph-query.test.js +49 -0
- package/web/graph.html +107 -0
- package/web/index-diff.js +109 -0
- package/web/index-diff.test.js +39 -0
- package/web/index.html +45 -20
- package/web/kiosk-ask-tips.js +15 -5
- package/web/kiosk-ask-tips.test.js +14 -1
- package/web/kiosk-estate-scene.js +72 -8
- package/web/kiosk-light-frame.js +1 -0
- package/web/kiosk-light.js +41 -3
- package/web/kiosk-member-kind.test.js +140 -0
- package/web/kiosk-popover.js +4 -1
- package/web/kiosk-side.js +296 -0
- package/web/kiosk-side.test.js +249 -0
- package/web/kiosk-watch.js +12 -0
- package/web/kiosk-watch.test.js +15 -1
- package/web/kiosk.html +47 -1
- package/web/kiosk.js +106 -7
- package/web/member-kind.js +31 -0
- package/web/neighbourhood.js +105 -0
- package/web/neighbourhood.test.js +131 -0
- package/web/outside-refs.js +515 -0
- package/web/outside-refs.test.js +249 -0
- package/web/template-apps.js +245 -0
- package/web/template-apps.test.js +252 -0
- package/web/templates.js +285 -0
- package/web/templates.test.js +155 -0
- package/web/terragucci-lifecycle.js +112 -62
- package/web/terragucci-lifecycle.test.js +29 -1
- package/web/terragucci-timeline.js +39 -2
- package/web/terragucci-timeline.test.js +42 -1
- package/web/theme-paint.js +14 -0
- package/example-three-cloud/aws/chant.config.ts +0 -8
- package/example-three-cloud/aws/site.component.ts +0 -13
- package/example-three-cloud/aws/src/site.ts +0 -27
- package/example-three-cloud/azure/chant.config.ts +0 -1
- package/example-three-cloud/azure/src/site.component.ts +0 -13
- package/example-three-cloud/azure/src/site.ts +0 -18
- /package/example-carve/{legacy-tf → tf-root}/cdn.tf +0 -0
- /package/example-carve/{legacy-tf → tf-root}/compute.tf +0 -0
- /package/example-carve/{legacy-tf → tf-root}/floci-override.tf.disabled +0 -0
- /package/example-carve/{legacy-tf → tf-root}/modules/cdn/main.tf +0 -0
- /package/example-carve/{legacy-tf → tf-root}/naming.tf +0 -0
- /package/example-carve/{legacy-tf → tf-root}/network.tf +0 -0
- /package/example-carve/{legacy-tf → tf-root}/observability.tf +0 -0
- /package/example-carve/{legacy-tf → tf-root}/outputs.tf +0 -0
- /package/example-carve/{legacy-tf → tf-root}/storage.tf +0 -0
- /package/example-carve/{legacy-tf → tf-root}/versions.tf +0 -0
|
@@ -1,30 +1,121 @@
|
|
|
1
1
|
# three-cloud
|
|
2
2
|
|
|
3
3
|
A small website in AWS, Azure and GCP behind Route 53, as a chant workspace on
|
|
4
|
-
the floci emulators
|
|
5
|
-
|
|
4
|
+
the floci emulators, its four members on three engines: chant, choudoufu and
|
|
5
|
+
plunge. It is behold's `three-cloud` demo, and its exported page asks one
|
|
6
|
+
question: turn Azure off, and where does traffic go?
|
|
6
7
|
|
|
7
8
|
```
|
|
8
|
-
chant.workspace.json the workspace: dns
|
|
9
|
+
chant.workspace.json the workspace: dns and gcp (chant), azure (choudoufu), aws (pulumi, on plunge)
|
|
10
|
+
chant.config.json names azure as the terraform lexicon's `azure` root, for its activities
|
|
9
11
|
dns/src/route53.ts hosted zone, and a latency entry per cloud (HostnameEntry, AddressEntry)
|
|
12
|
+
dns/src/records.component.ts dns's components: azure (reads the estate's outputs) and records
|
|
10
13
|
dns/ops/front-door.op.ts the Op that rebuilds the page
|
|
11
|
-
aws/
|
|
12
|
-
azure/
|
|
14
|
+
aws/index.ts, Pulumi.yaml a Pulumi program on plunge: ECS on Fargate behind a load balancer, in its VPC
|
|
15
|
+
azure/main.tf, site.tf a choudoufu estate: a Container Apps site and its network, through azurerm
|
|
13
16
|
gcp/src/site.ts Cloud Run behind a global load balancer (PublicCloudRun, PrivateEgressNetwork)
|
|
14
|
-
*.component.ts one component per member: how it deploys
|
|
15
|
-
|
|
16
|
-
scripts/
|
|
17
|
-
|
|
17
|
+
*.component.ts one component per chant member: how it deploys
|
|
18
|
+
scripts/emulators-up.sh boots floci, floci-az (with TLS) and floci-gcp, then `choudoufu init` in azure
|
|
19
|
+
scripts/front-door.ts the Op's steps: apply, turn Azure off, wait, export; plan, apply a
|
|
20
|
+
planned set, and an out-of-band edit per member
|
|
18
21
|
```
|
|
19
22
|
|
|
20
|
-
The composites are the lexicons' own. Each member is one component.
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
23
|
+
The composites are the lexicons' own. Each chant member is one component. gcp
|
|
24
|
+
runs its member's apply from `scripts/front-door.ts` (`apply-gcp`) until its
|
|
25
|
+
lexicon has deploy steps of its own (chant#4273). dns has three components.
|
|
26
|
+
`azure` and `aws` stand for those members: each one's step, `member-outputs`,
|
|
27
|
+
reads the member's outputs through its engine and applies nothing.
|
|
28
|
+
`records` builds the dns template with `build-dns`, which fills in
|
|
29
|
+
gcpEndpoint from what is applied and points each health check at the
|
|
30
|
+
emulator that answers for it, then deploys it with `cfn-deploy`, its
|
|
31
|
+
azureEndpoint and awsEndpoint parameters wired to `stackOutput("azure",
|
|
32
|
+
"azureEndpoint")` and `stackOutput("aws", "awsEndpoint")`.
|
|
25
33
|
|
|
26
|
-
|
|
27
|
-
|
|
34
|
+
aws is a Pulumi program (INTENTIUS/behold#1000) with the resources the aws
|
|
35
|
+
member declared when it was a chant member (VpcDefault and FargateAlb), in
|
|
36
|
+
TypeScript on pulumi-aws 7.51.1, pinned as plunge's corpus pins it.
|
|
37
|
+
`Pulumi.yaml` names plunge's record backend over `aws/.plunge`
|
|
38
|
+
(`plunge+file://./.plunge`), which is also how chant knows the member runs
|
|
39
|
+
on plunge. Its provider is explicit and goes to floci at AWS_ENDPOINT_URL
|
|
40
|
+
(default http://localhost:4566) with floci's fake key pair; the program
|
|
41
|
+
refuses an endpoint that is not on this machine. `apply-aws` runs `plunge
|
|
42
|
+
up` on the stack `local` and then `plunge stack export` into
|
|
43
|
+
`aws/stack-export.json`, which is what chant draws the member's graph from
|
|
44
|
+
(the graph read never runs the program). That export, `aws/.plunge` and the
|
|
45
|
+
stack file `Pulumi.local.yaml` (only its encryption salt) are that
|
|
46
|
+
machine's state and stay untracked, so a fresh checkout draws aws with no
|
|
47
|
+
cards until it has applied once.
|
|
48
|
+
|
|
49
|
+
azure is a choudoufu estate (INTENTIUS/choudoufu#2246), the resources the
|
|
50
|
+
azure lexicon's ContainerAppNetwork and ContainerAppSite declared, written in
|
|
51
|
+
HCL with a `live` block. Its provider block reaches floci-az the way
|
|
52
|
+
choudoufu's own floci-az estates do, every endpoint and credential stated.
|
|
53
|
+
`apply-azure` plans it with the terraform lexicon's `choudoufuPlanSet`, run
|
|
54
|
+
as a step of a one-step Op (chant#4483), and applies that set with
|
|
55
|
+
`choudoufuWaveApply`, under the same floci-az endpoint lock. On a chant
|
|
56
|
+
older than the activity (0.124.52 and before) the script calls the same
|
|
57
|
+
function directly. Its records stay in `azure/.tofu-records`.
|
|
58
|
+
|
|
59
|
+
Each cloud publishes its endpoint as an output (`output()` in aws and gcp, an
|
|
60
|
+
`output` block in azure) and `dns` reads it as a parameter of the same name.
|
|
61
|
+
azure's reaches dns through chant (INTENTIUS/chant#4455): dns lists
|
|
62
|
+
`terraform` among its lexicons, since the terraform lexicon is what reads a
|
|
63
|
+
choudoufu member's outputs, and names the estate as its one
|
|
64
|
+
`terraform.roots` entry, `azure`, so a change under `azure/` puts the azure
|
|
65
|
+
component, and dns with it, in the change. When azure's plan creates or
|
|
66
|
+
replaces the Container App, azureEndpoint is known only after azure applies:
|
|
67
|
+
dns's plan lists `azure` under its unresolved inputs and
|
|
68
|
+
`azure.azureEndpoint` under its unknown inputs, and dns applies after azure,
|
|
69
|
+
planned again against the value it applied as. aws reaches dns the same way,
|
|
70
|
+
through the pulumi lexicon, which dns lists too: `plunge stack output --json
|
|
71
|
+
--show-secrets=false` for the applied value and `plunge preview --json` for
|
|
72
|
+
the planned one. gcp still reaches dns through `build-dns`.
|
|
73
|
+
|
|
74
|
+
## Which chant
|
|
75
|
+
|
|
76
|
+
The `azure` and `aws` components need a chant with `member-outputs`
|
|
77
|
+
(chant#4455), and the aws member needs `@intentius/chant-lexicon-pulumi`
|
|
78
|
+
(chant#4453). chant 0.124.54 is the first release with both, and this
|
|
79
|
+
directory depends on it: `npm ci` here installs it. The workspace pins the
|
|
80
|
+
terraform and pulumi lexicons by package at 0.124.58, and chant checks each
|
|
81
|
+
pin against the installed lexicon. behold follows the same release through
|
|
82
|
+
`CHANT_RELEASE` (src/chant-release.ts, behold#1005).
|
|
83
|
+
|
|
84
|
+
## One change set
|
|
85
|
+
|
|
86
|
+
```sh
|
|
87
|
+
npm run change-set # writes .front-door/change-set.json, applies nothing
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
That plans the four members into one change-set document under one digest,
|
|
91
|
+
a part per member in its engine's terms: a chant part each for dns and gcp
|
|
92
|
+
(`chant lifecycle plan local --json`), a choudoufu part for azure
|
|
93
|
+
(the `choudoufuPlanSet` Op activity), and a pulumi part for aws (`plunge preview --json`, read
|
|
94
|
+
by the pulumi lexicon's `pulumiPreviewPart`).
|
|
95
|
+
|
|
96
|
+
```sh
|
|
97
|
+
npx tsx scripts/front-door.ts apply --change-set .front-door/change-set.json
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
applies that set and nothing else. It plans the four members again first,
|
|
101
|
+
and when any part's plan moved, in any engine, it refuses the whole set
|
|
102
|
+
before anything applies: `.front-door/apply-verdict.json` says `refused` and
|
|
103
|
+
names each moved part with chant's reason (`planCoveredBy`), and it exits 3,
|
|
104
|
+
chant's code for a moved plan.
|
|
105
|
+
|
|
106
|
+
## Out-of-band edits
|
|
107
|
+
|
|
108
|
+
```sh
|
|
109
|
+
npx tsx scripts/front-door.ts oob-edit dns # the hosted zone's comment
|
|
110
|
+
npx tsx scripts/front-door.ts oob-edit gcp # a label on the Cloud Run service
|
|
111
|
+
npx tsx scripts/front-door.ts oob-edit azure # a tag on the Container App
|
|
112
|
+
npx tsx scripts/front-door.ts oob-edit aws # the log group's retention, 7 days to 14
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
Each changes one live resource straight on the emulator, so each member's
|
|
116
|
+
own engine has to notice it: chant's live read for dns and gcp, choudoufu's
|
|
117
|
+
plan for azure, `plunge drift` for aws. In behold the edited card turns from
|
|
118
|
+
in sync to drifted when the member's drift is read.
|
|
28
119
|
|
|
29
120
|
## Run it
|
|
30
121
|
|
|
@@ -32,7 +123,10 @@ parameter of the same name.
|
|
|
32
123
|
npx @intentius/behold demo three-cloud
|
|
33
124
|
```
|
|
34
125
|
|
|
35
|
-
Or by hand, from this directory (needs Docker
|
|
126
|
+
Or by hand, from this directory (needs Docker, choudoufu on PATH or named by
|
|
127
|
+
CHOUDOUFU_BIN, and plunge on PATH or named by PLUNGE_BIN, with the nodejs
|
|
128
|
+
language host beside it; on a Mac, the floci-az certificate choudoufu's
|
|
129
|
+
`scripts/floci-az-mac-cert.sh` makes, trusted once):
|
|
36
130
|
|
|
37
131
|
```sh
|
|
38
132
|
npm install
|
|
@@ -43,4 +137,3 @@ npx serve export
|
|
|
43
137
|
|
|
44
138
|
`cd dns && npx chant run front-door` runs the same steps as an Op.
|
|
45
139
|
|
|
46
|
-
Needs chant 0.124.39 or newer.
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# The aws member: a Pulumi program on plunge (INTENTIUS/behold#1000). The
|
|
2
|
+
# backend is plunge's record backend over a local directory beside the
|
|
3
|
+
# program, so the stack, its records and its markers stay in aws/.plunge
|
|
4
|
+
# and nothing is stored anywhere else. chant reads the `plunge+` scheme as
|
|
5
|
+
# "this member runs on plunge" (chant-lexicon-pulumi, pulumiMemberEngine) and
|
|
6
|
+
# runs `plunge preview`, `plunge drift` and `plunge stack output` for it.
|
|
7
|
+
name: three-cloud-aws
|
|
8
|
+
description: The three-cloud demo's AWS site, ECS on Fargate behind a load balancer, on the floci emulator
|
|
9
|
+
runtime:
|
|
10
|
+
name: nodejs
|
|
11
|
+
options:
|
|
12
|
+
typescript: true
|
|
13
|
+
packagemanager: npm
|
|
14
|
+
backend:
|
|
15
|
+
url: plunge+file://./.plunge
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
// The three-cloud demo's aws member (INTENTIUS/behold#1000): the website on
|
|
2
|
+
// ECS Fargate in us-east-1, behind its own load balancer, as a Pulumi program
|
|
3
|
+
// that plunge runs. The ALB's DNS name is the stable hostname Route 53 points
|
|
4
|
+
// at, published as the stack output `awsEndpoint`, which the dns member reads
|
|
5
|
+
// through chant (memberOutputsComponent("aws"), stackOutput("aws",
|
|
6
|
+
// "awsEndpoint")).
|
|
7
|
+
//
|
|
8
|
+
// The resources are the ones the chant aws member declared before this
|
|
9
|
+
// program replaced it: the aws lexicon's VpcDefault (a VPC across two zones,
|
|
10
|
+
// public subnets for the load balancer, private ones for the tasks, a NAT
|
|
11
|
+
// gateway they reach out through) and FargateAlb (cluster, roles, log group,
|
|
12
|
+
// task definition, security groups, load balancer, target group, listener,
|
|
13
|
+
// service), with the same arguments. Logical names are the chant member's
|
|
14
|
+
// entity names in kebab case.
|
|
15
|
+
//
|
|
16
|
+
// Every call goes to floci. The provider is explicit, every resource and
|
|
17
|
+
// invoke names it, and its endpoint is AWS_ENDPOINT_URL (default
|
|
18
|
+
// http://localhost:4566), refused unless it is on this machine. The key pair
|
|
19
|
+
// is floci's fake one and the skip flags stop the provider calling STS or the
|
|
20
|
+
// metadata service, as the plunge corpus's stacks do
|
|
21
|
+
// (plunge tests/plunge-corpus/aws-ts).
|
|
22
|
+
import * as pulumi from "@pulumi/pulumi";
|
|
23
|
+
import * as aws from "@pulumi/aws";
|
|
24
|
+
|
|
25
|
+
const endpoint = process.env.AWS_ENDPOINT_URL ?? "http://localhost:4566";
|
|
26
|
+
const host = new URL(endpoint).hostname;
|
|
27
|
+
if (!["localhost", "127.0.0.1", "::1", "[::1]"].includes(host)) {
|
|
28
|
+
throw new Error(`three-cloud-aws runs only against an emulator on this machine; AWS_ENDPOINT_URL names ${endpoint}`);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const floci = new aws.Provider("floci", {
|
|
32
|
+
region: "us-east-1",
|
|
33
|
+
accessKey: "test",
|
|
34
|
+
secretKey: "test",
|
|
35
|
+
skipCredentialsValidation: true,
|
|
36
|
+
skipRequestingAccountId: true,
|
|
37
|
+
skipRegionValidation: true,
|
|
38
|
+
skipMetadataApiCheck: true,
|
|
39
|
+
endpoints: [{
|
|
40
|
+
ec2: endpoint,
|
|
41
|
+
ecs: endpoint,
|
|
42
|
+
elbv2: endpoint,
|
|
43
|
+
iam: endpoint,
|
|
44
|
+
logs: endpoint,
|
|
45
|
+
sts: endpoint,
|
|
46
|
+
}],
|
|
47
|
+
});
|
|
48
|
+
const opts = { provider: floci };
|
|
49
|
+
|
|
50
|
+
// ── the network (VpcDefault) ────────────────────────────────────────────────
|
|
51
|
+
|
|
52
|
+
const zones = aws.getAvailabilityZonesOutput({ state: "available" }, opts);
|
|
53
|
+
const az1 = zones.names[0];
|
|
54
|
+
const az2 = zones.names[1];
|
|
55
|
+
|
|
56
|
+
const vpc = new aws.ec2.Vpc("network-vpc", { cidrBlock: "10.20.0.0/16", enableDnsSupport: true, enableDnsHostnames: true }, opts);
|
|
57
|
+
const igw = new aws.ec2.InternetGateway("network-igw", {}, opts);
|
|
58
|
+
const igwAttachment = new aws.ec2.InternetGatewayAttachment("network-igw-attachment", { vpcId: vpc.id, internetGatewayId: igw.id }, opts);
|
|
59
|
+
|
|
60
|
+
const publicSubnet1 = new aws.ec2.Subnet("network-public-subnet-1", { vpcId: vpc.id, cidrBlock: "10.20.0.0/24", availabilityZone: az1, mapPublicIpOnLaunch: true }, opts);
|
|
61
|
+
const publicSubnet2 = new aws.ec2.Subnet("network-public-subnet-2", { vpcId: vpc.id, cidrBlock: "10.20.1.0/24", availabilityZone: az2, mapPublicIpOnLaunch: true }, opts);
|
|
62
|
+
const privateSubnet1 = new aws.ec2.Subnet("network-private-subnet-1", { vpcId: vpc.id, cidrBlock: "10.20.10.0/24", availabilityZone: az1 }, opts);
|
|
63
|
+
const privateSubnet2 = new aws.ec2.Subnet("network-private-subnet-2", { vpcId: vpc.id, cidrBlock: "10.20.11.0/24", availabilityZone: az2 }, opts);
|
|
64
|
+
|
|
65
|
+
const publicRouteTable = new aws.ec2.RouteTable("network-public-route-table", { vpcId: vpc.id }, opts);
|
|
66
|
+
new aws.ec2.Route("network-public-route", { routeTableId: publicRouteTable.id, destinationCidrBlock: "0.0.0.0/0", gatewayId: igw.id }, { ...opts, dependsOn: [igwAttachment] });
|
|
67
|
+
new aws.ec2.RouteTableAssociation("network-public-rta-1", { subnetId: publicSubnet1.id, routeTableId: publicRouteTable.id }, opts);
|
|
68
|
+
new aws.ec2.RouteTableAssociation("network-public-rta-2", { subnetId: publicSubnet2.id, routeTableId: publicRouteTable.id }, opts);
|
|
69
|
+
|
|
70
|
+
const natEip = new aws.ec2.Eip("network-nat-eip", { domain: "vpc" }, opts);
|
|
71
|
+
const natGateway = new aws.ec2.NatGateway("network-nat-gateway", { allocationId: natEip.id, subnetId: publicSubnet1.id }, opts);
|
|
72
|
+
|
|
73
|
+
const privateRouteTable = new aws.ec2.RouteTable("network-private-route-table", { vpcId: vpc.id }, opts);
|
|
74
|
+
new aws.ec2.Route("network-private-route", { routeTableId: privateRouteTable.id, destinationCidrBlock: "0.0.0.0/0", natGatewayId: natGateway.id }, opts);
|
|
75
|
+
new aws.ec2.RouteTableAssociation("network-private-rta-1", { subnetId: privateSubnet1.id, routeTableId: privateRouteTable.id }, opts);
|
|
76
|
+
new aws.ec2.RouteTableAssociation("network-private-rta-2", { subnetId: privateSubnet2.id, routeTableId: privateRouteTable.id }, opts);
|
|
77
|
+
|
|
78
|
+
// ── the website (FargateAlb) ────────────────────────────────────────────────
|
|
79
|
+
|
|
80
|
+
const containerPort = 80;
|
|
81
|
+
const ecsTrustPolicy = JSON.stringify({
|
|
82
|
+
Version: "2012-10-17",
|
|
83
|
+
Statement: [{ Effect: "Allow", Principal: { Service: "ecs-tasks.amazonaws.com" }, Action: "sts:AssumeRole" }],
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
const cluster = new aws.ecs.Cluster("web-cluster", {}, opts);
|
|
87
|
+
|
|
88
|
+
// Execution role: ECR pull and CloudWatch Logs write.
|
|
89
|
+
const executionRole = new aws.iam.Role("web-execution-role", {
|
|
90
|
+
assumeRolePolicy: ecsTrustPolicy,
|
|
91
|
+
inlinePolicies: [{
|
|
92
|
+
name: "ExecutionPolicy",
|
|
93
|
+
policy: JSON.stringify({
|
|
94
|
+
Version: "2012-10-17",
|
|
95
|
+
Statement: [
|
|
96
|
+
{ Effect: "Allow", Action: ["ecr:GetAuthorizationToken", "ecr:BatchCheckLayerAvailability", "ecr:GetDownloadUrlForLayer", "ecr:BatchGetImage"], Resource: "*" },
|
|
97
|
+
{ Effect: "Allow", Action: ["logs:CreateLogStream", "logs:PutLogEvents"], Resource: "*" },
|
|
98
|
+
],
|
|
99
|
+
}),
|
|
100
|
+
}],
|
|
101
|
+
}, opts);
|
|
102
|
+
|
|
103
|
+
// Task role: the app's own permissions, none here.
|
|
104
|
+
const taskRole = new aws.iam.Role("web-task-role", { assumeRolePolicy: ecsTrustPolicy }, opts);
|
|
105
|
+
|
|
106
|
+
// Named, so an out-of-band edit (scripts/front-door.ts oob-edit aws) can find it.
|
|
107
|
+
const logGroup = new aws.cloudwatch.LogGroup("web-log-group", { name: "/ecs/three-cloud-aws-web", retentionInDays: 7 }, opts);
|
|
108
|
+
|
|
109
|
+
const taskDef = new aws.ecs.TaskDefinition("web-task-def", {
|
|
110
|
+
family: "three-cloud-aws-web",
|
|
111
|
+
networkMode: "awsvpc",
|
|
112
|
+
requiresCompatibilities: ["FARGATE"],
|
|
113
|
+
cpu: "256",
|
|
114
|
+
memory: "512",
|
|
115
|
+
executionRoleArn: executionRole.arn,
|
|
116
|
+
taskRoleArn: taskRole.arn,
|
|
117
|
+
containerDefinitions: pulumi.jsonStringify([{
|
|
118
|
+
name: "app",
|
|
119
|
+
image: "traefik/whoami:v1.10",
|
|
120
|
+
essential: true,
|
|
121
|
+
portMappings: [{ containerPort, protocol: "tcp" }],
|
|
122
|
+
logConfiguration: {
|
|
123
|
+
logDriver: "awslogs",
|
|
124
|
+
options: { "awslogs-group": logGroup.name, "awslogs-region": "us-east-1", "awslogs-stream-prefix": "ecs" },
|
|
125
|
+
},
|
|
126
|
+
}]),
|
|
127
|
+
}, opts);
|
|
128
|
+
|
|
129
|
+
const albSg = new aws.ec2.SecurityGroup("web-alb-sg", {
|
|
130
|
+
description: "ALB security group",
|
|
131
|
+
vpcId: vpc.id,
|
|
132
|
+
ingress: [{ protocol: "tcp", fromPort: 80, toPort: 80, cidrBlocks: ["0.0.0.0/0"] }],
|
|
133
|
+
}, opts);
|
|
134
|
+
|
|
135
|
+
const taskSg = new aws.ec2.SecurityGroup("web-task-sg", {
|
|
136
|
+
description: "Fargate task security group",
|
|
137
|
+
vpcId: vpc.id,
|
|
138
|
+
ingress: [{ protocol: "tcp", fromPort: containerPort, toPort: containerPort, securityGroups: [albSg.id] }],
|
|
139
|
+
}, opts);
|
|
140
|
+
|
|
141
|
+
const alb = new aws.lb.LoadBalancer("web-alb", {
|
|
142
|
+
loadBalancerType: "application",
|
|
143
|
+
internal: false,
|
|
144
|
+
subnets: [publicSubnet1.id, publicSubnet2.id],
|
|
145
|
+
securityGroups: [albSg.id],
|
|
146
|
+
}, opts);
|
|
147
|
+
|
|
148
|
+
const targetGroup = new aws.lb.TargetGroup("web-target-group", {
|
|
149
|
+
targetType: "ip",
|
|
150
|
+
protocol: "HTTP",
|
|
151
|
+
port: containerPort,
|
|
152
|
+
vpcId: vpc.id,
|
|
153
|
+
healthCheck: { path: "/" },
|
|
154
|
+
}, opts);
|
|
155
|
+
|
|
156
|
+
const listener = new aws.lb.Listener("web-listener", {
|
|
157
|
+
loadBalancerArn: alb.arn,
|
|
158
|
+
port: 80,
|
|
159
|
+
protocol: "HTTP",
|
|
160
|
+
defaultActions: [{ type: "forward", targetGroupArn: targetGroup.arn }],
|
|
161
|
+
}, opts);
|
|
162
|
+
|
|
163
|
+
new aws.ecs.Service("web-service", {
|
|
164
|
+
cluster: cluster.arn,
|
|
165
|
+
taskDefinition: taskDef.arn,
|
|
166
|
+
launchType: "FARGATE",
|
|
167
|
+
desiredCount: 1,
|
|
168
|
+
healthCheckGracePeriodSeconds: 60,
|
|
169
|
+
loadBalancers: [{ containerName: "app", containerPort, targetGroupArn: targetGroup.arn }],
|
|
170
|
+
networkConfiguration: { subnets: [privateSubnet1.id, privateSubnet2.id], securityGroups: [taskSg.id], assignPublicIp: false },
|
|
171
|
+
}, { ...opts, dependsOn: [listener] });
|
|
172
|
+
|
|
173
|
+
// The dns member reads this as its `awsEndpoint` parameter.
|
|
174
|
+
export const awsEndpoint = alb.dnsName;
|