Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Import generates conflicting keys #78

Closed
GeoffMillerAZ opened this issue Oct 22, 2023 · 2 comments
Closed

Import generates conflicting keys #78

GeoffMillerAZ opened this issue Oct 22, 2023 · 2 comments
Assignees
Labels
kind/bug Some behavior is incorrect or out of spec resolution/fixed This issue was fixed
Milestone

Comments

@GeoffMillerAZ
Copy link

What happened?

When the import from terraform command is used, it imports conflicting keys. See the example for aws_subnet.

The error message tells me that Pulumi can detect conflicting keys. This could automatically address this issue and make the import experience smooth and fast.

Example

variable "profile" {
  type    = string
  default = "ce_admin"
}

provider "aws" {
  profile = var.profile
  region  = "us-west-2"
}

locals {
  azs = ["a", "b", "c"]
}

data "aws_region" "default" {}

data "aws_availability_zone" "default" {
  for_each = toset(local.azs)
  name     = format("%s%s", data.aws_region.default.name, each.key)
}

resource "aws_vpc" "vpc" {
  cidr_block = "10.0.0.0/16"
  tags = {
    "Name"   = "testingImportIssueOnIndexes"
    "Region" = data.aws_region.default.name
  }
}

resource "aws_subnet" "a" {
  for_each          = toset(local.azs)
  vpc_id            = aws_vpc.vpc.id
  cidr_block        = cidrsubnet(aws_vpc.vpc.cidr_block, 4, index(local.azs, each.key))
  availability_zone = data.aws_availability_zone.default[each.key].name
  tags = {
    "Name" = "subnet-a-${each.key}"
  }
}

resource "aws_subnet" "b" {
  count             = length(local.azs)
  vpc_id            = aws_vpc.vpc.id
  cidr_block        = cidrsubnet(aws_vpc.vpc.cidr_block, 4, (length(local.azs) + count.index))
  availability_zone = data.aws_availability_zone.default[local.azs[count.index]].name
  tags = {
    "Name" = format("subnet-b-%s", count.index)
  }
}

pulumi import --from terraform terraform.tfstate

    Type                 Name                    Status               Info
 +   pulumi:pulumi:Stack  import_index_match-dev  created (3s)
 =   ├─ aws:ec2:Subnet    a-a                     imported (0.85s)     3 warnings
 =   ├─ aws:ec2:Subnet    a-b                     imported (0.86s)     3 warnings
 =   ├─ aws:ec2:Subnet    b-0                     imported (0.85s)     3 warnings
 =   ├─ aws:ec2:Subnet    a-c                     imported (0.94s)     3 warnings
 =   ├─ aws:ec2:Subnet    b-1                     imported (0.95s)     3 warnings
 =   ├─ aws:ec2:Subnet    b-2                     imported (1s)        3 warnings
 =   └─ aws:ec2:Vpc       vpc                     imported (1s)

The imports aligned with mismatching configuration:

Diagnostics:
  aws:ec2:Subnet (a-c):
    warning: One or more imported inputs failed to validate. This is almost certainly a bug in the `aws` provider. The import will still proceed, but you will need to edit the generated code after copying it into your program.
    warning: aws:ec2/subnet:Subnet resource 'a-c' has a problem: Conflicting configuration arguments: "availability_zone": conflicts with availability_zone_id. Examine values at 'a-c.availabilityZone'.
    warning: aws:ec2/subnet:Subnet resource 'a-c' has a problem: Conflicting configuration arguments: "availability_zone_id": conflicts with availability_zone. Examine values at 'a-c.availabilityZoneId'.

  aws:ec2:Subnet (b-1):
    warning: One or more imported inputs failed to validate. This is almost certainly a bug in the `aws` provider. The import will still proceed, but you will need to edit the generated code after copying it into your program.
    warning: aws:ec2/subnet:Subnet resource 'b-1' has a problem: Conflicting configuration arguments: "availability_zone_id": conflicts with availability_zone. Examine values at 'b-1.availabilityZoneId'.
    warning: aws:ec2/subnet:Subnet resource 'b-1' has a problem: Conflicting configuration arguments: "availability_zone": conflicts with availability_zone_id. Examine values at 'b-1.availabilityZone'.

  aws:ec2:Subnet (b-2):
    warning: One or more imported inputs failed to validate. This is almost certainly a bug in the `aws` provider. The import will still proceed, but you will need to edit the generated code after copying it into your program.
    warning: aws:ec2/subnet:Subnet resource 'b-2' has a problem: Conflicting configuration arguments: "availability_zone": conflicts with availability_zone_id. Examine values at 'b-2.availabilityZone'.
    warning: aws:ec2/subnet:Subnet resource 'b-2' has a problem: Conflicting configuration arguments: "availability_zone_id": conflicts with availability_zone. Examine values at 'b-2.availabilityZoneId'.

  aws:ec2:Subnet (a-a):
    warning: One or more imported inputs failed to validate. This is almost certainly a bug in the `aws` provider. The import will still proceed, but you will need to edit the generated code after copying it into your program.
    warning: aws:ec2/subnet:Subnet resource 'a-a' has a problem: Conflicting configuration arguments: "availability_zone": conflicts with availability_zone_id. Examine values at 'a-a.availabilityZone'.
    warning: aws:ec2/subnet:Subnet resource 'a-a' has a problem: Conflicting configuration arguments: "availability_zone_id": conflicts with availability_zone. Examine values at 'a-a.availabilityZoneId'.

  aws:ec2:Subnet (a-b):
    warning: One or more imported inputs failed to validate. This is almost certainly a bug in the `aws` provider. The import will still proceed, but you will need to edit the generated code after copying it into your program.
    warning: aws:ec2/subnet:Subnet resource 'a-b' has a problem: Conflicting configuration arguments: "availability_zone_id": conflicts with availability_zone. Examine values at 'a-b.availabilityZoneId'.
    warning: aws:ec2/subnet:Subnet resource 'a-b' has a problem: Conflicting configuration arguments: "availability_zone": conflicts with availability_zone_id. Examine values at 'a-b.availabilityZone'.

  aws:ec2:Subnet (b-0):
    warning: One or more imported inputs failed to validate. This is almost certainly a bug in the `aws` provider. The import will still proceed, but you will need to edit the generated code after copying it into your program.
    warning: aws:ec2/subnet:Subnet resource 'b-0' has a problem: Conflicting configuration arguments: "availability_zone": conflicts with availability_zone_id. Examine values at 'b-0.availabilityZone'.
    warning: aws:ec2/subnet:Subnet resource 'b-0' has a problem: Conflicting configuration arguments: "availability_zone_id": conflicts with availability_zone. Examine values at 'b-0.availabilityZoneId'.
import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";

const a_a = new aws.ec2.Subnet(
  "a-a",
  {
    availabilityZone: "us-west-2a",
    availabilityZoneId: "usw2-az2",
    cidrBlock: "10.0.0.0/20",
    privateDnsHostnameTypeOnLaunch: "ip-name",
    tags: {
      Name: "subnet-a-a",
    },
    vpcId: "vpc-0b3b92d37552381ce",
  },
  {
    protect: true,
  }
);
const a_b = new aws.ec2.Subnet(
  "a-b",
  {
    availabilityZone: "us-west-2b",
    availabilityZoneId: "usw2-az1",
    cidrBlock: "10.0.16.0/20",
    privateDnsHostnameTypeOnLaunch: "ip-name",
    tags: {
      Name: "subnet-a-b",
    },
    vpcId: "vpc-0b3b92d37552381ce",
  },
  {
    protect: true,
  }
);
const a_c = new aws.ec2.Subnet(
  "a-c",
  {
    availabilityZone: "us-west-2c",
    availabilityZoneId: "usw2-az3",
    cidrBlock: "10.0.32.0/20",
    privateDnsHostnameTypeOnLaunch: "ip-name",
    tags: {
      Name: "subnet-a-c",
    },
    vpcId: "vpc-0b3b92d37552381ce",
  },
  {
    protect: true,
  }
);
const b_0 = new aws.ec2.Subnet(
  "b-0",
  {
    availabilityZone: "us-west-2a",
    availabilityZoneId: "usw2-az2",
    cidrBlock: "10.0.48.0/20",
    privateDnsHostnameTypeOnLaunch: "ip-name",
    tags: {
      Name: "subnet-b-0",
    },
    vpcId: "vpc-0b3b92d37552381ce",
  },
  {
    protect: true,
  }
);
const b_1 = new aws.ec2.Subnet(
  "b-1",
  {
    availabilityZone: "us-west-2b",
    availabilityZoneId: "usw2-az1",
    cidrBlock: "10.0.64.0/20",
    privateDnsHostnameTypeOnLaunch: "ip-name",
    tags: {
      Name: "subnet-b-1",
    },
    vpcId: "vpc-0b3b92d37552381ce",
  },
  {
    protect: true,
  }
);
const b_2 = new aws.ec2.Subnet(
  "b-2",
  {
    availabilityZone: "us-west-2c",
    availabilityZoneId: "usw2-az3",
    cidrBlock: "10.0.80.0/20",
    privateDnsHostnameTypeOnLaunch: "ip-name",
    tags: {
      Name: "subnet-b-2",
    },
    vpcId: "vpc-0b3b92d37552381ce",
  },
  {
    protect: true,
  }
);
const vpc = new aws.ec2.Vpc(
  "vpc",
  {
    cidrBlock: "10.0.0.0/16",
    tags: {
      Name: "testingImportIssueOnIndexes",
      Region: "us-west-2",
    },
  },
  {
    protect: true,
  }
);

pulumi up

Diagnostics:
  aws:ec2:Subnet (a-b):
    error: aws:ec2/subnet:Subnet resource 'a-b' has a problem: Conflicting configuration arguments: "availability_zone_id": conflicts with availability_zone. Examine values at 'a-b.availabilityZoneId'.
    error: aws:ec2/subnet:Subnet resource 'a-b' has a problem: Conflicting configuration arguments: "availability_zone": conflicts with availability_zone_id. Examine values at 'a-b.availabilityZone'.

but commenting out one of the conflicting keys works

const a_a = new aws.ec2.Subnet(
  "a-a",
  {
    // availabilityZone: "us-west-2a",
    availabilityZoneId: "usw2-az2",
    cidrBlock: "10.0.0.0/20",
    privateDnsHostnameTypeOnLaunch: "ip-name",
    tags: {
      Name: "subnet-a-a",
    },
    vpcId: "vpc-0b3b92d37552381ce",
  },
  {
    protect: true,
  }
);

Output of pulumi about

pulumi about
CLI          
Version      3.89.0
Go Version   go1.21.3
Go Compiler  gc

Plugins
NAME    VERSION
aws     5.42.0
awsx    1.0.6
docker  3.6.1
nodejs  unknown

Host     
OS       darwin
Version  14.0
Arch     arm64

This project is written in nodejs: executable='/usr/local/bin/node' version='v18.18.0'

Current Stack: GeoffMillerAZ/import_index_match/dev

TYPE                   URN
pulumi:pulumi:Stack    urn:pulumi:dev::import_index_match::pulumi:pulumi:Stack::import_index_match-dev
pulumi:providers:aws   urn:pulumi:dev::import_index_match::pulumi:providers:aws::default_5_42_0
aws:ec2/subnet:Subnet  urn:pulumi:dev::import_index_match::aws:ec2/subnet:Subnet::b-0
aws:ec2/subnet:Subnet  urn:pulumi:dev::import_index_match::aws:ec2/subnet:Subnet::a-a
aws:ec2/subnet:Subnet  urn:pulumi:dev::import_index_match::aws:ec2/subnet:Subnet::a-b
aws:ec2/subnet:Subnet  urn:pulumi:dev::import_index_match::aws:ec2/subnet:Subnet::a-c
aws:ec2/subnet:Subnet  urn:pulumi:dev::import_index_match::aws:ec2/subnet:Subnet::b-1
aws:ec2/subnet:Subnet  urn:pulumi:dev::import_index_match::aws:ec2/subnet:Subnet::b-2
aws:ec2/vpc:Vpc        urn:pulumi:dev::import_index_match::aws:ec2/vpc:Vpc::vpc


Found no pending operations associated with dev

Backend        
Name           pulumi.com
URL            https://app.pulumi.com/GeoffMillerAZ
User           GeoffMillerAZ
Organizations  GeoffMillerAZ
Token type     personal

Dependencies:
NAME            VERSION
@pulumi/awsx    1.0.6
@pulumi/pulumi  3.89.0
@types/node     16.18.59
@pulumi/aws     5.42.0

Pulumi locates its logs in /var/folders/39/pjbcs1t54djdg68ptpxw5q880000gn/T/ by default

terraform version:

Terraform v1.5.7
on darwin_arm64
+ provider registry.terraform.io/hashicorp/aws v5.22.0

Additional context

No response

Contributing

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).

@GeoffMillerAZ GeoffMillerAZ added kind/bug Some behavior is incorrect or out of spec needs-triage Needs attention from the triage team labels Oct 22, 2023
@justinvp justinvp removed the needs-triage Needs attention from the triage team label Oct 30, 2023
@t0yv0
Copy link
Member

t0yv0 commented Jun 13, 2024

Trying this with the following stack:

CLI          
Version      3.117.0
Go Version   go1.22.3
Go Compiler  gc

Plugins
KIND      NAME    VERSION
resource  aws     6.40.0
resource  awsx    2.12.1
resource  docker  4.5.4
resource  docker  3.6.1
language  nodejs  unknown

Host     
OS       darwin
Version  14.5
Arch     arm64

This project is written in nodejs: executable='/Users/anton/bin/node' version='v18.18.2'

Current Stack: anton-pulumi-corp/pulumi-converter-terraform-78/dev

TYPE                   URN
pulumi:pulumi:Stack    urn:pulumi:dev::pulumi-converter-terraform-78::pulumi:pulumi:Stack::pulumi-converter-terraform-78-dev
pulumi:providers:aws   urn:pulumi:dev::pulumi-converter-terraform-78::pulumi:providers:aws::default_6_40_0
aws:ec2/subnet:Subnet  urn:pulumi:dev::pulumi-converter-terraform-78::aws:ec2/subnet:Subnet::b-0
aws:ec2/subnet:Subnet  urn:pulumi:dev::pulumi-converter-terraform-78::aws:ec2/subnet:Subnet::a-a
aws:ec2/subnet:Subnet  urn:pulumi:dev::pulumi-converter-terraform-78::aws:ec2/subnet:Subnet::b-1
aws:ec2/subnet:Subnet  urn:pulumi:dev::pulumi-converter-terraform-78::aws:ec2/subnet:Subnet::a-b
aws:ec2/subnet:Subnet  urn:pulumi:dev::pulumi-converter-terraform-78::aws:ec2/subnet:Subnet::a-c
aws:ec2/subnet:Subnet  urn:pulumi:dev::pulumi-converter-terraform-78::aws:ec2/subnet:Subnet::b-2
aws:ec2/vpc:Vpc        urn:pulumi:dev::pulumi-converter-terraform-78::aws:ec2/vpc:Vpc::vpc


Found no pending operations associated with dev

Backend        
Name           pulumi.com
URL            https://app.pulumi.com/anton-pulumi-corp
User           anton-pulumi-corp
Organizations  anton-pulumi-corp, moolumi, pulumi
Token type     personal

Dependencies:
NAME            VERSION
@pulumi/aws     6.40.0
@pulumi/awsx    2.12.1
@pulumi/pulumi  3.120.0
@types/node     18.19.34
typescript      5.4.5

Pulumi locates its logs in /var/folders/gd/3ncjb1lj5ljgk8xl5ssn_gvc0000gn/T/com.apple.shortcuts.mac-helper// by default

Getting:

Importing (dev)

View in Browser (Ctrl+O): https://app.pulumi.com/anton-pulumi-corp/pulumi-converter-terraform-78/dev/updates/1

     Type                 Name                               Status            Info
 +   pulumi:pulumi:Stack  pulumi-converter-terraform-78-dev  created           
 =   ├─ aws:ec2:Subnet    b-0                                imported (1s)     3 warnings
 =   ├─ aws:ec2:Subnet    b-1                                imported (1s)     3 warnings
 =   ├─ aws:ec2:Vpc       vpc                                imported (2s)     3 warnings
 =   ├─ aws:ec2:Subnet    a-c                                imported (1s)     3 warnings
 =   ├─ aws:ec2:Subnet    b-2                                imported (1s)     3 warnings
 =   ├─ aws:ec2:Subnet    a-b                                imported (1s)     3 warnings
 =   └─ aws:ec2:Subnet    a-a                                imported (1s)     3 warnings

Diagnostics:
  aws:ec2:Subnet (b-0):
    warning: Type checking failed: 
    warning: Unexpected type at field "tags.__defaults":
               expected string type, got [] type
    warning: Type checking is still experimental. If you believe that a warning is incorrect,
    please let us know by creating an issue at https://github.com/pulumi/pulumi-terraform-bridge/issues.
    This will become a hard error in the future.

  aws:ec2:Subnet (b-1):
    warning: Type checking failed: 
    warning: Unexpected type at field "tags.__defaults":
               expected string type, got [] type
    warning: Type checking is still experimental. If you believe that a warning is incorrect,
    please let us know by creating an issue at https://github.com/pulumi/pulumi-terraform-bridge/issues.
    This will become a hard error in the future.

  aws:ec2:Vpc (vpc):
    warning: Type checking failed: 
    warning: Unexpected type at field "tags.__defaults":
               expected string type, got [] type
    warning: Type checking is still experimental. If you believe that a warning is incorrect,
    please let us know by creating an issue at https://github.com/pulumi/pulumi-terraform-bridge/issues.
    This will become a hard error in the future.

  aws:ec2:Subnet (a-c):
    warning: Type checking failed: 
    warning: Unexpected type at field "tags.__defaults":
               expected string type, got [] type
    warning: Type checking is still experimental. If you believe that a warning is incorrect,
    please let us know by creating an issue at https://github.com/pulumi/pulumi-terraform-bridge/issues.
    This will become a hard error in the future.

  aws:ec2:Subnet (b-2):
    warning: Type checking failed: 
    warning: Unexpected type at field "tags.__defaults":
               expected string type, got [] type
    warning: Type checking is still experimental. If you believe that a warning is incorrect,
    please let us know by creating an issue at https://github.com/pulumi/pulumi-terraform-bridge/issues.
    This will become a hard error in the future.

  aws:ec2:Subnet (a-b):
    warning: Type checking failed: 
    warning: Unexpected type at field "tags.__defaults":
               expected string type, got [] type
    warning: Type checking is still experimental. If you believe that a warning is incorrect,
    please let us know by creating an issue at https://github.com/pulumi/pulumi-terraform-bridge/issues.
    This will become a hard error in the future.

  aws:ec2:Subnet (a-a):
    warning: Type checking failed: 
    warning: Unexpected type at field "tags.__defaults":
               expected string type, got [] type
    warning: Type checking is still experimental. If you believe that a warning is incorrect,
    please let us know by creating an issue at https://github.com/pulumi/pulumi-terraform-bridge/issues.
    This will become a hard error in the future.

Conflicting configuration arguments problem is fixed in the latest AWS provider.

However it looks like we have introduced a new unnecessary warning.

@t0yv0
Copy link
Member

t0yv0 commented Jun 13, 2024

I will close this issue as fixed but track pulumi/pulumi-terraform-bridge#2096 instead to remove the type checker warning.

@t0yv0 t0yv0 self-assigned this Jun 13, 2024
@t0yv0 t0yv0 added this to the 0.106 milestone Jun 13, 2024
@t0yv0 t0yv0 added the resolution/fixed This issue was fixed label Jun 13, 2024
@t0yv0 t0yv0 closed this as completed Jun 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Some behavior is incorrect or out of spec resolution/fixed This issue was fixed
Projects
None yet
Development

No branches or pull requests

3 participants