pulumi / pulumi-converter-terraform

Apache License 2.0
9 stars 2 forks source link

xxx already declared error #172

Open brianmay opened 1 month ago

brianmay commented 1 month ago

What happened?

Trying to import my terraform state, I get the error:

 $ pulumi import --from terraform ~/tree/.../terraform.tfstate
[...]
error: anonymous.pp:0,0-9,2: "test_s3" already declared; "test_s3" already declared, and 5 other diagnostic(s)

Strongly suspect this is because the terraform has multiple resource types with the same id:

data "aws_iam_policy_document" "test_s3" {
  statement {
    effect = "Allow"

    actions = [
      "s3:List*",
      "s3:Get*",
      "s3:PutObject",
      "s3:DeleteObject"
    ]

    resources = [
      "${test_s3_bucket.geoip.arn}/*",
      "${test_s3_bucket.geoip.arn}"
    ]
  }
}

resource "aws_iam_policy" "test_s3" {
  name        = "test_s3"
  path        = "/"
  description = "IAM policy for accessing test s3 bucket"
  policy      = data.aws_iam_policy_document.test_s3.json
  tags        = local.tags
}

resource "aws_iam_role_policy_attachment" "test_s3" {
  role       = aws_iam_role.test_update.name
  policy_arn = aws_iam_policy.test_s3.arn
}

But this should be legal.

Example

See test case: https://github.com/brianmay/pulumi_2169

Output of pulumi about

base-5.2$ pulumi about
warning: using pulumi-language-go from $PATH at /nix/store/j1kjljhp66ia1ml9ssj47mglm25v09pf-pulumi-language-go-3.122.0/bin/pulumi-language-go
Enter your passphrase to unlock config/secrets
    (set PULUMI_CONFIG_PASSPHRASE or PULUMI_CONFIG_PASSPHRASE_FILE to remember):
Enter your passphrase to unlock config/secrets
CLI
Version      3.122.0
Go Version   go1.22.5
Go Compiler  gc

Plugins
NAME  VERSION
aws   6.44.0
go    unknown

Host
OS       darwin
Version  14.5
Arch     arm64

This project is written in go: executable='/nix/store/05saqcgidraqmn4z82prsp7rbj9hjmwm-go-1.22.5/bin/go' version='go version go1.22.5 darwin/arm64'

Current Stack: organization/simple/test

TYPE                                               URN
pulumi:pulumi:Stack                                urn:pulumi:test::simple::pulumi:pulumi:Stack::simple-test
pulumi:providers:aws                               urn:pulumi:test::simple::pulumi:providers:aws::default_6_44_0
aws:iam/rolePolicyAttachment:RolePolicyAttachment  urn:pulumi:test::simple::aws:iam/rolePolicyAttachment:RolePolicyAttachment::test_s3
aws:iam/policy:Policy                              urn:pulumi:test::simple::aws:iam/policy:Policy::test_s3
aws:iam/role:Role                                  urn:pulumi:test::simple::aws:iam/role:Role::test_update
aws:s3/bucketV2:BucketV2                           urn:pulumi:test::simple::aws:s3/bucketV2:BucketV2::test

Found no pending operations associated with test

Backend
Name           MEL
URL            file://~
User           brmay
Organizations
Token type     personal

Dependencies:
NAME                                 VERSION
github.com/pulumi/pulumi-aws/sdk/v6  6.44.0
github.com/pulumi/pulumi/sdk/v3      3.121.0

Pulumi locates its logs in /tmp/brmay/nix-shell.Podmtd by default

Additional context

I reported here because it seems to be related to terraform state, and this seems to be the project for that. Apologise if I reported the bug in the wrong place... Please do let me know if that is the case.

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

VenelinMartinov commented 1 month ago

Hey @brianmay, thanks for reporting the issue and sorry you had trouble here.

This does indeed look like a bug and I'll transfer it to the repo which does the TF state conversion - confusingly it is not the terraform-bridge.

justinvp commented 1 month ago

Thanks for opening the issue!

dishu2511 commented 3 weeks ago

I'm facing a similar issue where I'm trying to import both S3 and its bucket policy, but they both share the same ID. I'm currently running an older version of Pulumi (v3.92.0) on a test VM, and it works fine with this version. However, the pipeline uses the latest version of Pulumi, which is where the issue appears. Edit: Seems like the version v3.98.0 introduced this bug.