@intentius/chant-lexicon-pulumi 0.124.101 → 0.124.103

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.
Files changed (71) hide show
  1. package/dist/change-set.d.ts +5 -0
  2. package/dist/change-set.js +4 -0
  3. package/dist/chant-floors.d.ts +36 -0
  4. package/dist/chant-floors.js +36 -0
  5. package/dist/cost-hold.d.ts +45 -0
  6. package/dist/cost-hold.js +49 -0
  7. package/dist/describe-resources.d.ts +10 -0
  8. package/dist/describe-resources.js +79 -3
  9. package/dist/disruption.d.ts +50 -0
  10. package/dist/disruption.js +104 -0
  11. package/dist/engine-graph.d.ts +1 -1
  12. package/dist/engine-graph.js +40 -1
  13. package/dist/health-targets.d.ts +25 -0
  14. package/dist/health-targets.js +57 -0
  15. package/dist/index.d.ts +7 -0
  16. package/dist/index.js +8 -0
  17. package/dist/integrity.json +18 -18
  18. package/dist/lint/post-synth/member-read-helpers.d.ts +1 -1
  19. package/dist/lint/post-synth/member-read-helpers.js +1 -1
  20. package/dist/lint/post-synth/pul001.js +1 -1
  21. package/dist/lint/post-synth/pul002.js +1 -1
  22. package/dist/lint/post-synth/pul003.js +1 -1
  23. package/dist/lint/post-synth/pul004.js +1 -1
  24. package/dist/lint/post-synth/pul005.js +1 -1
  25. package/dist/lint/post-synth/pul006.js +1 -1
  26. package/dist/lint/post-synth/pul007.js +1 -1
  27. package/dist/lint/post-synth/pul008.js +1 -1
  28. package/dist/lint/post-synth/pul009.js +1 -1
  29. package/dist/lint/post-synth/pul010.js +1 -1
  30. package/dist/lint/post-synth/pul011.js +1 -1
  31. package/dist/lint/post-synth/pul012.js +1 -1
  32. package/dist/lint/post-synth/pul013.js +1 -1
  33. package/dist/lint/post-synth/pul014.js +1 -1
  34. package/dist/lint/post-synth/pul015.js +1 -1
  35. package/dist/manifest.json +1 -1
  36. package/dist/member-outputs.js +1 -1
  37. package/dist/member-report.d.ts +32 -0
  38. package/dist/member-report.js +23 -0
  39. package/dist/plugin.js +35 -2
  40. package/dist/preview-observation.d.ts +97 -0
  41. package/dist/preview-observation.js +218 -0
  42. package/dist/pulumi-up.d.ts +44 -3
  43. package/dist/pulumi-up.js +71 -11
  44. package/dist/reference-catalog.d.ts +84 -0
  45. package/dist/reference-catalog.js +383 -0
  46. package/dist/reference-props.d.ts +19 -0
  47. package/dist/reference-props.js +93 -0
  48. package/dist/rules/member-read-helpers.ts +1 -1
  49. package/dist/rules/pul001.ts +1 -1
  50. package/dist/rules/pul002.ts +1 -1
  51. package/dist/rules/pul003.ts +1 -1
  52. package/dist/rules/pul004.ts +1 -1
  53. package/dist/rules/pul005.ts +1 -1
  54. package/dist/rules/pul006.ts +1 -1
  55. package/dist/rules/pul007.ts +1 -1
  56. package/dist/rules/pul008.ts +1 -1
  57. package/dist/rules/pul009.ts +1 -1
  58. package/dist/rules/pul010.ts +1 -1
  59. package/dist/rules/pul011.ts +1 -1
  60. package/dist/rules/pul012.ts +1 -1
  61. package/dist/rules/pul013.ts +1 -1
  62. package/dist/rules/pul014.ts +1 -1
  63. package/dist/rules/pul015.ts +1 -1
  64. package/dist/run.js +1 -1
  65. package/dist/stack-export-snapshot.js +1 -1
  66. package/dist/stack-references.js +6 -1
  67. package/dist/workspace-member.d.ts +1 -26
  68. package/dist/workspace-member.js +11 -21
  69. package/dist/workspace-stack-reads.d.ts +12 -0
  70. package/dist/workspace-stack-reads.js +60 -0
  71. package/package.json +3 -3
@@ -0,0 +1,383 @@
1
+ /**
2
+ * How the resources of a Pulumi stack name each other, as a `ReferenceCatalog`
3
+ * over the aws, gcp, azure and kubernetes providers (#5330).
4
+ *
5
+ * `chant workspace graph` runs each lexicon's catalog over the composed
6
+ * nodes (`packages/core/src/workspace/catalog-edges.ts`), and behold keeps
7
+ * its own name matcher for a lexicon that has none. This is the pulumi
8
+ * lexicon's, shaped like the terraform lexicon's
9
+ * (`../../terraform/src/behaviour/reference-catalog.ts`): rules grouped by
10
+ * the relation they produce, a short list of kinds known to reference
11
+ * nothing, and `identities` for what else names a kind.
12
+ *
13
+ * ## Shape
14
+ *
15
+ * A node's kind is the Pulumi type token (`aws:ec2/subnet:Subnet`), which is
16
+ * what the member read gives it (`./workspace-member.ts`). Its attrs are the
17
+ * resource's inputs as the stack export records them, in Pulumi's camelCase
18
+ * (`vpcId`, `networkConfiguration.subnets[]`), plus an `outputs` object
19
+ * holding its `id` and top-level string outputs (`outputs.arn`,
20
+ * `outputs.selfLink`), from `./reference-props.ts`. An export holds resolved
21
+ * values, so a reference reads as the physical id, ARN or name of its
22
+ * target, and the rules match that against the target's identities.
23
+ *
24
+ * ## Ids, ARNs and names
25
+ *
26
+ * Every target is identified by `outputs.id`, `outputs.arn`, `outputs.name`
27
+ * and the `name` input, with the extra names its provider uses
28
+ * ({@link EXTRA_IDS}): a bucket's `bucket`, a service account's `accountId`
29
+ * and `email`, a Kubernetes object's `metadata.name`. A rule names the kind
30
+ * it expects, so a name that two kinds share joins neither to the wrong one.
31
+ *
32
+ * ## Targets in other members
33
+ *
34
+ * A reference can name a resource that another member declares. The
35
+ * terraform lexicon identifies a few kinds by name (`aws_iam_role`,
36
+ * `aws_eks_cluster`, `aws_secretsmanager_secret`, `google_service_account`,
37
+ * `google_container_cluster`, `google_secret_manager_secret`,
38
+ * `azurerm_kubernetes_cluster`), and the k8s lexicon identifies its objects
39
+ * by `metadata.name`. A rule toward one of those has a second rule for the
40
+ * other lexicon's kind, under the same id, so a value that names a node of
41
+ * either is found and the other is not reported as missing. A Terraform
42
+ * block that names no identity (a VPC's id before it is applied) is not
43
+ * reachable by value; the edge appears once the id is on the node.
44
+ *
45
+ * ## Kubernetes
46
+ *
47
+ * A name is unique only inside its namespace. The namespaced kinds are
48
+ * `scopes` on `metadata.namespace`, and a pod spec's references to a service
49
+ * account, a ConfigMap or a Secret are `join` rules that look the name up in
50
+ * the holder's namespace across members, so a Deployment in this lexicon
51
+ * reaches a ServiceAccount of the k8s lexicon in the same namespace. A
52
+ * namespaced object also has an `in namespace` containment toward its
53
+ * `Namespace`, optional because most namespaces are created elsewhere.
54
+ *
55
+ * ## What "no rule" means
56
+ *
57
+ * A kind with no rule produces no edges. {@link REFERENCES_NOTHING} lists
58
+ * kinds looked at and found to hold no argument that identifies another
59
+ * resource, so {@link isUnresolvedKind} separates "nobody wrote a rule" from
60
+ * "there is nothing to find".
61
+ *
62
+ * ## Adding a rule
63
+ *
64
+ * A rule is one call to `rule` in the list for its provider: holder kind,
65
+ * input path, target kind or kinds, label. A target kind that others name
66
+ * goes in {@link EXTRA_IDS} or {@link NAMED_KINDS}. The test "each rule draws
67
+ * its edge" covers a new rule with no test of its own.
68
+ */
69
+ import { readPath } from "@intentius/chant/graph-refs";
70
+ /** Terraform kinds the terraform lexicon identifies by name, keyed by the Pulumi kind that is the same resource. */
71
+ const TERRAFORM_ALIAS = {
72
+ "aws:iam/role:Role": "aws_iam_role",
73
+ "aws:eks/cluster:Cluster": "aws_eks_cluster",
74
+ "aws:secretsmanager/secret:Secret": "aws_secretsmanager_secret",
75
+ "gcp:serviceaccount/account:Account": "google_service_account",
76
+ "gcp:container/cluster:Cluster": "google_container_cluster",
77
+ "gcp:secretmanager/secret:Secret": "google_secret_manager_secret",
78
+ "azure:containerservice/kubernetesCluster:KubernetesCluster": "azurerm_kubernetes_cluster",
79
+ };
80
+ /** The k8s lexicon's kind for a Pulumi Kubernetes kind. */
81
+ const K8S_ALIAS = {
82
+ "kubernetes:core/v1:Namespace": "K8s::Core::Namespace",
83
+ "kubernetes:core/v1:ServiceAccount": "K8s::Core::ServiceAccount",
84
+ "kubernetes:core/v1:ConfigMap": "K8s::Core::ConfigMap",
85
+ "kubernetes:core/v1:Secret": "K8s::Core::Secret",
86
+ };
87
+ /** A Pulumi kind and the kinds of other lexicons that stand for the same resource, the Pulumi kind last: a missing target is reported under the last rule of its id. */
88
+ const targets = (kind) => [...[TERRAFORM_ALIAS[kind], K8S_ALIAS[kind]].filter((k) => k !== undefined), kind];
89
+ const rule = (from, path, target, label, relation = "reference", viaAttr) => targets(target).map((targetKind) => ({ from, path, targetKind, relation, label, ...(viaAttr ? { viaAttr } : {}) }));
90
+ const containment = (from, path, target, label, viaAttr) => rule(from, path, target, label, "containment", viaAttr);
91
+ /** `rule` for a value that names no node most of the time (an env var, a free-form name). */
92
+ const maybe = (from, path, target, label) => rule(from, path, target, label).map((r) => ({ ...r, optional: true }));
93
+ // ── aws ──
94
+ const EC2 = (t) => `aws:ec2/${t[0].toLowerCase()}${t.slice(1)}:${t}`;
95
+ const VPC = EC2("Vpc");
96
+ const SUBNET = EC2("Subnet");
97
+ const SECURITY_GROUP = EC2("SecurityGroup");
98
+ const ROUTE_TABLE = EC2("RouteTable");
99
+ const INTERNET_GATEWAY = EC2("InternetGateway");
100
+ const NAT_GATEWAY = EC2("NatGateway");
101
+ const EIP = EC2("Eip");
102
+ const INSTANCE = EC2("Instance");
103
+ const NETWORK_INTERFACE = EC2("NetworkInterface");
104
+ const LB = "aws:lb/loadBalancer:LoadBalancer";
105
+ const TARGET_GROUP = "aws:lb/targetGroup:TargetGroup";
106
+ const ECS_CLUSTER = "aws:ecs/cluster:Cluster";
107
+ const ECS_TASK = "aws:ecs/taskDefinition:TaskDefinition";
108
+ const IAM_ROLE = "aws:iam/role:Role";
109
+ const IAM_POLICY = "aws:iam/policy:Policy";
110
+ const INSTANCE_PROFILE = "aws:iam/instanceProfile:InstanceProfile";
111
+ const LAMBDA = "aws:lambda/function:Function";
112
+ const S3_BUCKET = "aws:s3/bucket:Bucket";
113
+ const S3_BUCKET_V2 = "aws:s3/bucketV2:BucketV2";
114
+ const ROUTE53_ZONE = "aws:route53/zone:Zone";
115
+ const EKS_CLUSTER = "aws:eks/cluster:Cluster";
116
+ const RDS_SUBNET_GROUP = "aws:rds/subnetGroup:SubnetGroup";
117
+ const RDS_CLUSTER = "aws:rds/cluster:Cluster";
118
+ const SQS_QUEUE = "aws:sqs/queue:Queue";
119
+ const SNS_TOPIC = "aws:sns/topic:Topic";
120
+ const KMS_KEY = "aws:kms/key:Key";
121
+ const LOG_GROUP = "aws:cloudwatch/logGroup:LogGroup";
122
+ /** A bucket is `Bucket` or `BucketV2`; a rule toward one has the same rule toward the other. */
123
+ const bucketRules = (from, path, label, relation = "reference") => [S3_BUCKET, S3_BUCKET_V2].flatMap((b) => rule(from, path, b, label, relation));
124
+ const awsRules = [
125
+ // containment
126
+ ...[SUBNET, SECURITY_GROUP, ROUTE_TABLE, INTERNET_GATEWAY, "aws:lb/targetGroup:TargetGroup", "aws:ec2/vpcEndpoint:VpcEndpoint"].flatMap((k) => containment(k, "vpcId", VPC, "in VPC")),
127
+ ...containment(INSTANCE, "subnetId", SUBNET, "in subnet", "subnetId"),
128
+ ...[NAT_GATEWAY, NETWORK_INTERFACE].flatMap((k) => containment(k, "subnetId", SUBNET, "in subnet")),
129
+ ...[LB, "aws:rds/subnetGroup:SubnetGroup", "aws:elasticache/subnetGroup:SubnetGroup", "aws:eks/nodeGroup:NodeGroup"].flatMap((k) => containment(k, k === LB ? "subnets[]" : "subnetIds[]", SUBNET, "in subnet")),
130
+ ...containment(LAMBDA, "vpcConfig.subnetIds[]", SUBNET, "in subnet"),
131
+ ...containment("aws:ecs/service:Service", "networkConfiguration.subnets[]", SUBNET, "in subnet"),
132
+ ...containment(EKS_CLUSTER, "vpcConfig.subnetIds[]", SUBNET, "in subnet"),
133
+ ...[RDS_CLUSTER, "aws:rds/instance:Instance"].flatMap((k) => containment(k, "dbSubnetGroupName", RDS_SUBNET_GROUP, "in subnet group")),
134
+ // references
135
+ ...rule(INSTANCE, "vpcSecurityGroupIds[]", SECURITY_GROUP, "sg", "reference", "vpcSecurityGroupIds"),
136
+ ...rule(INSTANCE, "iamInstanceProfile", INSTANCE_PROFILE, "as"),
137
+ ...[NETWORK_INTERFACE, LB].flatMap((k) => rule(k, "securityGroups[]", SECURITY_GROUP, "sg")),
138
+ ...rule(LAMBDA, "vpcConfig.securityGroupIds[]", SECURITY_GROUP, "sg"),
139
+ ...[RDS_CLUSTER, "aws:rds/instance:Instance"].flatMap((k) => rule(k, "vpcSecurityGroupIds[]", SECURITY_GROUP, "sg")),
140
+ ...rule("aws:ecs/service:Service", "networkConfiguration.securityGroups[]", SECURITY_GROUP, "sg"),
141
+ ...rule("aws:ec2/securityGroupRule:SecurityGroupRule", "securityGroupId", SECURITY_GROUP, "rule on", "reference", "securityGroupId"),
142
+ ...rule("aws:ec2/securityGroupRule:SecurityGroupRule", "sourceSecurityGroupId", SECURITY_GROUP, "allows"),
143
+ ...rule("aws:lb/listener:Listener", "loadBalancerArn", LB, "on"),
144
+ ...rule("aws:lb/listener:Listener", "defaultActions[].targetGroupArn", TARGET_GROUP, "forwards to"),
145
+ ...rule("aws:lb/targetGroupAttachment:TargetGroupAttachment", "targetGroupArn", TARGET_GROUP, "in group"),
146
+ ...[INSTANCE, LAMBDA].flatMap((k) => maybe("aws:lb/targetGroupAttachment:TargetGroupAttachment", "targetId", k, "targets")),
147
+ ...rule("aws:ec2/route:Route", "routeTableId", ROUTE_TABLE, "in table", "reference", "routeTableId"),
148
+ ...rule("aws:ec2/route:Route", "gatewayId", INTERNET_GATEWAY, "via", "reference", "gatewayId"),
149
+ ...rule("aws:ec2/route:Route", "natGatewayId", NAT_GATEWAY, "via"),
150
+ ...rule("aws:ec2/routeTableAssociation:RouteTableAssociation", "subnetId", SUBNET, "associates", "reference", "subnetId"),
151
+ ...rule("aws:ec2/routeTableAssociation:RouteTableAssociation", "routeTableId", ROUTE_TABLE, "to table", "reference", "routeTableId"),
152
+ ...rule("aws:ec2/internetGatewayAttachment:InternetGatewayAttachment", "internetGatewayId", INTERNET_GATEWAY, "attaches"),
153
+ ...rule("aws:ec2/internetGatewayAttachment:InternetGatewayAttachment", "vpcId", VPC, "to VPC"),
154
+ ...rule(NAT_GATEWAY, "allocationId", EIP, "uses"),
155
+ ...rule("aws:ecs/service:Service", "cluster", ECS_CLUSTER, "in cluster"),
156
+ ...rule("aws:ecs/service:Service", "taskDefinition", ECS_TASK, "runs"),
157
+ ...rule("aws:ecs/service:Service", "loadBalancers[].targetGroupArn", TARGET_GROUP, "registered in"),
158
+ ...["executionRoleArn", "taskRoleArn"].flatMap((p) => rule(ECS_TASK, p, IAM_ROLE, "as")),
159
+ ...rule(LAMBDA, "role", IAM_ROLE, "as"),
160
+ ...rule(EKS_CLUSTER, "roleArn", IAM_ROLE, "as"),
161
+ ...rule("aws:eks/nodeGroup:NodeGroup", "clusterName", EKS_CLUSTER, "in cluster"),
162
+ ...rule("aws:eks/nodeGroup:NodeGroup", "nodeRoleArn", IAM_ROLE, "as"),
163
+ ...rule("aws:iam/rolePolicyAttachment:RolePolicyAttachment", "role", IAM_ROLE, "on"),
164
+ ...rule("aws:iam/rolePolicyAttachment:RolePolicyAttachment", "policyArn", IAM_POLICY, "attaches"),
165
+ ...rule("aws:iam/rolePolicy:RolePolicy", "role", IAM_ROLE, "on"),
166
+ ...rule(INSTANCE_PROFILE, "role", IAM_ROLE, "holds"),
167
+ ...["aws:s3/bucketPolicy:BucketPolicy", "aws:s3/bucketAclV2:BucketAclV2", "aws:s3/bucketVersioningV2:BucketVersioningV2", "aws:s3/bucketPublicAccessBlock:BucketPublicAccessBlock", "aws:s3/bucketServerSideEncryptionConfigurationV2:BucketServerSideEncryptionConfigurationV2", "aws:s3/bucketOwnershipControls:BucketOwnershipControls"].flatMap((k) => bucketRules(k, "bucket", "setting on")),
168
+ ...rule("aws:sqs/queuePolicy:QueuePolicy", "queueUrl", SQS_QUEUE, "grant on"),
169
+ ...rule("aws:sns/topicSubscription:TopicSubscription", "topic", SNS_TOPIC, "on"),
170
+ ...[LOG_GROUP, SNS_TOPIC].flatMap((k) => rule(k, k === LOG_GROUP ? "kmsKeyId" : "kmsMasterKeyId", KMS_KEY, "encrypted with")),
171
+ ...rule("aws:route53/record:Record", "zoneId", ROUTE53_ZONE, "in zone"),
172
+ ...rule("aws:secretsmanager/secretVersion:SecretVersion", "secretId", "aws:secretsmanager/secret:Secret", "version of"),
173
+ ...rule("aws:lambda/permission:Permission", "function", LAMBDA, "grant on"),
174
+ ...rule("aws:lambda/eventSourceMapping:EventSourceMapping", "functionName", LAMBDA, "invokes"),
175
+ ...rule("aws:lambda/eventSourceMapping:EventSourceMapping", "eventSourceArn", SQS_QUEUE, "drains"),
176
+ // A bucket's regional domain name or a load balancer's DNS name; no target kind.
177
+ { from: "aws:cloudfront/distribution:Distribution", path: "origins[].domainName", relation: "reference", label: "origin" },
178
+ ];
179
+ // ── gcp ──
180
+ const GCP_NETWORK = "gcp:compute/network:Network";
181
+ const GCP_SUBNETWORK = "gcp:compute/subnetwork:Subnetwork";
182
+ const GCP_INSTANCE = "gcp:compute/instance:Instance";
183
+ const GCP_CLUSTER = "gcp:container/cluster:Cluster";
184
+ const GCP_SERVICE_ACCOUNT = "gcp:serviceaccount/account:Account";
185
+ const GCP_SECRET = "gcp:secretmanager/secret:Secret";
186
+ const GCP_BUCKET = "gcp:storage/bucket:Bucket";
187
+ const gcpRules = [
188
+ ...containment(GCP_SUBNETWORK, "network", GCP_NETWORK, "in network"),
189
+ ...containment(GCP_INSTANCE, "networkInterfaces[].subnetwork", GCP_SUBNETWORK, "in subnet"),
190
+ ...rule(GCP_INSTANCE, "networkInterfaces[].network", GCP_NETWORK, "on network"),
191
+ ...rule(GCP_INSTANCE, "serviceAccount.email", GCP_SERVICE_ACCOUNT, "as"),
192
+ ...rule(GCP_CLUSTER, "network", GCP_NETWORK, "on network"),
193
+ ...containment(GCP_CLUSTER, "subnetwork", GCP_SUBNETWORK, "in subnet"),
194
+ ...rule("gcp:container/nodePool:NodePool", "cluster", GCP_CLUSTER, "in cluster"),
195
+ ...rule("gcp:container/nodePool:NodePool", "nodeConfig.serviceAccount", GCP_SERVICE_ACCOUNT, "as"),
196
+ ...rule("gcp:compute/firewall:Firewall", "network", GCP_NETWORK, "on network"),
197
+ ...rule("gcp:compute/router:Router", "network", GCP_NETWORK, "on network"),
198
+ ...rule("gcp:secretmanager/secretVersion:SecretVersion", "secret", GCP_SECRET, "version of"),
199
+ ...rule("gcp:secretmanager/secretIamMember:SecretIamMember", "secretId", GCP_SECRET, "grant on"),
200
+ ...rule("gcp:storage/bucketIAMMember:BucketIAMMember", "bucket", GCP_BUCKET, "grant on"),
201
+ ...rule("gcp:storage/bucketIAMBinding:BucketIAMBinding", "bucket", GCP_BUCKET, "grant on"),
202
+ ...rule("gcp:storage/bucketObject:BucketObject", "bucket", GCP_BUCKET, "in bucket"),
203
+ ...rule("gcp:serviceaccount/iAMMember:IAMMember", "serviceAccountId", GCP_SERVICE_ACCOUNT, "grant on"),
204
+ ...rule("gcp:serviceaccount/key:Key", "serviceAccountId", GCP_SERVICE_ACCOUNT, "key of"),
205
+ ];
206
+ const AZURE_NATIVE = {
207
+ group: "azure-native:resources:ResourceGroup",
208
+ vnet: "azure-native:network:VirtualNetwork",
209
+ subnet: "azure-native:network:Subnet",
210
+ aks: "azure-native:containerservice:ManagedCluster",
211
+ nic: "azure-native:network:NetworkInterface",
212
+ nsg: "azure-native:network:NetworkSecurityGroup",
213
+ inGroup: ["azure-native:storage:StorageAccount", "azure-native:keyvault:Vault", "azure-native:network:PublicIPAddress", "azure-native:compute:VirtualMachine", "azure-native:web:WebApp", "azure-native:app:ContainerApp", "azure-native:app:ManagedEnvironment", "azure-native:containerregistry:Registry"],
214
+ subnetVnet: "virtualNetworkName",
215
+ aksSubnet: "agentPoolProfiles[].vnetSubnetID",
216
+ nicSubnet: "ipConfigurations[].subnet.id",
217
+ nicNsg: "networkSecurityGroup.id",
218
+ };
219
+ const AZURE_CLASSIC = {
220
+ group: "azure:core/resourceGroup:ResourceGroup",
221
+ vnet: "azure:network/virtualNetwork:VirtualNetwork",
222
+ subnet: "azure:network/subnet:Subnet",
223
+ aks: "azure:containerservice/kubernetesCluster:KubernetesCluster",
224
+ nic: "azure:network/networkInterface:NetworkInterface",
225
+ nsg: "azure:network/networkSecurityGroup:NetworkSecurityGroup",
226
+ inGroup: ["azure:storage/account:Account", "azure:keyvault/keyVault:KeyVault", "azure:network/publicIp:PublicIp", "azure:compute/linuxVirtualMachine:LinuxVirtualMachine", "azure:containerservice/registry:Registry"],
227
+ subnetVnet: "virtualNetworkName",
228
+ aksSubnet: "defaultNodePool.vnetSubnetId",
229
+ nicSubnet: "ipConfigurations[].subnetId",
230
+ nicNsg: "networkSecurityGroupId",
231
+ };
232
+ const AZURE_FAMILIES = [AZURE_NATIVE, AZURE_CLASSIC];
233
+ function azureRulesOf(f) {
234
+ return [
235
+ // Both providers name the group by `resourceGroupName`.
236
+ ...[f.vnet, f.subnet, f.aks, f.nic, f.nsg, ...f.inGroup].flatMap((k) => containment(k, "resourceGroupName", f.group, "in resource group")),
237
+ ...containment(f.subnet, f.subnetVnet, f.vnet, "in VNet"),
238
+ ...containment(f.aks, f.aksSubnet, f.subnet, "in subnet"),
239
+ ...containment(f.nic, f.nicSubnet, f.subnet, "in subnet"),
240
+ ...rule(f.nic, f.nicNsg, f.nsg, "sg"),
241
+ ];
242
+ }
243
+ const azureRules = AZURE_FAMILIES.flatMap(azureRulesOf);
244
+ // ── kubernetes ──
245
+ /** Workload kinds and the path to their pod spec. */
246
+ const POD_SPECS = [
247
+ ["kubernetes:core/v1:Pod", "spec"],
248
+ ["kubernetes:apps/v1:Deployment", "spec.template.spec"],
249
+ ["kubernetes:apps/v1:StatefulSet", "spec.template.spec"],
250
+ ["kubernetes:apps/v1:DaemonSet", "spec.template.spec"],
251
+ ["kubernetes:batch/v1:Job", "spec.template.spec"],
252
+ ["kubernetes:batch/v1:CronJob", "spec.jobTemplate.spec.template.spec"],
253
+ ];
254
+ const NAMESPACE = "kubernetes:core/v1:Namespace";
255
+ const SERVICE_ACCOUNT = "kubernetes:core/v1:ServiceAccount";
256
+ const CONFIG_MAP = "kubernetes:core/v1:ConfigMap";
257
+ const SECRET = "kubernetes:core/v1:Secret";
258
+ /** Kinds that sit in a namespace, so `metadata.namespace` places them. */
259
+ const NAMESPACED_KINDS = [
260
+ ...POD_SPECS.map(([kind]) => kind),
261
+ "kubernetes:core/v1:Service",
262
+ CONFIG_MAP,
263
+ SECRET,
264
+ SERVICE_ACCOUNT,
265
+ "kubernetes:core/v1:PersistentVolumeClaim",
266
+ "kubernetes:networking.k8s.io/v1:Ingress",
267
+ "kubernetes:rbac.authorization.k8s.io/v1:Role",
268
+ "kubernetes:rbac.authorization.k8s.io/v1:RoleBinding",
269
+ ];
270
+ /** Kinds other objects name by `metadata.name`. */
271
+ const NAMED_KINDS = [...NAMESPACED_KINDS, NAMESPACE];
272
+ const first = (holder, path) => readPath(holder.attrs, path).find((v) => v !== "");
273
+ /**
274
+ * A pod spec's reference to a namespaced object, by name: the name is looked
275
+ * up inside the holder's `metadata.namespace` in any member, so the object
276
+ * can be this lexicon's or the k8s lexicon's. A holder that names no
277
+ * namespace looks inside its own scope.
278
+ */
279
+ function namespacedRule(from, path, target, label) {
280
+ return targets(target).map((targetKind) => ({
281
+ from,
282
+ path,
283
+ targetKind,
284
+ relation: "reference",
285
+ label,
286
+ join(holder, find) {
287
+ const namespace = first(holder, "metadata.namespace");
288
+ return [...new Set(readPath(holder.attrs, path))]
289
+ .filter((name) => name !== "")
290
+ .map((name) => ({ value: name, targets: (namespace === undefined ? find(name) : find(name, namespace)).filter((n) => n.kind === targetKind) }));
291
+ },
292
+ }));
293
+ }
294
+ /** What a pod spec names: its service account, mounted config and secrets, and env sources. */
295
+ function podSpecRules(kind, p) {
296
+ return [
297
+ ...namespacedRule(kind, `${p}.serviceAccountName`, SERVICE_ACCOUNT, "runs as"),
298
+ ...namespacedRule(kind, `${p}.volumes[].configMap.name`, CONFIG_MAP, "mounts"),
299
+ ...namespacedRule(kind, `${p}.volumes[].secret.secretName`, SECRET, "mounts"),
300
+ ...namespacedRule(kind, `${p}.containers[].envFrom[].configMapRef.name`, CONFIG_MAP, "env from"),
301
+ ...namespacedRule(kind, `${p}.containers[].envFrom[].secretRef.name`, SECRET, "env from"),
302
+ // An env var whose value is a bucket's literal name (behold#166).
303
+ ...[S3_BUCKET, S3_BUCKET_V2].flatMap((b) => maybe(kind, `${p}.containers[].env[].value`, b, "uses bucket")),
304
+ ];
305
+ }
306
+ const kubernetesRules = [
307
+ ...POD_SPECS.flatMap(([kind, p]) => podSpecRules(kind, p)),
308
+ // A namespaced object is in its Namespace. Optional: most namespaces are made elsewhere.
309
+ ...NAMESPACED_KINDS.flatMap((kind) => rule(kind, "metadata.namespace", NAMESPACE, "in namespace", "containment").map((r) => ({ ...r, optional: true }))),
310
+ ];
311
+ // ── identities, scopes, and the kinds that reference nothing ──
312
+ /** What else names a kind, beyond `outputs.id`, `outputs.arn`, `outputs.name` and `name`. */
313
+ const EXTRA_IDS = {
314
+ [S3_BUCKET]: ["bucket", "outputs.bucket"],
315
+ [S3_BUCKET_V2]: ["bucket", "outputs.bucket"],
316
+ [SQS_QUEUE]: ["outputs.url"],
317
+ [IAM_POLICY]: [],
318
+ [ROUTE53_ZONE]: ["outputs.zoneId"],
319
+ [LB]: ["outputs.dnsName"],
320
+ [GCP_NETWORK]: ["outputs.selfLink"],
321
+ [GCP_SUBNETWORK]: ["outputs.selfLink"],
322
+ [GCP_SERVICE_ACCOUNT]: ["accountId", "outputs.email"],
323
+ [GCP_SECRET]: ["secretId"],
324
+ [GCP_CLUSTER]: ["outputs.selfLink"],
325
+ [AZURE_NATIVE.group]: ["resourceGroupName"],
326
+ [AZURE_NATIVE.vnet]: ["virtualNetworkName"],
327
+ [AZURE_NATIVE.subnet]: ["subnetName"],
328
+ };
329
+ const AWS_NAMED = [
330
+ VPC, SUBNET, SECURITY_GROUP, ROUTE_TABLE, INTERNET_GATEWAY, NAT_GATEWAY, EIP, INSTANCE, NETWORK_INTERFACE, LB, TARGET_GROUP, ECS_CLUSTER, ECS_TASK,
331
+ IAM_ROLE, IAM_POLICY, INSTANCE_PROFILE, LAMBDA, S3_BUCKET, S3_BUCKET_V2, ROUTE53_ZONE, EKS_CLUSTER, RDS_SUBNET_GROUP, RDS_CLUSTER, SQS_QUEUE, SNS_TOPIC, KMS_KEY, LOG_GROUP,
332
+ "aws:secretsmanager/secret:Secret", "aws:elasticache/subnetGroup:SubnetGroup", "aws:rds/instance:Instance",
333
+ ];
334
+ const GCP_NAMED = [GCP_NETWORK, GCP_SUBNETWORK, GCP_INSTANCE, GCP_CLUSTER, GCP_SERVICE_ACCOUNT, GCP_SECRET, GCP_BUCKET];
335
+ const AZURE_NAMED = AZURE_FAMILIES.flatMap((f) => [f.group, f.vnet, f.subnet, f.aks, f.nsg]);
336
+ /** Kinds whose identities are `metadata.name`, in place of the provider outputs. */
337
+ const K8S_NAMED = new Set(NAMED_KINDS);
338
+ const identities = [
339
+ ...[...AWS_NAMED, ...GCP_NAMED, ...AZURE_NAMED].map((kind) => ({ kind, ids: ["outputs.id", "outputs.arn", "outputs.name", "name", ...(EXTRA_IDS[kind] ?? [])] })),
340
+ ...[...K8S_NAMED].map((kind) => ({ kind, ids: ["metadata.name"] })),
341
+ ];
342
+ const scopes = NAMESPACED_KINDS.map((kind) => ({ kind, path: "metadata.namespace" }));
343
+ /**
344
+ * Pulumi kinds this catalog has looked at and found to hold no input that
345
+ * identifies another resource. A node of one of these kinds is not an
346
+ * unresolved kind: nothing was looked for because there is nothing to find.
347
+ */
348
+ export const REFERENCES_NOTHING = new Set([
349
+ VPC,
350
+ EIP,
351
+ S3_BUCKET,
352
+ S3_BUCKET_V2,
353
+ ECS_CLUSTER,
354
+ ROUTE53_ZONE,
355
+ KMS_KEY,
356
+ SQS_QUEUE,
357
+ SNS_TOPIC,
358
+ GCP_NETWORK,
359
+ GCP_SECRET,
360
+ GCP_BUCKET,
361
+ GCP_SERVICE_ACCOUNT,
362
+ AZURE_NATIVE.group,
363
+ AZURE_CLASSIC.group,
364
+ NAMESPACE,
365
+ CONFIG_MAP,
366
+ SECRET,
367
+ SERVICE_ACCOUNT,
368
+ ]);
369
+ /** The catalog. Rules are grouped by provider; each provider lists containment before references. */
370
+ export const PULUMI_REFERENCE_CATALOG = {
371
+ identities,
372
+ scopes,
373
+ refs: [...awsRules, ...gcpRules, ...azureRules, ...kubernetesRules],
374
+ };
375
+ /** Every Pulumi kind the catalog has at least one rule from. */
376
+ export const CATALOGUED_KINDS = new Set(PULUMI_REFERENCE_CATALOG.refs.map((r) => r.from));
377
+ /**
378
+ * True when nothing would be looked for on a node of this kind: no rule is
379
+ * written for it, and it is not one of the kinds known to reference nothing.
380
+ */
381
+ export function isUnresolvedKind(kind) {
382
+ return !CATALOGUED_KINDS.has(kind) && !REFERENCES_NOTHING.has(kind);
383
+ }
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Whether a property named `key` may be copied to a node (#5332): not a
3
+ * Pulumi `__` key, not credential-like, and, at the top level of a Kubernetes
4
+ * Secret or ConfigMap, not its payload. The preview observation
5
+ * (`./preview-observation.ts`) asks this of every path it puts on a node.
6
+ */
7
+ export declare function mayCarryKey(key: string, opts?: {
8
+ type?: unknown;
9
+ topLevel?: boolean;
10
+ }): boolean;
11
+ /** Whether a string is short enough to be a name rather than a document. */
12
+ export declare const isNameSized: (value: string) => boolean;
13
+ /** The inputs and `outputs` a resource's node carries, as the node's props. */
14
+ export declare function referenceProps(resource: {
15
+ type?: unknown;
16
+ id?: unknown;
17
+ inputs?: unknown;
18
+ outputs?: unknown;
19
+ }): Record<string, unknown>;
@@ -0,0 +1,93 @@
1
+ /**
2
+ * What a member's node carries for the reference catalog (#5330): the values
3
+ * a resource's inputs and outputs name other resources by. The graph read
4
+ * used to copy neither, since an export can hold secrets; the catalog needs
5
+ * the names, ids and ARNs, so this copies those and nothing else.
6
+ *
7
+ * - `inputs` keep their Pulumi shape (`vpcId`, `metadata.namespace`), minus
8
+ * Pulumi's own `__` keys. A secret envelope and a value under a key that
9
+ * reads as a credential are left out, and so are the `data`, `stringData`
10
+ * and `binaryData` of a Kubernetes Secret or ConfigMap.
11
+ * - `outputs` keep the top-level strings a resource is named by elsewhere
12
+ * (`arn`, `name`, `selfLink`, `email`), and the resource's `id`, under one
13
+ * `outputs` key so an output never replaces an input of the same name.
14
+ *
15
+ * A string longer than {@link MAX_VALUE} is a document, not a name, and is
16
+ * left out. Pure.
17
+ */
18
+ import { isObject, isSecret, isUnknown } from "./values.js";
19
+ /** Longest string worth matching: an ARN or a self link fits, a policy document does not. */
20
+ const MAX_VALUE = 1024;
21
+ /** Keys whose values are credentials or their carriers. */
22
+ const SENSITIVE_KEY = /(password|passwd|secret|token|credential|private|apikey|accesskey|connectionstring|userdata|sasurl|certificatebody|pem|kubeconfig)/i;
23
+ /** A key that ends like a reference to a thing, which a credential-sounding word may precede (`secretArn`, `tokenName`). */
24
+ const REFERENCE_KEY = /(Arns?|Ids?|IDs?|Names?|Uris?|Urls?)$/;
25
+ /** Kubernetes kinds whose payload is data, not references. */
26
+ const DATA_KINDS = new Set(["kubernetes:core/v1:Secret", "kubernetes:core/v1:ConfigMap"]);
27
+ const DATA_KEYS = new Set(["data", "stringData", "binaryData"]);
28
+ const sensitiveKey = (key) => SENSITIVE_KEY.test(key) && !REFERENCE_KEY.test(key);
29
+ /**
30
+ * Whether a property named `key` may be copied to a node (#5332): not a
31
+ * Pulumi `__` key, not credential-like, and, at the top level of a Kubernetes
32
+ * Secret or ConfigMap, not its payload. The preview observation
33
+ * (`./preview-observation.ts`) asks this of every path it puts on a node.
34
+ */
35
+ export function mayCarryKey(key, opts = {}) {
36
+ if (key.startsWith("__") || sensitiveKey(key))
37
+ return false;
38
+ const dataKind = typeof opts.type === "string" && DATA_KINDS.has(opts.type);
39
+ return !(dataKind && opts.topLevel && DATA_KEYS.has(key));
40
+ }
41
+ /** Whether a string is short enough to be a name rather than a document. */
42
+ export const isNameSized = (value) => value.length <= MAX_VALUE;
43
+ function clean(value, depth) {
44
+ if (depth > 8 || isSecret(value) || isUnknown(value) || value === null || value === undefined)
45
+ return undefined;
46
+ if (typeof value === "string")
47
+ return value.length <= MAX_VALUE ? value : undefined;
48
+ if (typeof value === "number" || typeof value === "boolean")
49
+ return value;
50
+ if (Array.isArray(value)) {
51
+ const items = value.map((v) => clean(v, depth + 1)).filter((v) => v !== undefined);
52
+ return items.length > 0 ? items : undefined;
53
+ }
54
+ if (isObject(value)) {
55
+ const out = {};
56
+ for (const [k, v] of Object.entries(value)) {
57
+ if (k.startsWith("__") || sensitiveKey(k))
58
+ continue;
59
+ const c = clean(v, depth + 1);
60
+ if (c !== undefined)
61
+ out[k] = c;
62
+ }
63
+ return Object.keys(out).length > 0 ? out : undefined;
64
+ }
65
+ return undefined;
66
+ }
67
+ /** The inputs and `outputs` a resource's node carries, as the node's props. */
68
+ export function referenceProps(resource) {
69
+ const props = {};
70
+ const dataKind = typeof resource.type === "string" && DATA_KINDS.has(resource.type);
71
+ if (isObject(resource.inputs)) {
72
+ for (const [k, v] of Object.entries(resource.inputs)) {
73
+ if (k.startsWith("__") || sensitiveKey(k) || (dataKind && DATA_KEYS.has(k)))
74
+ continue;
75
+ const c = clean(v, 0);
76
+ if (c !== undefined)
77
+ props[k] = c;
78
+ }
79
+ }
80
+ const outputs = {};
81
+ if (isObject(resource.outputs) && !dataKind) {
82
+ for (const [k, v] of Object.entries(resource.outputs)) {
83
+ if (k.startsWith("__") || sensitiveKey(k) || typeof v !== "string" || v.length > MAX_VALUE || isSecret(v) || isUnknown(v))
84
+ continue;
85
+ outputs[k] = v;
86
+ }
87
+ }
88
+ if (typeof resource.id === "string" && resource.id !== "" && outputs.id === undefined)
89
+ outputs.id = resource.id;
90
+ if (Object.keys(outputs).length > 0)
91
+ props.outputs = outputs;
92
+ return props;
93
+ }
@@ -21,7 +21,7 @@ import type { Severity } from "@intentius/chant/lint/rule";
21
21
  import { parsePulumiUrn, pulumiNodeKey } from "@intentius/chant/pulumi-urn";
22
22
  import { parseYAML } from "@intentius/chant/yaml";
23
23
  import { isObject, PULUMI_SECRET_SIG, PULUMI_SIG_KEY } from "../../values";
24
- import { lastMemberRead, type PulumiMemberRead } from "../../workspace-member";
24
+ import { lastMemberRead, type PulumiMemberRead } from "../../member-report";
25
25
 
26
26
  /** One resource of the export, with the fields the checks read. */
27
27
  export interface ExportResource {
@@ -14,7 +14,7 @@
14
14
  * project that names the lexicon without a `pulumi.member` gets nothing.
15
15
  */
16
16
  import type { PostSynthCheck, PostSynthContext, PostSynthDiagnostic } from "@intentius/chant/lint/post-synth";
17
- import { lastMemberReport, PULUMI_EXPORT_FILE } from "../../workspace-member";
17
+ import { lastMemberReport, PULUMI_EXPORT_FILE } from "../../member-report";
18
18
 
19
19
  export const pul001: PostSynthCheck = {
20
20
  id: "PUL001",
@@ -14,7 +14,7 @@
14
14
  * stack owner's, outside chant.
15
15
  */
16
16
  import type { PostSynthCheck, PostSynthContext, PostSynthDiagnostic } from "@intentius/chant/lint/post-synth";
17
- import { lastMemberReport, PULUMI_EXPORT_FILE } from "../../workspace-member";
17
+ import { lastMemberReport, PULUMI_EXPORT_FILE } from "../../member-report";
18
18
 
19
19
  export const pul002: PostSynthCheck = {
20
20
  id: "PUL002",
@@ -13,7 +13,7 @@
13
13
  * itself carries none of them.
14
14
  */
15
15
  import type { PostSynthCheck, PostSynthContext, PostSynthDiagnostic } from "@intentius/chant/lint/post-synth";
16
- import { PULUMI_EXPORT_FILE } from "../../workspace-member";
16
+ import { PULUMI_EXPORT_FILE } from "../../member-report";
17
17
  import { entityOf, finding, listed, memberExport, plaintextSecretPaths } from "./member-read-helpers";
18
18
 
19
19
  export const pul003: PostSynthCheck = {
@@ -9,7 +9,7 @@
9
9
  * its own, and drift for that URN reads the live resource only.
10
10
  */
11
11
  import type { PostSynthCheck, PostSynthContext, PostSynthDiagnostic } from "@intentius/chant/lint/post-synth";
12
- import { PULUMI_EXPORT_FILE } from "../../workspace-member";
12
+ import { PULUMI_EXPORT_FILE } from "../../member-report";
13
13
  import { entityOf, finding, flagged, memberExport } from "./member-read-helpers";
14
14
 
15
15
  export const pul004: PostSynthCheck = {
@@ -8,7 +8,7 @@
8
8
  * Its drift reads as missing until the next `pulumi up` creates it.
9
9
  */
10
10
  import type { PostSynthCheck, PostSynthContext, PostSynthDiagnostic } from "@intentius/chant/lint/post-synth";
11
- import { PULUMI_EXPORT_FILE } from "../../workspace-member";
11
+ import { PULUMI_EXPORT_FILE } from "../../member-report";
12
12
  import { entityOf, finding, flagged, memberExport } from "./member-read-helpers";
13
13
 
14
14
  export const pul005: PostSynthCheck = {
@@ -8,7 +8,7 @@
8
8
  * change, which a reviewer reading the diff alone cannot see.
9
9
  */
10
10
  import type { PostSynthCheck, PostSynthContext, PostSynthDiagnostic } from "@intentius/chant/lint/post-synth";
11
- import { PULUMI_EXPORT_FILE } from "../../workspace-member";
11
+ import { PULUMI_EXPORT_FILE } from "../../member-report";
12
12
  import { entityOf, finding, flagged, memberExport } from "./member-read-helpers";
13
13
 
14
14
  export const pul006: PostSynthCheck = {
@@ -9,7 +9,7 @@
9
9
  * does not describe.
10
10
  */
11
11
  import type { PostSynthCheck, PostSynthContext, PostSynthDiagnostic } from "@intentius/chant/lint/post-synth";
12
- import { PULUMI_EXPORT_FILE } from "../../workspace-member";
12
+ import { PULUMI_EXPORT_FILE } from "../../member-report";
13
13
  import { finding, memberExport, urnScopes } from "./member-read-helpers";
14
14
 
15
15
  export const pul007: PostSynthCheck = {
@@ -8,7 +8,7 @@
8
8
  * `--stack`. An export like this was merged or edited by hand.
9
9
  */
10
10
  import type { PostSynthCheck, PostSynthContext, PostSynthDiagnostic } from "@intentius/chant/lint/post-synth";
11
- import { PULUMI_EXPORT_FILE } from "../../workspace-member";
11
+ import { PULUMI_EXPORT_FILE } from "../../member-report";
12
12
  import { finding, memberExport, urnScopes } from "./member-read-helpers";
13
13
 
14
14
  export const pul008: PostSynthCheck = {
@@ -7,7 +7,7 @@
7
7
  * graph shows resources this member's preview and refresh never touch.
8
8
  */
9
9
  import type { PostSynthCheck, PostSynthContext, PostSynthDiagnostic } from "@intentius/chant/lint/post-synth";
10
- import { PULUMI_EXPORT_FILE } from "../../workspace-member";
10
+ import { PULUMI_EXPORT_FILE } from "../../member-report";
11
11
  import { finding, memberExport, pulumiYamlName, urnScopes } from "./member-read-helpers";
12
12
 
13
13
  export const pul009: PostSynthCheck = {
@@ -9,7 +9,7 @@
9
9
  * missing the edges it names.
10
10
  */
11
11
  import type { PostSynthCheck, PostSynthContext, PostSynthDiagnostic } from "@intentius/chant/lint/post-synth";
12
- import { PULUMI_EXPORT_FILE } from "../../workspace-member";
12
+ import { PULUMI_EXPORT_FILE } from "../../member-report";
13
13
  import { entityOf, finding, listed, memberExport } from "./member-read-helpers";
14
14
 
15
15
  export const pul010: PostSynthCheck = {
@@ -8,7 +8,7 @@
8
8
  * keeps the last one, so the other has no node.
9
9
  */
10
10
  import type { PostSynthCheck, PostSynthContext, PostSynthDiagnostic } from "@intentius/chant/lint/post-synth";
11
- import { PULUMI_EXPORT_FILE } from "../../workspace-member";
11
+ import { PULUMI_EXPORT_FILE } from "../../member-report";
12
12
  import { entityOf, finding, memberExport } from "./member-read-helpers";
13
13
 
14
14
  export const pul011: PostSynthCheck = {
@@ -10,7 +10,7 @@
10
10
  */
11
11
  import type { PostSynthCheck, PostSynthContext, PostSynthDiagnostic } from "@intentius/chant/lint/post-synth";
12
12
  import { isPulumiNodeless } from "@intentius/chant/pulumi-urn";
13
- import { PULUMI_EXPORT_FILE } from "../../workspace-member";
13
+ import { PULUMI_EXPORT_FILE } from "../../member-report";
14
14
  import { finding, flagged, listed, memberExport } from "./member-read-helpers";
15
15
 
16
16
  export const pul012: PostSynthCheck = {
@@ -8,7 +8,7 @@
8
8
  * resources out differently, and what chant reads from it is not checked.
9
9
  */
10
10
  import type { PostSynthCheck, PostSynthContext, PostSynthDiagnostic } from "@intentius/chant/lint/post-synth";
11
- import { PULUMI_EXPORT_FILE } from "../../workspace-member";
11
+ import { PULUMI_EXPORT_FILE } from "../../member-report";
12
12
  import { finding, memberExport } from "./member-read-helpers";
13
13
 
14
14
  /** The deployment schema version the readers are written against. */