A question on importing existing resources into Pu...
# general
s
A question on importing existing resources into Pulumi using the
import
resource option: The docs state that:
The resulting Pulumi program, after the import is complete, will faithfully generate the same desired state as your existing infrastructure’s actual state.
Because of this, all properties need to be fully specified. If you forget to specify a property, or that property’s value is incorrect, you’ll first receive a warning during preview, and then an error during the actual import update.
But that isn’t matching the behavior that I’m seeing with regards to unspecified properties.
(This is for a Python-GCP project) I am importing a
gcp.container.Cluster
resource by specifying the
import_
option, and I can leave off the majority of the options and still have the preview portion of
pulumi up
succeed with no warning. I can see in the
details
of the preview that the unspecified fields are properly being pulled in from the imported resource (e.g, the nodepools on the cluster). Three specific questions: 1. If I go through with
pulumi up
, can I guarantee that it will not modify any of the existing resources as long as
import_
is in place? 2. If I then remove the
import_
option with those unspecified options unchanged, would it then modify the resources and (e.g.) delete the nodepools that are present on the cluster? 3. After the initial
pulumi up
has been run to import the resource, do I have to remove the
import_
command? a. We are swapping from manually-managed to pulumi-managed infrastructure gradually, so allowing the two to coexist might be nice, especially if the answer to 2. is ‘yes’
l
Did you not get errors? The docs (just below where you linked) say you should get an error if your code doesn't match the imported resource's in-provider configuration.
Generally, the correct thing to do is to update your code to match the actual configuration (which is why there are warnings and errors, as documented), import, then remove the import option.
a
You can also use the
pulumi import
CLI command, which might be easier than trying to do it via code. It's what I usually do. Pulumi imports just change the state file, not the resources themselves.
s
Does anyone use the
pulumi import
command to generate Pulumi code as mentioned in docs? It seems like a good option - how well does it work?
a
I use the CLI version from time to time. No issues there, if I remember to reference the provider correctly. Usually it's not needed, but in my case it's needed.
s
Generally, the correct thing to do is to update your code to match the actual configuration (which is why there are warnings and errors, as documented), import, then remove the import option.
I did not get any warnings on the preview, which is at the heart of my question. I’m hesitant to go through with the
up
operation, because I am not confident it will run without modifying the state on the server — especially because removing (most) fields does not affect whether an warning is raised.
Does anyone use the
pulumi import
command to generate Pulumi code as mentioned in docs?
I did attempt to use that — for gcp/python I got some warnings about the fields that were set in the imported definitions being incompatible with one another. Right now I am leaning towards just recreating new infrastructure with pulumi and not attempting to migrate my existing infrastructure over at all. It seems like it’s less risky if I do not want to accidentally modify the properties of the legacy infrastructure