question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

EC2 - Unable to import Instance

See original GitHub issue

Hello!

  • Vote on this issue by adding a 👍 reaction
  • To contribute a fix for this issue, leave a comment (and link to your pull request, if you’ve opened one already)

Steps to reproduce

  1. In AWS, create a new EC2 instance (and stop it eventually)
  2. Create a new Pulumi project and stack (I used typescript) and set the region to the region used to create your EC2 instance
  3. Run the following command to import the instance into your project pulumi import aws:ec2/instance:Instance TestInstance i-0e122bd18c42c7373

Expected: The resource is imported into the stack, TypeScript code is generated. Actual: The command fails to complete. Output below.

~$ pulumi import aws:ec2/instance:Instance TestInstance i-0e122bd18c42c7373
Previewing import (dev)

View Live: <removed>

     Type                 Name               Plan       Info
 +   pulumi:pulumi:Stack  pulumi-import-dev  create     1 error
 =   └─ aws:ec2:Instance  TestInstance       import     4 errors
 
Diagnostics:
  pulumi:pulumi:Stack (pulumi-import-dev):
    error: preview failed
 
  aws:ec2:Instance (TestInstance):
    error: aws:ec2/instance:Instance resource 'TestInstance' has a problem: AtLeastOne: "instance_type": one of `instance_type,launch_template` must be specified. Examine values at 'Instance.InstanceType'.
    error: aws:ec2/instance:Instance resource 'TestInstance' has a problem: AtLeastOne: "launch_template": one of `ami,instance_type,launch_template` must be specified. Examine values at 'Instance.LaunchTemplate'.
    error: aws:ec2/instance:Instance resource 'TestInstance' has a problem: AtLeastOne: "ami": one of `ami,launch_template` must be specified. Examine values at 'Instance.Ami'.
    error: Preview failed: one or more inputs failed to validate

Environment:

  • Debian 10 (up to date)
  • Pulumi 3.10.2
  • NodeJS v16.6.0
  • Npm modules
pulumi-import@ /<removed>/pulumi-import
├── @pulumi/aws@4.16.0
├── @pulumi/awsx@0.30.0
├── @pulumi/pulumi@3.10.3
└── @types/node@10.17.60

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:3
  • Comments:12 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
joeduffycommented, Aug 22, 2021

Unless I am mistaken, the root cause is this:

https://github.com/pulumi/pulumi/blob/da2bd2ab043f2588b3a136846da1b97505326f25/pkg/resource/deploy/step.go#L935-L938

This limits the propagation of read properties to inputs based on IsRequired. There are plenty of non-required properties that are valid inputs. In this specific case, for example, I assume we can’t tell from the schema alone that the AtLeastOne constraints exist which are dynamically validated.

I tried removing that line (since the iteration is already limited to input properties only), but that just yielded more problems:

    error: aws:ec2/instance:Instance resource 'web-server-www' has a problem: ConflictsWith: "network_interface": conflicts with associate_public_ip_address. Examine values at 'Instance.NetworkInterfaces'.
    error: aws:ec2/instance:Instance resource 'web-server-www' has a problem: Computed attributes cannot be set: Computed attributes cannot be set, but a value was set for "root_block_device.0.device_name".. Examine values at 'Instance.RootBlockDevice.DeviceName'.
    error: aws:ec2/instance:Instance resource 'web-server-www' has a problem: Computed attributes cannot be set: Computed attributes cannot be set, but a value was set for "root_block_device.0.volume_id".. Examine values at 'Instance.RootBlockDevice.VolumeId'.
    error: Preview failed: one or more inputs failed to validate

I think we may need to deeply strip out “empty” values like maps, arrays, etc, but it’s even more complicated because they contain __defaults properties and I actually don’t know why computed-only properties like root_block_device are in the input property set from the schema in the first place.

0reactions
mikhailshilkovcommented, Mar 18, 2022

Import functionality has been significantly refactored in #8922 to substantially reduce the number of failures during pulumi import and make the generated code more truthful and complete. We haven’t tested this exact issue, but we believe it’s addressed by the refactoring.

I’ll go ahead and close the issue - feel free if you still get issues with it after upgrading to the Pulumi CLI version 3.26.1 or above.

Read more about the changes in Easier IaC adoption with improved pulumi import experience.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Troubleshooting VM Import/Export - AWS Documentation
When you import a VM using the ec2-import-instance command, the import task might stop before its completed, and then fail. To investigate what...
Read more >
Unable to import my vmdk to EC2 [duplicate] - Super User
The error message suggests you are not in the correct region. According to the AWS documentation you need to specify a zone.
Read more >
Unable to import module 'index': Error on Amazon Linux EC2 ...
Hi i am seeing the aforementioned error error while running the command "sam local invoke "HelloWorld" -e input/events.json " from the directory where...
Read more >
Unable to import EC2 instance with pulumi import command
I am running an EC2 instance on aws which I need to import to pulumi by running the following command pulumi import -f...
Read more >
How do I resolve the "Unable to import module ... - YouTube
... Knowledge Center article with this video: https:// aws.amazon.com/premiumsupport/knowledge-center/lambda- import -module-error-python/0...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found