@startuml
hide empty description

[*] --> Read: read existing resource
[*] --> Import: import existing resource
[*] --> Manage: manage resource

state Read {
	state "Read(reg.URN, reg.ID, reg.State)" as read_read

	read_read --> [*]
}

state Import {
	state "Read(reg.URN, reg.ID)" as import_read
	state "Check(reg.URN, reg.Inputs, read.Inputs)" as import_check
	state "Diff(reg.URN, check.Inputs, read.State)" as import_diff

	import_read --> import_check
	import_check --> import_diff
	import_diff --> [*]
}

state Manage {
	state "Check(reg.URN, reg.Inputs, last?.Inputs)" as manage_check
	state "Create(reg.URN, check.Inputs)" as manage_create
	state "Diff(reg.URN, check.Inputs, last.ID, last.State)" as manage_diff
	state "Update(reg.URN, last.ID, last.State)" as manage_update
	state "Check(reg.URN, reg.Inputs)" as manage_replace_check
	state "Create(reg.URN, reg.Inputs)" as manage_replace_create_before_delete
	state "Delete(reg.URN, last.ID, last.State)" as manage_replace_delete_after_create
	state "Delete dependents" as manage_replace_delete_dependents
	state "Delete(reg.URN, last.ID, last.State)" as manage_replace_delete_before_create
	state "Create(reg.URN, check.Inputs)" as manage_replace_create_after_delete

	manage_replace_delete_after_create: note that this step happens once the Pulumi program has exited

	manage_check --> manage_create: no last state
	manage_check --> manage_diff: has last state
	manage_diff --> manage_update: can be updated
	manage_diff --> manage_replace_check: must be replaced
	manage_replace_check --> manage_replace_create_before_delete: create before delete
	manage_replace_check --> manage_replace_delete_dependents: delete after craete
	manage_replace_create_before_delete --> manage_replace_delete_after_create
	manage_replace_delete_dependents --> manage_replace_delete_before_create
	manage_replace_delete_before_create --> manage_replace_create_after_delete
	manage_create --> [*]
	manage_update --> [*]
	manage_replace_delete_after_create --> [*]
	manage_replace_create_after_delete --> [*]
}
@enduml
