Skip to content
This repository was archived by the owner on May 20, 2025. It is now read-only.

Commit a57fdf3

Browse files
improve importing resources docs (#687)
Co-authored-by: Ryan Cartwright <[email protected]>
1 parent f654b11 commit a57fdf3

File tree

5 files changed

+129
-83
lines changed

5 files changed

+129
-83
lines changed

docs/get-started/foundations/deployment/index.mdx

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,37 @@ Provider specific stack configuration, including advanced configuration options,
167167
the stack files that target your provider.
168168
</Note>
169169
170+
## Importing Existing Resources
171+
172+
Nitric allows you to import existing resources into your Nitric project.
173+
Currently, the [AWS standard provider](/providers/pulumi/aws#importing-existing-resources) supports importing both [buckets](/providers/pulumi/aws#buckets) and [secrets](/providers/pulumi/aws#secrets), while the [Google Cloud standard provider](/providers/pulumi/gcp#importing-existing-resources) supports importing [secrets](/providers/pulumi/gcp#secrets) only. Importing resources via other providers is not yet supported.
174+
175+
<Note>
176+
Need to import another resource type or want support for additional providers?
177+
Chat with us on [Discord](https://nitric.io/chat) or [open an
178+
issue](https://github.com/nitrictech/nitric/issues) on GitHub.
179+
</Note>
180+
181+
### How imports work
182+
183+
If you have existing resources that you would like to use in your Nitric project, you may be able to import them using the `import` section of your Nitric [stack file](#stacks). This section allows you to import existing resources and use them in your Nitric project. This indicates to the provider that you would like to use the existing resources in your Nitric project, rather than create a new one.
184+
185+
Imports are stack specific, meaning that you can import resources into a specific stack file, and they will only be available in that stack. Other stacks for the same project can either create or import those resources as needed.
186+
187+
### What happens during `nitric up`
188+
189+
When deploying a stack that has imported resources, the resources will not be created. Instead, Nitric will use the referenced resources from the stack file. If the resources can't be located or accessed, the deployment will fail.
190+
191+
Nitric attempts to make the minimum changes needed to the imported resources to make them compatible with the Nitric project. Since Nitric standard providers use custom tags for resource location, the resources will have these tags added during deployment. Additionally, Nitric will add the necessary permissions to the resources to allow the Nitric project to access them, just like it would with resources it creates.
192+
193+
The tags created are extremely unlikely to conflict with existing tags. For example, with the AWS standard provider, an S3 bucket will have these two tags created `x-nitric-{project}-{stack}-{randomId}-type` and `x-nitric-{project}-{stack}-{randomId}-name`. The type tag identifies the type of Nitric resource, and the name tag is the name of the resource in the Nitric project.
194+
195+
### What happens during `nitric down`
196+
197+
When tearing down a stack that has imported resources, the resources will not be deleted. This is because the resources were not created by Nitric, so for safety they're always set to 'retainOnDelete'. If you would like to delete the resources, you will need to do so manually or using whichever tools created those resources initially.
198+
199+
The tags added to the resources during deployment may not be removed during the `nitric down` process. If you intend to redeploy the stack with an updated import, you may need to remove these tags manually.
200+
170201
## CI/CD
171202

172203
Deploying Nitric applications with CI/CD automation tools is simple. Explore the guides below for examples with common CI/CD tools:

docs/providers/pulumi/aws/index.mdx renamed to docs/providers/pulumi/aws.mdx

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ You can create an Access Key by logging into the [AWS console](https://aws.amazo
5555
for full details on credentials and configuration.
5656
</Note>
5757

58-
## Locating deployed resources
58+
## Locating Deployed Resources
5959

6060
This Nitric AWS provider creates a resource tag manager group and tags all possible resources to be referenced by this group. You can locate resources using the [AWS Console](https://console.aws.amazon.com/).
6161

@@ -88,6 +88,66 @@ API Endpoints:
8888
main: https://example.execute-api.us-east-2.amazonaws.com
8989
```
9090

91+
## Importing Existing Resources
92+
93+
The Nitric team is working to expand the list of resources that can be imported. Currently, only the following resources are supported:
94+
95+
- [Secrets](/secrets)
96+
- [Buckets](/storage)
97+
98+
<Note>
99+
Currently, only resources in the same AWS account and region as the Nitric project
100+
are supported.
101+
</Note>
102+
103+
### Buckets
104+
105+
To import an S3 bucket, you will need to know the bucket's name or ARN. You can find the ARN of an S3 bucket in the AWS console or by using the AWS CLI.
106+
107+
First, add the bucket to your project as you usually would if it wasn't imported. Then add the bucket to the `import` section of your stack file. Here's an example of how to import an S3 bucket:
108+
109+
```javascript
110+
import { bucket } from '@nitric/sdk'
111+
112+
const images = bucket('images').allow('read', 'write', 'delete')
113+
```
114+
115+
```yaml
116+
import:
117+
buckets:
118+
images: arn:aws:s3:::images-bucket-example
119+
```
120+
121+
<Note>
122+
Either the bucket's name or ARN can be used to import the bucket. The ARN is
123+
recommended as it is less likely to have a conflict during lookup.
124+
</Note>
125+
126+
### Secrets
127+
128+
To import a secret, you will need to know the secret's ARN. You can find the ARN of a secret in the AWS console or by using the AWS CLI.
129+
130+
First, add the secret to your project as you usually would if it wasn't imported. Then add the secret to the `import` section of your stack file. Here's an example of how to import a secret:
131+
132+
```javascript
133+
import { secret } from "@nitric/sdk
134+
135+
const mySecret = secret("credentials").allow("access");
136+
```
137+
138+
```yaml
139+
import:
140+
secrets:
141+
credentials: arn:aws:secretsmanager:us-east-1:123456789012:secret:my-secret
142+
```
143+
144+
<Note>
145+
Unlike some other imported resources, secret imports require the ARN to be used.
146+
Providing only the secret's name will be invalid.
147+
</Note>
148+
149+
Need to import another resource type or have another question? Chat with us on [Discord](https://nitric.io/chat) or [open an issue](https://github.com/nitrictech/nitric/issues) on GitHub.
150+
91151
## Stack Configuration
92152

93153
```yaml title:nitric.[stack ID].yaml

docs/providers/pulumi/aws/imports.mdx

Lines changed: 0 additions & 82 deletions
This file was deleted.

docs/providers/pulumi/gcp.mdx

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,37 @@ Download & install the [latest CLI release](https://cloud.google.com/sdk/install
5757

5858
For Google Cloud to allow deployments, a billing account must be [created and attached](https://console.cloud.google.com/billing) to the project you deploy to.
5959

60+
## Importing Existing Resources
61+
62+
The Nitric team is working to expand the list of resources that can be imported. Currently, only the following resources are supported:
63+
64+
- [Secrets](/secrets)
65+
66+
<Note>
67+
Only resources in the same GCP project as specified by gcp-project-id are
68+
currently supported.
69+
</Note>
70+
71+
### Secrets
72+
73+
To import a secret, you will need to know the secret's unique name. You can find the name of a secret in the Google Cloud Secret Manager in the browser or by using the gcloud CLI.
74+
75+
First, add the secret to your project as you usually would if it wasn't imported. Then add the secret to the `import` section of your stack file. Here's an example of how to import a secret:
76+
77+
```javascript
78+
import { secret } from "@nitric/sdk
79+
80+
const mySecret = secret("credentials").allow("access");
81+
```
82+
83+
```yaml
84+
import:
85+
secrets:
86+
credentials: existing-secret
87+
```
88+
89+
Need to import another resource type or have another question? Chat with us on [Discord](https://nitric.io/chat) or [open an issue](https://github.com/nitrictech/nitric/issues) on GitHub.
90+
6091
## Stack Configuration
6192

6293
```yaml title:nitric.[stack ID].yaml

next.config.mjs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -517,6 +517,12 @@ const nextConfig = {
517517
basePath: false,
518518
permanent: true,
519519
},
520+
{
521+
source: '/docs/providers/pulumi/aws/imports',
522+
destination: '/docs/providers/pulumi/aws#importing-existing-resources',
523+
basePath: false,
524+
permanent: true,
525+
},
520526
{
521527
source: '/docs/reference/providers/aws/configuration',
522528
destination: '/docs/providers/pulumi/aws#stack-configuration',

0 commit comments

Comments
 (0)