Skip to content

Commit e418f32

Browse files
authored
Add documentation for the replaceWith resource option (#16727)
* Make it so * Claude * Spacing * Linting? * ????
1 parent 75e9af2 commit e418f32

File tree

2 files changed

+131
-0
lines changed

2 files changed

+131
-0
lines changed

content/docs/iac/concepts/resources/options/_index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ Resource constructors accept the following resource options:
2424
- [customTimeouts](/docs/concepts/options/customtimeouts/): override the default retry/timeout behavior for resource provisioning. The default value varies by resource.
2525
- [deleteBeforeReplace](/docs/concepts/options/deletebeforereplace/): override the default create-before-delete behavior when replacing a resource.
2626
- [deletedWith](/docs/concepts/options/deletedwith/): If set, the provider's Delete method will not be called for this resource if the specified resource is being deleted as well.
27+
- [replaceWith](/docs/concepts/options/replacewith/): If set, the resource will be replaced if one of the specified resources is replaced.
2728
- [dependsOn](/docs/concepts/options/dependson/): specify additional explicit dependencies in addition to the ones in the dependency graph.
2829
- [hideDiffs](/docs/concepts/options/hidediffs/): compact the display of diffs for specified properties in CLI output without affecting update behavior.
2930
- [hooks](/docs/concepts/options/hooks/): specify a set of resource hooks that will be executed at specific points in the resource lifecycle.
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
---
2+
title_tag: "replacewith | Resource Options"
3+
meta_desc: The replacewith resource option allows for explicit replace dependencies to be declared between resources.
4+
title: "replacewith"
5+
h1: "Resource option: replaceWith"
6+
meta_image: /images/docs/meta-images/docs-meta.png
7+
menu:
8+
iac:
9+
identifier: replaceWith
10+
parent: options-concepts
11+
weight: 5
12+
aliases:
13+
- /docs/intro/concepts/resources/options/replacewith/
14+
- /docs/concepts/options/replacewith/
15+
- /docs/iac/concepts/options/replacewith/
16+
---
17+
18+
The `replaceWith` resource option allows you to force a replace operation on the current resource every time one of the given resources is replaced.
19+
20+
However, not all relationships are visible to Pulumi: perhaps there are differences in behavior between providers, or your application introduces its own specific relationships, such as two services that depend on one another and thus must always be replaced together.
21+
22+
In these cases, you can use `replaceWith` to make these relationships explicit to the Pulumi engine. In the following example, an explicit dependency is declared: whenever the database is replaced, we must also replace the server.
23+
24+
{{< chooser language "typescript,python,go,csharp,java,yaml" >}}
25+
26+
{{% choosable language typescript %}}
27+
28+
```typescript
29+
import * as pulumi from "@pulumi/pulumi";
30+
import * as aws from "@pulumi/aws";
31+
32+
const database = new aws.rds.Instance('app-db', { /* ... */ });
33+
const application = new aws.ec2.Instance('app-service', { /* ... */ }, {
34+
replaceWith: [database]
35+
})
36+
```
37+
38+
{{% /choosable %}}
39+
{{% choosable language python %}}
40+
41+
```python
42+
import pulumi
43+
import pulumi_aws as aws
44+
45+
database = aws.rds.Instance('app-db', {})
46+
application = aws.ec2.Instance('app-service', {},
47+
opts=pulumi.ResourceOptions(replace_with=[database])
48+
)
49+
```
50+
51+
{{% /choosable %}}
52+
{{% choosable language go %}}
53+
54+
```go
55+
import (
56+
"github.com/pulumi/pulumi-aws/sdk/v6/go/aws/ec2"
57+
"github.com/pulumi/pulumi-aws/sdk/v6/go/aws/rds"
58+
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
59+
)
60+
61+
database, err := rds.NewInstance(ctx, "app-db", &rds.InstanceArgs{ ... })
62+
if err != nil {
63+
return err
64+
}
65+
66+
application, err := ec2.NewInstance(ctx, "app-service", &ec2.InstanceArgs{ ... },
67+
pulumi.ReplaceWith([]pulumi.Resource{database}))
68+
if err != nil {
69+
return err
70+
}
71+
```
72+
73+
{{% /choosable %}}
74+
{{% choosable language csharp %}}
75+
76+
```csharp
77+
using Pulumi;
78+
using Aws = Pulumi.Aws;
79+
80+
var database = new Aws.Rds.Instance("app-db", new() { ... });
81+
var application = new Aws.Ec2.Instance("app-service", new() { ... }, new CustomResourceOptions
82+
{
83+
ReplaceWith = new[]
84+
{
85+
database,
86+
},
87+
});
88+
```
89+
90+
{{% /choosable %}}
91+
{{% choosable language java %}}
92+
93+
```java
94+
import com.pulumi.aws.ec2.Instance;
95+
import com.pulumi.aws.ec2.InstanceArgs;
96+
import com.pulumi.resources.CustomResourceOptions;
97+
98+
var database = new com.pulumi.aws.rds.Instance("app-db",
99+
com.pulumi.aws.rds.InstanceArgs.builder()
100+
.build());
101+
102+
var application = new Instance("app-service",
103+
InstanceArgs.builder()
104+
.build(),
105+
CustomResourceOptions.builder()
106+
.replaceWith(database)
107+
.build());
108+
```
109+
110+
{{% /choosable %}}
111+
{{% choosable language yaml %}}
112+
113+
```yaml
114+
resources:
115+
database:
116+
type: aws:rds:Instance
117+
properties:
118+
# ...
119+
application:
120+
type: aws:ec2:Instance
121+
properties:
122+
# ...
123+
options:
124+
replaceWith:
125+
- ${database}
126+
```
127+
128+
{{% /choosable %}}
129+
130+
{{< /chooser >}}

0 commit comments

Comments
 (0)