pulumi/pkg/engine/lifecycletest
Will Jones 4e90fcb781 Implement the `CreateIfNotExists` resource option
This commit implements `CreateIfNotExists`, a new resource option that
allows programs to specify resource options that should be created only
if they do not already exist in the provider. Use cases for this feature
include "global" or shared resources, such as AWS service-linked
providers within an account, or SSL policies within a GCP
account/project. `CreateIfNotExists` behaves as follows:

* The option accepts an ID, much like `Import`, that will be used to
  determine whether or not a resource exists using a `Read` operation.
  If it does, resource inputs must match as they would be required to in
  an ordinary import. If not, the resource is created as usual.

* Due to the semantics specified above, it is an error to specify both
  `CreateIfNotExists` and `Import` resource options on a single
  resource.

The "if not exists" part is handled by a provider `Read` call that we
make in step generation. This is not ideal, since we'd like step
generation to be non-blocking (and `Read` could block for an arbitrary
amount of time). However, there aren't many other good options for
achieving this:

* Source evaluation would be a good middle ground, but this would
  require changing the contract of `Read`/introducing another call since
  we do not have a URN at this point.
* Parallelising step generation (see e.g. #15026). This is the "best"
  outcome and feels the most correct, but carries a large amount of risk.

There _are_ instances of us breaking this rule (not blocking in step
generation) already (e.g. `Check` and `Diff`, which "should" be fast but
in reality could do anything they like), and the hypothesis is that
there won't be many resources with this option in a given stack, so this
feels like an acceptable compromise.

A set of lifecycle tests capturing `CreateIfNotExists`' interactions
with existing resource options and scenarios are included. This commit
does not include SDK updates to use the new option; these will be
introduced in future changesets.

Part of #16189
2024-07-02 17:27:42 +01:00
..
testdata Implement the `CreateIfNotExists` resource option 2024-07-02 17:27:42 +01:00
alias_test.go Add display to the engine tests (#16050) 2024-05-13 07:18:25 +00:00
analyzer_test.go Add display to the engine tests (#16050) 2024-05-13 07:18:25 +00:00
continue_on_error_test.go Fix --continue-on-error running indefinitely when a resource fails to be created or updated (#16371) 2024-06-13 15:42:57 +00:00
create_if_not_exists_test.go Implement the `CreateIfNotExists` resource option 2024-07-02 17:27:42 +01:00
delete_before_replace_test.go Add display to the engine tests (#16050) 2024-05-13 07:18:25 +00:00
golang_sdk_test.go Add display to the engine tests (#16050) 2024-05-13 07:18:25 +00:00
import_test.go Normalize plugin.Provider methods to (Context, Request) -> (Response, error) (#16302) 2024-06-07 19:47:49 +00:00
parameterized_test.go Keep package refs separate from providers (#16458) 2024-06-24 14:59:18 +00:00
pending_delete_test.go Add display to the engine tests (#16050) 2024-05-13 07:18:25 +00:00
pending_replace_test.go Don't re-delete resources that are `PendingReplacement` (#16510) 2024-06-28 23:16:20 +00:00
provider_test.go Add display to the engine tests (#16050) 2024-05-13 07:18:25 +00:00
pulumi_test.go Display `[retain]` in all cases of delete retention (#16506) 2024-06-28 23:19:26 +00:00
refresh_legacy_diff_test.go Change `pulumi refresh` to report diff relative to desired state instead of relative to only output changes (#16146) 2024-06-12 16:17:05 +00:00
refresh_test.go Don't call `Diff` when refreshing external resources (#16544) 2024-07-02 10:11:10 +00:00
resource_reference_test.go Add display to the engine tests (#16050) 2024-05-13 07:18:25 +00:00
retain_on_delete_test.go Display `[retain]` in all cases of delete retention (#16506) 2024-06-28 23:19:26 +00:00
source_query_test.go deploytest/RegisterResource: return struct instead of values (#15988) 2024-04-19 11:08:56 +00:00
step_generator_test.go Add display to the engine tests (#16050) 2024-05-13 07:18:25 +00:00
target_test.go Propagate deleted dependencies of untargeted resources (#16247) 2024-05-23 12:31:03 +00:00
test_plan.go Normalize plugin.Provider methods to (Context, Request) -> (Response, error) (#16302) 2024-06-07 19:47:49 +00:00
transformation_test.go resolve providers in the engine before running transforms (#16409) 2024-06-21 08:55:17 +00:00
update_plan_test.go Add display to the engine tests (#16050) 2024-05-13 07:18:25 +00:00