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

Support provider aliases #144

Open
t0yv0 opened this issue Apr 17, 2024 · 0 comments
Open

Support provider aliases #144

t0yv0 opened this issue Apr 17, 2024 · 0 comments
Labels
kind/enhancement Improvements or new features

Comments

@t0yv0
Copy link
Member

t0yv0 commented Apr 17, 2024

Hello!

  • Vote on this issue by adding a 👍 reaction
  • If you want to implement this feature, comment to let us know (we'll work with you on design, scheduling, etc.)

Issue details

variable "another_uid" {
  default = "xxxx"
}
# Method 1: Use assume_role to operate resources in the target cen account, detail see https://registry.terraform.io/providers/aliyun/alicloud/latest/docs#assume-role
provider "alicloud" {
  region = "cn-hangzhou"
  alias  = "child_account"
  assume_role {
    role_arn = "acs:ram::${var.another_uid}:role/terraform-example-assume-role"
  }
}

# Method 2: Use the target cen account's access_key, secret_key
# provider "alicloud" {
#   region     = "cn-hangzhou"
#   access_key = "access_key"
#   secret_key = "secret_key"
#   alias      = "child_account"
# }

provider "alicloud" {
  alias = "your_account"
}
data "alicloud_account" "your_account" {
  provider = alicloud.your_account
}
data "alicloud_account" "child_account" {
  provider = alicloud.child_account
}
data "alicloud_regions" "default" {
  current = true
}

resource "alicloud_cen_instance" "example" {
  provider          = alicloud.your_account
  cen_instance_name = "tf_example"
  description       = "an example for cen"
}

resource "alicloud_vpc" "child_account" {
  provider   = alicloud.child_account
  vpc_name   = "terraform-example"
  cidr_block = "172.17.3.0/24"
}
resource "alicloud_cen_instance_grant" "child_account" {
  provider          = alicloud.child_account
  cen_id            = alicloud_cen_instance.example.id
  child_instance_id = alicloud_vpc.child_account.id
  cen_owner_id      = data.alicloud_account.your_account.id
}

resource "alicloud_cen_instance_attachment" "example" {
  provider                 = alicloud.your_account
  instance_id              = alicloud_cen_instance.example.id
  child_instance_id        = alicloud_cen_instance_grant.child_account.child_instance_id
  child_instance_type      = "VPC"
  child_instance_region_id = data.alicloud_regions.default.regions.0.id
  child_instance_owner_id  = data.alicloud_account.child_account.id
}

Converting this snippet yields:

warning: /Users/t0yv0/bugs/ci-mgmt-889/repro-comments/first-class-provider/ali_cen.tf:5,1-20: Provider alias not supported; Provider aliases are not supported, ignoring alicloud=child_account
warning: /Users/t0yv0/bugs/ci-mgmt-889/repro-comments/first-class-provider/ali_cen.tf:21,1-20: Provider alias not supported; Provider aliases are not supported, ignoring alicloud=your_account

Consider supporting.

Also as a side note, introducing the new converter removed comments here, so presumably comments are no longer supported; for this example it might be fine since comments have more TF in them that didn't get converted before. Regarding aliases, prior to the converter we had some incorrect Provider options generated but that's now gone so looks like an improvement. Thank you!

Affected area/feature

@t0yv0 t0yv0 added kind/enhancement Improvements or new features needs-triage Needs attention from the triage team labels Apr 17, 2024
@justinvp justinvp removed the needs-triage Needs attention from the triage team label Apr 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/enhancement Improvements or new features
Projects
None yet
Development

No branches or pull requests

2 participants