Skip to content

Commit a9d0279

Browse files
authored
Add --exclude and --exclude-dependents to the Automation API (#1781)
Copying the same structure of `targets` and `targetDependents`.
1 parent e8009ac commit a9d0279

File tree

6 files changed

+127
-1
lines changed

6 files changed

+127
-1
lines changed

CHANGELOG_PENDING.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,6 @@
22

33
* Support generating programs using the `import` resource option
44

5-
### Bug Fixes
5+
* Support `--exclude` and `--exclude-dependents` in the Automation API.
6+
7+
### Bug Fixes

sdk/java/pulumi/src/main/java/com/pulumi/automation/DestroyOptions.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,15 @@
77
* operation.
88
*/
99
public final class DestroyOptions extends UpdateOptions {
10+
private final boolean excludeDependents;
1011
private final boolean targetDependents;
1112
private final boolean showSecrets;
1213
private final boolean continueOnError;
1314
private final boolean previewOnly;
1415

1516
private DestroyOptions(Builder builder) {
1617
super(builder);
18+
this.excludeDependents = builder.excludeDependents;
1719
this.targetDependents = builder.targetDependents;
1820
this.showSecrets = builder.showSecrets;
1921
this.continueOnError = builder.continueOnError;
@@ -29,6 +31,16 @@ public static Builder builder() {
2931
return new Builder();
3032
}
3133

34+
/**
35+
* Allows exclusion of dependent targets discovered but not specified
36+
* {@link #excludes()}
37+
*
38+
* @return true if dependent targets should be excluded
39+
*/
40+
public boolean isExcludeDependents() {
41+
return excludeDependents;
42+
}
43+
3244
/**
3345
* Allows updating of dependent targets discovered but not specified
3446
* {@link #targets()}
@@ -70,6 +82,7 @@ public boolean previewOnly() {
7082
* Builder for {@link DestroyOptions}.
7183
*/
7284
public static final class Builder extends UpdateOptions.Builder<DestroyOptions.Builder> {
85+
private boolean excludeDependents;
7386
private boolean targetDependents;
7487
private boolean showSecrets;
7588
private boolean continueOnError;
@@ -78,6 +91,18 @@ public static final class Builder extends UpdateOptions.Builder<DestroyOptions.B
7891
private Builder() {
7992
}
8093

94+
/**
95+
* Allows exclusion of dependent targets discovered but not specified
96+
* {@link #excludes}.
97+
*
98+
* @param excludeDependents true if dependent targets should be excluded
99+
* @return the builder
100+
*/
101+
public Builder excludeDependents(boolean excludeDependents) {
102+
this.excludeDependents = excludeDependents;
103+
return this;
104+
}
105+
81106
/**
82107
* Allows updating of dependent targets discovered but not specified
83108
* {@link #targets}.

sdk/java/pulumi/src/main/java/com/pulumi/automation/PreviewOptions.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ public final class PreviewOptions extends UpdateOptions {
1919
private final boolean expectNoChanges;
2020
private final boolean diff;
2121
private final List<String> replaces;
22+
private final boolean excludeDependents;
2223
private final boolean targetDependents;
2324
@Nullable
2425
private final Consumer<Context> program;
@@ -34,6 +35,7 @@ private PreviewOptions(Builder builder) {
3435
this.replaces = builder.replaces == null
3536
? Collections.emptyList()
3637
: Collections.unmodifiableList(builder.replaces);
38+
this.excludeDependents = builder.excludeDependents;
3739
this.targetDependents = builder.targetDependents;
3840
this.program = builder.program;
3941
this.plan = builder.plan;
@@ -76,6 +78,16 @@ public List<String> replaces() {
7678
return replaces;
7779
}
7880

81+
/**
82+
* Allows exclusion of dependent targets discovered but not specified
83+
* {@link #excludes()}
84+
*
85+
* @return true if dependent targets should be excluded
86+
*/
87+
public boolean excludeDependents() {
88+
return excludeDependents;
89+
}
90+
7991
/**
8092
* Allows updating of dependent targets discovered but not specified
8193
* {@link #targets()}
@@ -125,6 +137,7 @@ public static final class Builder extends UpdateOptions.Builder<PreviewOptions.B
125137
private boolean diff;
126138
@Nullable
127139
private List<String> replaces;
140+
private boolean excludeDependents;
128141
private boolean targetDependents;
129142
@Nullable
130143
private Consumer<Context> program;
@@ -170,6 +183,18 @@ public Builder replaces(List<String> replaces) {
170183
return this;
171184
}
172185

186+
/**
187+
* Allows exclusion of dependent targets discovered but not specified
188+
* {@link #excludes()}
189+
*
190+
* @param excludeDependents true if dependent targets should be excluded
191+
* @return the builder
192+
*/
193+
public Builder excludeDependents(boolean excludeDependents) {
194+
this.excludeDependents = excludeDependents;
195+
return this;
196+
}
197+
173198
/**
174199
* Allows updating of dependent targets discovered but not specified
175200
* {@link #targets()}

sdk/java/pulumi/src/main/java/com/pulumi/automation/UpOptions.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ public final class UpOptions extends UpdateOptions {
1717
private final boolean expectNoChanges;
1818
private final boolean diff;
1919
private final List<String> replaces;
20+
private final boolean excludeDependents;
2021
private final boolean targetDependents;
2122
@Nullable
2223
private final Consumer<Context> program;
@@ -32,6 +33,7 @@ private UpOptions(Builder builder) {
3233
this.expectNoChanges = builder.expectNoChanges;
3334
this.diff = builder.diff;
3435
this.replaces = builder.replaces;
36+
this.excludeDependents = builder.excludeDependents;
3537
this.targetDependents = builder.targetDependents;
3638
this.program = builder.program;
3739
this.plan = builder.plan;
@@ -76,6 +78,16 @@ public List<String> replaces() {
7678
return replaces;
7779
}
7880

81+
/**
82+
* Allows exclusion of dependent targets discovered but not specified
83+
* {@link #excludes()}
84+
*
85+
* @return true if dependent targets should be excluded
86+
*/
87+
public boolean excludeDependents() {
88+
return excludeDependents;
89+
}
90+
7991
/**
8092
* Allows updating of dependent targets discovered but not specified
8193
* {@link #targets()}
@@ -143,6 +155,7 @@ public static final class Builder extends UpdateOptions.Builder<UpOptions.Builde
143155
private boolean diff;
144156
@Nullable
145157
private List<String> replaces;
158+
private boolean excludeDependents;
146159
private boolean targetDependents;
147160
@Nullable
148161
private Consumer<Context> program;
@@ -190,6 +203,18 @@ public Builder replaces(List<String> replaces) {
190203
return this;
191204
}
192205

206+
/**
207+
* Allows exclusion of dependent targets discovered but not specified
208+
* {@link #excludes}.
209+
*
210+
* @param excludeDependents true if dependent targets should be excluded
211+
* @return the builder
212+
*/
213+
public Builder excludeDependents(boolean excludeDependents) {
214+
this.excludeDependents = excludeDependents;
215+
return this;
216+
}
217+
193218
/**
194219
* Allows updating of dependent targets discovered but not specified
195220
* {@link #targets}.

sdk/java/pulumi/src/main/java/com/pulumi/automation/UpdateOptions.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ public abstract class UpdateOptions {
1919
private final Integer parallel;
2020
@Nullable
2121
private final String message;
22+
private final List<String> excludes;
2223
private final List<String> targets;
2324
private final List<String> policyPacks;
2425
private final List<String> policyPackConfigs;
@@ -42,6 +43,9 @@ public abstract class UpdateOptions {
4243
protected UpdateOptions(Builder<?> builder) {
4344
parallel = builder.parallel;
4445
message = builder.message;
46+
excludes = builder.excludes == null
47+
? Collections.emptyList()
48+
: Collections.unmodifiableList(builder.excludes);
4549
targets = builder.targets == null
4650
? Collections.emptyList()
4751
: Collections.unmodifiableList(builder.targets);
@@ -84,6 +88,16 @@ public String Message() {
8488
return message;
8589
}
8690

91+
/**
92+
* A list of resource URNs to exclude during the operation. Wildcards
93+
* (*, **) are also supported.
94+
*
95+
* @return the list of excluded resource URNs
96+
*/
97+
public List<String> excludes() {
98+
return excludes;
99+
}
100+
87101
/**
88102
* A list of resource URNs to target during the operation. Wildcards (*, **) are
89103
* also supported.
@@ -219,6 +233,8 @@ public static abstract class Builder<B extends Builder<B>> {
219233
@Nullable
220234
private String message;
221235
@Nullable
236+
private List<String> excludes;
237+
@Nullable
222238
private List<String> targets;
223239
@Nullable
224240
private List<String> policyPacks;
@@ -269,6 +285,19 @@ public B message(String message) {
269285
return (B) this;
270286
}
271287

288+
/**
289+
* A list of resource URNs to exclude during the operation. Wildcards
290+
* (*, **) are also supported.
291+
*
292+
* @param excludes the list of excluded resource URNs
293+
* @return the builder
294+
*/
295+
@SuppressWarnings("unchecked")
296+
public B excludes(List<String> excludes) {
297+
this.excludes = excludes;
298+
return (B) this;
299+
}
300+
272301
/**
273302
* A list of resource URNs to target during the operation. Wildcards (*, **) are
274303
* also supported.

sdk/java/pulumi/src/main/java/com/pulumi/automation/WorkspaceStack.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,10 @@ public UpResult up(UpOptions options) throws AutomationException {
422422
}
423423
}
424424

425+
if (options.excludeDependents()) {
426+
args.add("--exclude-dependents");
427+
}
428+
425429
if (options.targetDependents()) {
426430
args.add("--target-dependents");
427431
}
@@ -541,6 +545,10 @@ public PreviewResult preview(PreviewOptions options) throws AutomationException
541545
}
542546
}
543547

548+
if (options.excludeDependents()) {
549+
args.add("--exclude-dependents");
550+
}
551+
544552
if (options.targetDependents()) {
545553
args.add("--target-dependents");
546554
}
@@ -730,6 +738,10 @@ public UpdateResult destroy(DestroyOptions options) throws AutomationException {
730738
}
731739

732740
if (options != null) {
741+
if (options.isExcludeDependents()) {
742+
args.add("--exclude-dependents");
743+
}
744+
733745
if (options.isTargetDependents()) {
734746
args.add("--target-dependents");
735747
}
@@ -970,6 +982,14 @@ private static void applyUpdateOptions(UpdateOptions options, ArrayList<String>
970982
}
971983
}
972984

985+
var excludes = options.excludes();
986+
if (excludes != null) {
987+
for (var item : excludes) {
988+
args.add("--exclude");
989+
args.add(item);
990+
}
991+
}
992+
973993
var policyPacks = options.policyPacks();
974994
if (policyPacks != null) {
975995
for (var item : policyPacks) {

0 commit comments

Comments
 (0)