@microagi/alchemy-gcp 0.1.2
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/LICENSE +201 -0
- package/README.md +88 -0
- package/lib/Auth/AuthProvider.d.ts +48 -0
- package/lib/Auth/AuthProvider.d.ts.map +1 -0
- package/lib/Auth/AuthProvider.js +84 -0
- package/lib/Auth/AuthProvider.js.map +1 -0
- package/lib/Auth/Credentials.d.ts +28 -0
- package/lib/Auth/Credentials.d.ts.map +1 -0
- package/lib/Auth/Credentials.js +41 -0
- package/lib/Auth/Credentials.js.map +1 -0
- package/lib/CloudResourceManager/Project.d.ts +143 -0
- package/lib/CloudResourceManager/Project.d.ts.map +1 -0
- package/lib/CloudResourceManager/Project.js +272 -0
- package/lib/CloudResourceManager/Project.js.map +1 -0
- package/lib/CloudResourceManager/index.d.ts +3 -0
- package/lib/CloudResourceManager/index.d.ts.map +1 -0
- package/lib/CloudResourceManager/index.js +2 -0
- package/lib/CloudResourceManager/index.js.map +1 -0
- package/lib/Compute/GlobalAddress.d.ts +101 -0
- package/lib/Compute/GlobalAddress.d.ts.map +1 -0
- package/lib/Compute/GlobalAddress.js +134 -0
- package/lib/Compute/GlobalAddress.js.map +1 -0
- package/lib/Compute/Network.d.ts +114 -0
- package/lib/Compute/Network.d.ts.map +1 -0
- package/lib/Compute/Network.js +145 -0
- package/lib/Compute/Network.js.map +1 -0
- package/lib/Compute/Operations.d.ts +34 -0
- package/lib/Compute/Operations.d.ts.map +1 -0
- package/lib/Compute/Operations.js +62 -0
- package/lib/Compute/Operations.js.map +1 -0
- package/lib/Compute/SharedVpcHost.d.ts +44 -0
- package/lib/Compute/SharedVpcHost.d.ts.map +1 -0
- package/lib/Compute/SharedVpcHost.js +71 -0
- package/lib/Compute/SharedVpcHost.js.map +1 -0
- package/lib/Compute/SharedVpcServiceProject.d.ts +46 -0
- package/lib/Compute/SharedVpcServiceProject.d.ts.map +1 -0
- package/lib/Compute/SharedVpcServiceProject.js +96 -0
- package/lib/Compute/SharedVpcServiceProject.js.map +1 -0
- package/lib/Compute/Subnetwork.d.ts +108 -0
- package/lib/Compute/Subnetwork.d.ts.map +1 -0
- package/lib/Compute/Subnetwork.js +201 -0
- package/lib/Compute/Subnetwork.js.map +1 -0
- package/lib/Compute/index.d.ts +6 -0
- package/lib/Compute/index.d.ts.map +1 -0
- package/lib/Compute/index.js +6 -0
- package/lib/Compute/index.js.map +1 -0
- package/lib/Container/Cluster.d.ts +216 -0
- package/lib/Container/Cluster.d.ts.map +1 -0
- package/lib/Container/Cluster.js +326 -0
- package/lib/Container/Cluster.js.map +1 -0
- package/lib/Container/NodePool.d.ts +214 -0
- package/lib/Container/NodePool.d.ts.map +1 -0
- package/lib/Container/NodePool.js +344 -0
- package/lib/Container/NodePool.js.map +1 -0
- package/lib/Container/Operations.d.ts +50 -0
- package/lib/Container/Operations.d.ts.map +1 -0
- package/lib/Container/Operations.js +51 -0
- package/lib/Container/Operations.js.map +1 -0
- package/lib/Container/index.d.ts +5 -0
- package/lib/Container/index.d.ts.map +1 -0
- package/lib/Container/index.js +3 -0
- package/lib/Container/index.js.map +1 -0
- package/lib/Parallelstore/Instance.d.ts +119 -0
- package/lib/Parallelstore/Instance.d.ts.map +1 -0
- package/lib/Parallelstore/Instance.js +180 -0
- package/lib/Parallelstore/Instance.js.map +1 -0
- package/lib/Parallelstore/index.d.ts +2 -0
- package/lib/Parallelstore/index.d.ts.map +1 -0
- package/lib/Parallelstore/index.js +2 -0
- package/lib/Parallelstore/index.js.map +1 -0
- package/lib/Providers.d.ts +24 -0
- package/lib/Providers.d.ts.map +1 -0
- package/lib/Providers.js +51 -0
- package/lib/Providers.js.map +1 -0
- package/lib/ServiceNetworking/PsaConnection.d.ts +84 -0
- package/lib/ServiceNetworking/PsaConnection.d.ts.map +1 -0
- package/lib/ServiceNetworking/PsaConnection.js +130 -0
- package/lib/ServiceNetworking/PsaConnection.js.map +1 -0
- package/lib/ServiceNetworking/index.d.ts +2 -0
- package/lib/ServiceNetworking/index.d.ts.map +1 -0
- package/lib/ServiceNetworking/index.js +2 -0
- package/lib/ServiceNetworking/index.js.map +1 -0
- package/lib/ServiceUsage/ApiEnable.d.ts +78 -0
- package/lib/ServiceUsage/ApiEnable.d.ts.map +1 -0
- package/lib/ServiceUsage/ApiEnable.js +132 -0
- package/lib/ServiceUsage/ApiEnable.js.map +1 -0
- package/lib/ServiceUsage/index.d.ts +3 -0
- package/lib/ServiceUsage/index.d.ts.map +1 -0
- package/lib/ServiceUsage/index.js +2 -0
- package/lib/ServiceUsage/index.js.map +1 -0
- package/lib/Tags.d.ts +57 -0
- package/lib/Tags.d.ts.map +1 -0
- package/lib/Tags.js +106 -0
- package/lib/Tags.js.map +1 -0
- package/lib/index.d.ts +11 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +10 -0
- package/lib/index.js.map +1 -0
- package/package.json +70 -0
- package/src/Auth/AuthProvider.ts +180 -0
- package/src/Auth/Credentials.ts +69 -0
- package/src/CloudResourceManager/Project.ts +517 -0
- package/src/CloudResourceManager/index.ts +2 -0
- package/src/Compute/GlobalAddress.ts +283 -0
- package/src/Compute/Network.ts +306 -0
- package/src/Compute/Operations.ts +108 -0
- package/src/Compute/SharedVpcHost.ts +141 -0
- package/src/Compute/SharedVpcServiceProject.ts +185 -0
- package/src/Compute/Subnetwork.ts +375 -0
- package/src/Compute/index.ts +5 -0
- package/src/Container/Cluster.ts +599 -0
- package/src/Container/NodePool.ts +620 -0
- package/src/Container/Operations.ts +88 -0
- package/src/Container/index.ts +8 -0
- package/src/Parallelstore/Instance.ts +371 -0
- package/src/Parallelstore/index.ts +1 -0
- package/src/Providers.ts +84 -0
- package/src/ServiceNetworking/PsaConnection.ts +269 -0
- package/src/ServiceNetworking/index.ts +1 -0
- package/src/ServiceUsage/ApiEnable.ts +267 -0
- package/src/ServiceUsage/index.ts +2 -0
- package/src/Tags.ts +130 -0
- package/src/index.ts +16 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for describing the origin of the Work and
|
|
141
|
+
reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Support. While redistributing the Work or
|
|
166
|
+
Derivative Works thereof, You may choose to offer, and charge a
|
|
167
|
+
fee for, acceptance of support, warranty, indemnity, or other
|
|
168
|
+
liability obligations and/or rights consistent with this License.
|
|
169
|
+
However, in accepting such obligations, You may act only on Your
|
|
170
|
+
own behalf and on Your sole responsibility, not on behalf of any
|
|
171
|
+
other Contributor, and only if You agree to indemnify, defend, and
|
|
172
|
+
hold each Contributor harmless for any liability incurred by, or
|
|
173
|
+
claims asserted against, such Contributor by reason of your
|
|
174
|
+
accepting any such warranty or support.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2026 MicroAGI Labs
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
# @microagi/alchemy-gcp
|
|
2
|
+
|
|
3
|
+
GCP provider for [Alchemy v2](https://v2.alchemy.run) — Effect-native Infrastructure-as-Code. Alchemy ships only AWS + Cloudflare providers out of the box; this package fills the GCP gap.
|
|
4
|
+
|
|
5
|
+
Resources are implemented against [`@distilled.cloud/gcp`](https://github.com/alchemy-run/distilled) (Effect-native, typed GCP SDK generated from the Google Discovery Documents). Authentication uses Google Application Default Credentials via [`google-auth-library`](https://www.npmjs.com/package/google-auth-library), bridged into the `Credentials` `Context.Service` exported by `@distilled.cloud/gcp`.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
bun add @microagi/alchemy-gcp alchemy@next @distilled.cloud/gcp effect
|
|
11
|
+
# or
|
|
12
|
+
npm install @microagi/alchemy-gcp alchemy@next @distilled.cloud/gcp effect
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
`alchemy`, `@distilled.cloud/gcp`, and `effect` are peer dependencies — they must resolve to a single instance in your dependency tree so that the `Credentials` `Context.Service` tag identity is preserved.
|
|
16
|
+
|
|
17
|
+
The `next` dist-tag is required for `alchemy` because `latest` still points at the v1 line (`0.93.x`); v2 betas live under `next`.
|
|
18
|
+
|
|
19
|
+
## Authenticate
|
|
20
|
+
|
|
21
|
+
```sh
|
|
22
|
+
gcloud auth application-default login # local
|
|
23
|
+
# or, in CI / on GCP, ADC resolves automatically via the metadata server
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
A `serviceAccountKey` flow is also wired through `alchemy login`.
|
|
27
|
+
|
|
28
|
+
## Use
|
|
29
|
+
|
|
30
|
+
```ts
|
|
31
|
+
import * as Alchemy from "alchemy";
|
|
32
|
+
import { inMemoryState } from "alchemy/State";
|
|
33
|
+
import * as Effect from "effect/Effect";
|
|
34
|
+
import * as GCP from "@microagi/alchemy-gcp";
|
|
35
|
+
|
|
36
|
+
await Alchemy.run(
|
|
37
|
+
Alchemy.Stack(
|
|
38
|
+
"research",
|
|
39
|
+
{ providers: GCP.providers(), state: inMemoryState() },
|
|
40
|
+
Effect.gen(function* () {
|
|
41
|
+
const project = yield* GCP.Project("ResearchProj", {
|
|
42
|
+
parent: { type: "folder", id: "<your-folder-id>" },
|
|
43
|
+
displayName: "research",
|
|
44
|
+
billingAccount: "billingAccounts/<your-billing-account>",
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
const cluster = yield* GCP.Cluster("Main", {
|
|
48
|
+
project: project.projectId,
|
|
49
|
+
location: "us-central1",
|
|
50
|
+
network: "shared-vpc",
|
|
51
|
+
subnetwork: "research-subnet",
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
yield* GCP.NodePool("system", {
|
|
55
|
+
cluster,
|
|
56
|
+
machineType: "e2-standard-4",
|
|
57
|
+
minNodes: 1,
|
|
58
|
+
maxNodes: 3,
|
|
59
|
+
});
|
|
60
|
+
}),
|
|
61
|
+
),
|
|
62
|
+
);
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
`inMemoryState()` works for examples and tests. For real deployments, swap it for `localState()` (file-backed) or `httpStateStore()` (server-backed) — see [`alchemy/State`](https://v2.alchemy.run/concepts/state).
|
|
66
|
+
|
|
67
|
+
Long-running operations (`createProjects`, `patchProjects`, GKE cluster ops) are polled internally; reconcilers follow the [Alchemy reconciler doctrine](https://v2.alchemy.run/concepts/resource-lifecycle) (single observe → ensure → sync → return flow that converges from any starting state, including adoption).
|
|
68
|
+
|
|
69
|
+
## Resources
|
|
70
|
+
|
|
71
|
+
- **`GCP.Project`** — projects under an org or folder, with optional billing-account attach.
|
|
72
|
+
- **`GCP.ApiEnable`** — project-level GCP service enablement.
|
|
73
|
+
- **`GCP.Cluster`** — Standard GKE cluster.
|
|
74
|
+
- **`GCP.NodePool`** — node pool attached to a cluster, including accelerator (GPU) configurations.
|
|
75
|
+
- **`GCP.Parallelstore`** — Parallelstore filesystem instance.
|
|
76
|
+
- **`GCP.Network`** — VPC network.
|
|
77
|
+
- **`GCP.Subnetwork`** — VPC subnetwork.
|
|
78
|
+
- **`GCP.PrivateServiceConnection`** — VPC peering for Google managed services (PSA).
|
|
79
|
+
|
|
80
|
+
Each resource's full prop/attribute set is documented as JSDoc on the source.
|
|
81
|
+
|
|
82
|
+
## Adoption
|
|
83
|
+
|
|
84
|
+
`read` is gated on the alchemy internal labels `alchemy_app` / `alchemy_stage` / `alchemy_id`. Existing GCP resources lacking those labels are returned `Unowned` — the engine refuses to take them over without explicit `--adopt` (or `adopt(true)` on the resource call).
|
|
85
|
+
|
|
86
|
+
## License
|
|
87
|
+
|
|
88
|
+
Apache-2.0.
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { AuthError } from "alchemy/Auth/AuthProvider";
|
|
2
|
+
import * as Effect from "effect/Effect";
|
|
3
|
+
import * as Redacted from "effect/Redacted";
|
|
4
|
+
export declare const GCP_AUTH_PROVIDER_NAME = "GCP";
|
|
5
|
+
/**
|
|
6
|
+
* GCP profile config.
|
|
7
|
+
*
|
|
8
|
+
* There is intentionally a single method — `adc` — because
|
|
9
|
+
* `google-auth-library` already discovers every credential source we
|
|
10
|
+
* care about, in this priority order:
|
|
11
|
+
*
|
|
12
|
+
* 1. `GOOGLE_APPLICATION_CREDENTIALS` env var → JSON service-account key
|
|
13
|
+
* 2. gcloud user ADC at `~/.config/gcloud/application_default_credentials.json`
|
|
14
|
+
* 3. GCE/GKE metadata server (workload identity)
|
|
15
|
+
*
|
|
16
|
+
* To pin a specific key file at the *profile* level (rather than
|
|
17
|
+
* process-wide via the env var), set `keyFile`. To override the
|
|
18
|
+
* billing/quota project, set `project`. Both are passed straight
|
|
19
|
+
* through to `new GoogleAuth({ ... })`.
|
|
20
|
+
*/
|
|
21
|
+
export type GCPAuthConfig = {
|
|
22
|
+
method: "adc";
|
|
23
|
+
/** Override the project that google-auth-library would discover. */
|
|
24
|
+
project?: string;
|
|
25
|
+
/** Pin a specific service-account JSON key file to this profile. */
|
|
26
|
+
keyFile?: string;
|
|
27
|
+
};
|
|
28
|
+
export interface GCPResolvedCredentials {
|
|
29
|
+
accessToken: Redacted.Redacted<string>;
|
|
30
|
+
project: string | undefined;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Mint a fresh access token (and resolve a project) by delegating to
|
|
34
|
+
* `google-auth-library`. All credential discovery — env-var key files,
|
|
35
|
+
* gcloud user ADC, metadata server — is the library's job; we just
|
|
36
|
+
* pass through `project` / `keyFile` overrides.
|
|
37
|
+
*/
|
|
38
|
+
export declare const mintToken: (config?: {
|
|
39
|
+
project?: string;
|
|
40
|
+
keyFile?: string;
|
|
41
|
+
}) => Effect.Effect<GCPResolvedCredentials, AuthError>;
|
|
42
|
+
/**
|
|
43
|
+
* Layer that registers the GCP {@link AuthProvider} into the
|
|
44
|
+
* {@link AuthProviders} registry when built. Include this in the GCP
|
|
45
|
+
* `providers()` layer so `alchemy login` can discover it.
|
|
46
|
+
*/
|
|
47
|
+
export declare const GCPAuth: import("effect/Layer").Layer<never, never, import("alchemy").AuthProviders>;
|
|
48
|
+
//# sourceMappingURL=AuthProvider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AuthProvider.d.ts","sourceRoot":"","sources":["../../src/Auth/AuthProvider.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,SAAS,EAGV,MAAM,2BAA2B,CAAC;AAKnC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AAExC,OAAO,KAAK,QAAQ,MAAM,iBAAiB,CAAC;AAK5C,eAAO,MAAM,sBAAsB,QAAQ,CAAC;AAE5C;;;;;;;;;;;;;;;GAeG;AACH,MAAM,MAAM,aAAa,GAAG;IAC1B,MAAM,EAAE,KAAK,CAAC;IACd,oEAAoE;IACpE,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,oEAAoE;IACpE,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,MAAM,WAAW,sBAAsB;IACrC,WAAW,EAAE,QAAQ,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;IACvC,OAAO,EAAE,MAAM,GAAG,SAAS,CAAC;CAC7B;AAED;;;;;GAKG;AACH,eAAO,MAAM,SAAS,GACpB,SAAQ;IAAE,OAAO,CAAC,EAAE,MAAM,CAAC;IAAC,OAAO,CAAC,EAAE,MAAM,CAAA;CAAO,KAClD,MAAM,CAAC,MAAM,CAAC,sBAAsB,EAAE,SAAS,CAkC9C,CAAC;AA4EL;;;;GAIG;AACH,eAAO,MAAM,OAAO,6EASlB,CAAC"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { AuthError, AuthProviderLayer, } from "alchemy/Auth/AuthProvider";
|
|
2
|
+
import { displayRedacted } from "alchemy/Auth/Credentials";
|
|
3
|
+
import { retryOnce } from "alchemy/Auth/Env";
|
|
4
|
+
import * as Clank from "alchemy/Util/Clank";
|
|
5
|
+
import * as Console from "effect/Console";
|
|
6
|
+
import * as Effect from "effect/Effect";
|
|
7
|
+
import * as Match from "effect/Match";
|
|
8
|
+
import * as Redacted from "effect/Redacted";
|
|
9
|
+
import { GoogleAuth } from "google-auth-library";
|
|
10
|
+
const SCOPES = ["https://www.googleapis.com/auth/cloud-platform"];
|
|
11
|
+
export const GCP_AUTH_PROVIDER_NAME = "GCP";
|
|
12
|
+
/**
|
|
13
|
+
* Mint a fresh access token (and resolve a project) by delegating to
|
|
14
|
+
* `google-auth-library`. All credential discovery — env-var key files,
|
|
15
|
+
* gcloud user ADC, metadata server — is the library's job; we just
|
|
16
|
+
* pass through `project` / `keyFile` overrides.
|
|
17
|
+
*/
|
|
18
|
+
export const mintToken = (config = {}) => Effect.gen(function* () {
|
|
19
|
+
const auth = yield* Effect.sync(() => new GoogleAuth({
|
|
20
|
+
scopes: SCOPES,
|
|
21
|
+
...(config.keyFile ? { keyFile: config.keyFile } : {}),
|
|
22
|
+
...(config.project ? { projectId: config.project } : {}),
|
|
23
|
+
}));
|
|
24
|
+
const accessToken = yield* Effect.tryPromise({
|
|
25
|
+
try: () => auth.getAccessToken(),
|
|
26
|
+
catch: (cause) => new AuthError({
|
|
27
|
+
message: `Failed to acquire GCP access token: ${cause?.message ?? String(cause)}. Run \`gcloud auth application-default login\` or set GOOGLE_APPLICATION_CREDENTIALS.`,
|
|
28
|
+
cause,
|
|
29
|
+
}),
|
|
30
|
+
});
|
|
31
|
+
if (!accessToken) {
|
|
32
|
+
return yield* new AuthError({
|
|
33
|
+
message: "google-auth-library returned an empty access token. Run `gcloud auth application-default login` or set GOOGLE_APPLICATION_CREDENTIALS.",
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
const project = yield* Effect.tryPromise({
|
|
37
|
+
try: () => auth.getProjectId(),
|
|
38
|
+
catch: () => undefined,
|
|
39
|
+
}).pipe(Effect.orElseSucceed(() => undefined));
|
|
40
|
+
return {
|
|
41
|
+
accessToken: Redacted.make(accessToken),
|
|
42
|
+
project: project ?? undefined,
|
|
43
|
+
};
|
|
44
|
+
});
|
|
45
|
+
const configureCredentials = (_profileName, ctx) => Effect.gen(function* () {
|
|
46
|
+
if (ctx.ci)
|
|
47
|
+
return { method: "adc" };
|
|
48
|
+
// Validate that google-auth-library can resolve credentials. If it
|
|
49
|
+
// can't, surface a hint but don't block — the user might be about
|
|
50
|
+
// to fix their environment, and `read` will fail loudly later.
|
|
51
|
+
yield* mintToken().pipe(Effect.tap(() => Clank.success("GCP: ADC credentials available.")), Effect.catch((e) => Clank.warn(`GCP: ${e.message} — continuing; alchemy will retry when credentials are needed.`).pipe(Effect.asVoid)));
|
|
52
|
+
const project = yield* Clank.text({
|
|
53
|
+
message: "Default GCP project (Enter to defer to google-auth-library discovery)",
|
|
54
|
+
placeholder: process.env.GOOGLE_CLOUD_PROJECT ??
|
|
55
|
+
process.env.GOOGLE_PROJECT_ID ??
|
|
56
|
+
"",
|
|
57
|
+
defaultValue: "",
|
|
58
|
+
}).pipe(retryOnce, Effect.catch(() => Effect.succeed("")));
|
|
59
|
+
return {
|
|
60
|
+
method: "adc",
|
|
61
|
+
...(project.trim() ? { project: project.trim() } : {}),
|
|
62
|
+
};
|
|
63
|
+
});
|
|
64
|
+
const login = (_profileName, config) => mintToken(config).pipe(Effect.tap(() => Clank.success("GCP: credentials valid.")), Effect.asVoid);
|
|
65
|
+
const logout = (_profileName, _config) => Clank.info("GCP: credentials are managed by google-auth-library. Run `gcloud auth application-default revoke` to revoke user ADC, or unset GOOGLE_APPLICATION_CREDENTIALS to drop a service-account key.");
|
|
66
|
+
const resolveCredentials = (_profileName, config) => Match.value(config).pipe(Match.when({ method: "adc" }, (cfg) => mintToken(cfg)), Match.exhaustive);
|
|
67
|
+
const prettyPrint = (profileName, config) => resolveCredentials(profileName, config).pipe(Effect.tap((creds) => Effect.all([
|
|
68
|
+
Console.log(` accessToken: ${displayRedacted(creds.accessToken, 6)}`),
|
|
69
|
+
Console.log(` project: ${creds.project ?? "(none)"}`),
|
|
70
|
+
Console.log(` source: google-auth-library${config.keyFile ? ` (keyFile=${config.keyFile})` : config.project ? " (ADC + pinned project)" : " (ADC)"}`),
|
|
71
|
+
])), Effect.catch((e) => Console.error(` Failed to retrieve credentials: ${e}`)));
|
|
72
|
+
/**
|
|
73
|
+
* Layer that registers the GCP {@link AuthProvider} into the
|
|
74
|
+
* {@link AuthProviders} registry when built. Include this in the GCP
|
|
75
|
+
* `providers()` layer so `alchemy login` can discover it.
|
|
76
|
+
*/
|
|
77
|
+
export const GCPAuth = AuthProviderLayer()(GCP_AUTH_PROVIDER_NAME, {
|
|
78
|
+
configure: configureCredentials,
|
|
79
|
+
login,
|
|
80
|
+
logout,
|
|
81
|
+
prettyPrint,
|
|
82
|
+
read: resolveCredentials,
|
|
83
|
+
});
|
|
84
|
+
//# sourceMappingURL=AuthProvider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AuthProvider.js","sourceRoot":"","sources":["../../src/Auth/AuthProvider.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,SAAS,EACT,iBAAiB,GAElB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAC3D,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,KAAK,KAAK,MAAM,oBAAoB,CAAC;AAC5C,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAC;AAC1C,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC;AACtC,OAAO,KAAK,QAAQ,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAEjD,MAAM,MAAM,GAAG,CAAC,gDAAgD,CAAC,CAAC;AAElE,MAAM,CAAC,MAAM,sBAAsB,GAAG,KAAK,CAAC;AA+B5C;;;;;GAKG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,CACvB,SAAiD,EAAE,EACD,EAAE,CACpD,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC;IAClB,MAAM,IAAI,GAAG,KAAK,CAAC,CAAC,MAAM,CAAC,IAAI,CAC7B,GAAG,EAAE,CACH,IAAI,UAAU,CAAC;QACb,MAAM,EAAE,MAAM;QACd,GAAG,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,MAAM,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACtD,GAAG,CAAC,MAAM,CAAC,OAAO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ConfigError, Credentials } from "@distilled.cloud/gcp";
|
|
2
|
+
import * as Config from "effect/Config";
|
|
3
|
+
import * as Layer from "effect/Layer";
|
|
4
|
+
export { Credentials } from "@distilled.cloud/gcp";
|
|
5
|
+
/**
|
|
6
|
+
* Single-profile ADC bridge. Bypasses the `AuthProvider` registry —
|
|
7
|
+
* useful for tests and one-off scripts where multi-profile resolution
|
|
8
|
+
* isn't needed. All credential discovery is delegated to
|
|
9
|
+
* `google-auth-library`; the optional `project` argument overrides
|
|
10
|
+
* the project the library would discover.
|
|
11
|
+
*
|
|
12
|
+
* Prefer {@link fromAuthProvider} when the stack runs through
|
|
13
|
+
* `alchemy login` / `ALCHEMY_PROFILE`.
|
|
14
|
+
*/
|
|
15
|
+
export declare const fromADC: (project?: string) => Layer.Layer<Credentials, ConfigError, never>;
|
|
16
|
+
/**
|
|
17
|
+
* Build a `Credentials` Layer that resolves GCP credentials via the
|
|
18
|
+
* Alchemy AuthProvider registry, using the active profile (from
|
|
19
|
+
* `ALCHEMY_PROFILE`, default `"default"`).
|
|
20
|
+
*
|
|
21
|
+
* Routes through `loadOrConfigure` so a missing profile triggers the
|
|
22
|
+
* provider's `configure` step (interactive locally, `{ method: "adc" }`
|
|
23
|
+
* in CI) before reading credentials. Both methods of the provider
|
|
24
|
+
* ultimately call `mintToken`, which is just a thin wrapper over
|
|
25
|
+
* `google-auth-library`.
|
|
26
|
+
*/
|
|
27
|
+
export declare const fromAuthProvider: () => Layer.Layer<Credentials, Config.ConfigError | import("alchemy/Auth/AuthProvider").AuthError | ConfigError, import("effect/FileSystem").FileSystem | import("alchemy").AuthProviders>;
|
|
28
|
+
//# sourceMappingURL=Credentials.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Credentials.d.ts","sourceRoot":"","sources":["../../src/Auth/Credentials.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAGhE,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AAExC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC;AAQtC,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AASnD;;;;;;;;;GASG;AACH,eAAO,MAAM,OAAO,GAAI,UAAU,MAAM,iDAIrC,CAAC;AAEJ;;;;;;;;;;GAUG;AACH,eAAO,MAAM,gBAAgB,4LAmB1B,CAAC"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { ConfigError, Credentials } from "@distilled.cloud/gcp";
|
|
2
|
+
import { getAuthProvider } from "alchemy/Auth/AuthProvider";
|
|
3
|
+
import { ALCHEMY_PROFILE, loadOrConfigure } from "alchemy/Auth/Profile";
|
|
4
|
+
import * as Config from "effect/Config";
|
|
5
|
+
import * as Effect from "effect/Effect";
|
|
6
|
+
import * as Layer from "effect/Layer";
|
|
7
|
+
import { GCP_AUTH_PROVIDER_NAME, mintToken, } from "./AuthProvider.js";
|
|
8
|
+
export { Credentials } from "@distilled.cloud/gcp";
|
|
9
|
+
const toConfigError = (e) => new ConfigError({
|
|
10
|
+
message: `Failed to resolve GCP credentials: ${e?.message ?? String(e)}`,
|
|
11
|
+
});
|
|
12
|
+
/**
|
|
13
|
+
* Single-profile ADC bridge. Bypasses the `AuthProvider` registry —
|
|
14
|
+
* useful for tests and one-off scripts where multi-profile resolution
|
|
15
|
+
* isn't needed. All credential discovery is delegated to
|
|
16
|
+
* `google-auth-library`; the optional `project` argument overrides
|
|
17
|
+
* the project the library would discover.
|
|
18
|
+
*
|
|
19
|
+
* Prefer {@link fromAuthProvider} when the stack runs through
|
|
20
|
+
* `alchemy login` / `ALCHEMY_PROFILE`.
|
|
21
|
+
*/
|
|
22
|
+
export const fromADC = (project) => Layer.effect(Credentials, mintToken({ project }).pipe(Effect.mapError(toConfigError)));
|
|
23
|
+
/**
|
|
24
|
+
* Build a `Credentials` Layer that resolves GCP credentials via the
|
|
25
|
+
* Alchemy AuthProvider registry, using the active profile (from
|
|
26
|
+
* `ALCHEMY_PROFILE`, default `"default"`).
|
|
27
|
+
*
|
|
28
|
+
* Routes through `loadOrConfigure` so a missing profile triggers the
|
|
29
|
+
* provider's `configure` step (interactive locally, `{ method: "adc" }`
|
|
30
|
+
* in CI) before reading credentials. Both methods of the provider
|
|
31
|
+
* ultimately call `mintToken`, which is just a thin wrapper over
|
|
32
|
+
* `google-auth-library`.
|
|
33
|
+
*/
|
|
34
|
+
export const fromAuthProvider = () => Layer.effect(Credentials, Effect.gen(function* () {
|
|
35
|
+
const auth = yield* getAuthProvider(GCP_AUTH_PROVIDER_NAME);
|
|
36
|
+
const profileName = yield* ALCHEMY_PROFILE;
|
|
37
|
+
const ci = yield* Config.boolean("CI").pipe(Config.withDefault(false));
|
|
38
|
+
const ctx = yield* Effect.context();
|
|
39
|
+
return yield* loadOrConfigure(auth, profileName, { ci }).pipe(Effect.flatMap((cfg) => auth.read(profileName, cfg)), Effect.map(({ accessToken, project }) => ({ accessToken, project })), Effect.mapError(toConfigError), Effect.provide(ctx));
|
|
40
|
+
}));
|
|
41
|
+
//# sourceMappingURL=Credentials.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Credentials.js","sourceRoot":"","sources":["../../src/Auth/Credentials.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAChE,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAC5D,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACxE,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC;AACtC,OAAO,EACL,sBAAsB,EAGtB,SAAS,GACV,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAEnD,MAAM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AAC,CAAC,EACpE,MAAM,CAAC,QAAQ,CAAC,aAAa,CAAC,EAC9B,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,CACpB,CAAC;AACJ,CAAC,CAAC,CACH,CAAC"}
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import { Resource } from "alchemy";
|
|
2
|
+
import * as Provider from "alchemy/Provider";
|
|
3
|
+
import type * as GCP from "../Providers.ts";
|
|
4
|
+
/**
|
|
5
|
+
* Parent for a GCP project — either a folder or an organization.
|
|
6
|
+
*/
|
|
7
|
+
export type ProjectParent = {
|
|
8
|
+
type: "folder";
|
|
9
|
+
id: string;
|
|
10
|
+
} | {
|
|
11
|
+
type: "organization";
|
|
12
|
+
id: string;
|
|
13
|
+
};
|
|
14
|
+
export type ProjectProps = {
|
|
15
|
+
/**
|
|
16
|
+
* Globally-unique project ID. 6-30 lowercase letters/digits/hyphens,
|
|
17
|
+
* must start with a letter, no trailing hyphens. If omitted, derived
|
|
18
|
+
* deterministically from the stack/stage/logical-id via
|
|
19
|
+
* `createPhysicalName`.
|
|
20
|
+
*
|
|
21
|
+
* Project IDs are immutable — changing this triggers a replacement.
|
|
22
|
+
*/
|
|
23
|
+
projectId?: string;
|
|
24
|
+
/**
|
|
25
|
+
* User-visible display name. 4-30 chars, mutable.
|
|
26
|
+
*/
|
|
27
|
+
displayName?: string;
|
|
28
|
+
/**
|
|
29
|
+
* The folder or organization that owns this project.
|
|
30
|
+
*
|
|
31
|
+
* Moving projects between parents is a separate API; treat as
|
|
32
|
+
* replace-only for now.
|
|
33
|
+
*/
|
|
34
|
+
parent: ProjectParent;
|
|
35
|
+
/**
|
|
36
|
+
* User-supplied labels. Alchemy-internal labels (`alchemy_app`,
|
|
37
|
+
* `alchemy_stage`, `alchemy_id`) are merged in automatically and used
|
|
38
|
+
* to gate `read`-time adoption — do not set those keys yourself.
|
|
39
|
+
*/
|
|
40
|
+
labels?: Record<string, string>;
|
|
41
|
+
/**
|
|
42
|
+
* Billing account to attach to the project. Must be the
|
|
43
|
+
* fully-qualified resource name `billingAccounts/{id}` (e.g.
|
|
44
|
+
* `billingAccounts/01A860-D25444-D4B584`) — that's what
|
|
45
|
+
* `cloudbilling.projects.updateBillingInfo` accepts in
|
|
46
|
+
* `billingAccountName`; passing the bare id returns `400 Request
|
|
47
|
+
* contains an invalid argument`. The prefix is enforced at the
|
|
48
|
+
* type level here so the wrong shape fails at compile time.
|
|
49
|
+
*
|
|
50
|
+
* Required for any paid API (GKE, Compute, etc.) — fresh projects
|
|
51
|
+
* have no billing account by default and refuse to enable paid
|
|
52
|
+
* services until one is attached.
|
|
53
|
+
*
|
|
54
|
+
* Mutable via `cloudbilling.projects.updateBillingInfo`. Set to
|
|
55
|
+
* `undefined` (omit) on a project that previously had billing
|
|
56
|
+
* attached and the resource will detach billing on next reconcile,
|
|
57
|
+
* which stops paid services on the project — be deliberate.
|
|
58
|
+
*
|
|
59
|
+
* The `cloudbilling.googleapis.com` API must be enabled on the
|
|
60
|
+
* caller's ADC quota project (typically the user's primary
|
|
61
|
+
* project), not on this target project. This is the same
|
|
62
|
+
* precondition as `cloudresourcemanager.googleapis.com` for project
|
|
63
|
+
* creation, so if you can create projects you can attach billing.
|
|
64
|
+
*/
|
|
65
|
+
billingAccount?: BillingAccountName;
|
|
66
|
+
};
|
|
67
|
+
/**
|
|
68
|
+
* Fully-qualified billing-account resource name. The
|
|
69
|
+
* `billingAccounts/` prefix is the form GCP's APIs return and accept;
|
|
70
|
+
* encoding it at the type level rules out the bare-id mistake at
|
|
71
|
+
* compile time.
|
|
72
|
+
*/
|
|
73
|
+
export type BillingAccountName = `billingAccounts/${string}`;
|
|
74
|
+
/**
|
|
75
|
+
* A GCP project under an organization or folder.
|
|
76
|
+
*
|
|
77
|
+
* Project creation is asynchronous: `createProjects` returns a
|
|
78
|
+
* long-running `Operation` which we poll until `done`. The same applies
|
|
79
|
+
* to `delete` and `patch`. Delete is soft (30-day window) on the
|
|
80
|
+
* server side; we don't undelete.
|
|
81
|
+
*
|
|
82
|
+
* Adoption: a `read` returning a project that lacks our `alchemy_*`
|
|
83
|
+
* labels is wrapped in `Unowned(attrs)`, so the engine fails the plan
|
|
84
|
+
* unless the user passed `--adopt`. This matters more for GCP than for
|
|
85
|
+
* R2 — projects carry billing.
|
|
86
|
+
*
|
|
87
|
+
* @section Creating a Project
|
|
88
|
+
* @example Project under a folder
|
|
89
|
+
* ```typescript
|
|
90
|
+
* const project = yield* GCP.Project("Research", {
|
|
91
|
+
* parent: { type: "folder", id: "264228230413" },
|
|
92
|
+
* displayName: "Research Cluster",
|
|
93
|
+
* });
|
|
94
|
+
* ```
|
|
95
|
+
*
|
|
96
|
+
* @example Project with an explicit ID
|
|
97
|
+
* ```typescript
|
|
98
|
+
* const project = yield* GCP.Project("Research", {
|
|
99
|
+
* projectId: "microagi-research-001",
|
|
100
|
+
* parent: { type: "folder", id: "264228230413" },
|
|
101
|
+
* });
|
|
102
|
+
* ```
|
|
103
|
+
*/
|
|
104
|
+
export type Project = Resource<"GCP.Project", ProjectProps, {
|
|
105
|
+
/** Globally-unique user-assigned id (e.g. `microagi-research-001`). */
|
|
106
|
+
projectId: string;
|
|
107
|
+
/**
|
|
108
|
+
* Server-assigned numeric id (e.g. `415104041262`). String at
|
|
109
|
+
* runtime — GCP encodes int64s as JSON strings to preserve
|
|
110
|
+
* precision — but typed as `` `${number}` `` so callers can
|
|
111
|
+
* compose project-number-form references (`PsaConnection`,
|
|
112
|
+
* `ParallelstoreInstance`, `networkRef`) without manual coercion.
|
|
113
|
+
*/
|
|
114
|
+
projectNumber: `${number}`;
|
|
115
|
+
/** Resource name in the form `projects/{projectNumber}`. */
|
|
116
|
+
name: string;
|
|
117
|
+
/** Display name — may be `undefined` if never set. */
|
|
118
|
+
displayName: string | undefined;
|
|
119
|
+
/** Lifecycle state — `ACTIVE` for normal projects. */
|
|
120
|
+
state: string;
|
|
121
|
+
/** Parent resource string in the form `folders/123` / `organizations/456`. */
|
|
122
|
+
parent: string;
|
|
123
|
+
/** RFC3339 timestamp from the server. */
|
|
124
|
+
createTime: string | undefined;
|
|
125
|
+
/** Labels currently set on the project, including `alchemy_*` internals. */
|
|
126
|
+
labels: Record<string, string>;
|
|
127
|
+
/**
|
|
128
|
+
* Billing account currently attached to the project (e.g.
|
|
129
|
+
* `billingAccounts/XXXXXX-YYYYYY-ZZZZZZ`), or `undefined` when none
|
|
130
|
+
* is attached.
|
|
131
|
+
*/
|
|
132
|
+
billingAccount: BillingAccountName | undefined;
|
|
133
|
+
/**
|
|
134
|
+
* Whether the project is associated with an *open* billing account.
|
|
135
|
+
* `false` when no billing account is attached or the attached
|
|
136
|
+
* account is closed; `true` once an open account is attached and
|
|
137
|
+
* paid services can be enabled.
|
|
138
|
+
*/
|
|
139
|
+
billingEnabled: boolean;
|
|
140
|
+
}, never, GCP.Providers>;
|
|
141
|
+
export declare const Project: import("alchemy").ResourceClass<Project>;
|
|
142
|
+
export declare const ProjectProvider: () => import("effect/Layer").Layer<Provider.Provider<Project>, never, import("effect/unstable/http/HttpClient").HttpClient | import("alchemy").Stage | import("alchemy").Stack | import("@distilled.cloud/gcp").Credentials>;
|
|
143
|
+
//# sourceMappingURL=Project.d.ts.map
|