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

Feature Request: Add support for CreateVPCAssociationAuthorization AWS API #384

Closed
hashibot opened this issue Jun 13, 2017 · 45 comments · Fixed by #14215
Closed

Feature Request: Add support for CreateVPCAssociationAuthorization AWS API #384

hashibot opened this issue Jun 13, 2017 · 45 comments · Fixed by #14215
Assignees
Labels
enhancement Requests to existing resources that expand the functionality or scope. new-resource Introduces a new resource. service/ec2 Issues and PRs that pertain to the ec2 service. upstream Addresses functionality related to the cloud provider.
Milestone

Comments

@hashibot
Copy link

This issue was originally opened by @rginev as hashicorp/terraform#10208. It was migrated here as part of the provider split. The original body of the issue is below.


Hey there,

Terraform does have route53_zone_association resource, but it works for private zones and VPCs in the same AWS account.
If you want to associate a VPC that you created with one AWS account with a private hosted zone that you created with a different account you had to ask AWS support to create authorisation manually.
Now they added an API for this. It would be great to have this implemented in terraform e.g. new resource.

Thanks in advance!

References

@hashibot hashibot added enhancement Requests to existing resources that expand the functionality or scope. new-resource Introduces a new resource. labels Jun 13, 2017
@josephholsten
Copy link

@RyanJarv I don't know if you've looked here since the provider split. Let me know if you want to help get a fix together for this.

@Zordrak
Copy link

Zordrak commented Jun 27, 2017

Should only require the creation of an authorization resource against a specific zone, with parameter inputs for source vpc id and source vpc region.

Would love to see this implemented.

EDIT: Just realised how difficult this could end up being to implement. It seems to me that the Zone owner account has to create an authorisation, the VPC owner account then has to perform the association, but then subsequently does not have permission to describe the association. If you manually create an authorisation and then use terraform to create the association; the association will be created but the apply will fail and all subsequent plans and applies will fail because in order to refresh the resource, the zone must be described, but permission is not available to do so.

@RyanJarv
Copy link
Contributor

RyanJarv commented Jul 2, 2017

@josephholsten Hey sorry, yeah that would be awesome I've just been pretty busy and not sure when I'll have time to get back to this.

Worth mentioning this actually does work currently for creating authorizations but like @Zordrak pointed out the association resource can't describe route53 zone and fails currently. This is talked about a bit more at https://github.com/hashicorp/terraform/pull/12553

If we don't mind the association and authorization resource working together currently this could probably be merged with some added docs and a note on the issue.

@robh007
Copy link
Contributor

robh007 commented Oct 21, 2017

Is anyone still interested in trying to get this feature out?

@RyanJarv
Copy link
Contributor

Went ahead and cleaned this up a bit and added documentation in #2005. Last PR was before the repo split.

@donotpush
Copy link

Awesome! this will be very useful! Thanks for the hard work!

@luisamador
Copy link

Agreed. Fixing this would be very helpful. In the meantime I have used the AWS CLI to do the Route53 VPC association from a VPC sitting in one AWS account to a Route53 Hosted Zone sitting on different AWS account. Here are the steps: https://aws.amazon.com/premiumsupport/knowledge-center/private-hosted-zone-different-account/

@ewbankkit
Copy link
Contributor

There's a problem with the way the Route 53 API works when creating the association between a hosted zone created in one AWS account and a VPC created in a second AWS account.

This Terraform code (following the steps here, and based on this code)

provider "aws" {
  // Zone creator's credentials.
}

provider "aws" {
  alias = "bar"
  // VPC creator's credentials.
  access_key = "XXXXXXXXXXXXXXXXXXXX"
  secret_key = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
}

resource "aws_vpc" "foo" {
  cidr_block           = "10.6.0.0/16"
  enable_dns_hostnames = true
  enable_dns_support   = true
}

resource "aws_route53_zone" "foo" {
  name   = "example.com"
  vpc_id = "${aws_vpc.foo.id}"
}

resource "aws_vpc" "bar" {
  provider = "aws.bar"

  cidr_block           = "10.7.0.0/16"
  enable_dns_hostnames = true
  enable_dns_support   = true
}

resource "aws_route53_zone_association_authorization" "foo" {
  zone_id = "${aws_route53_zone.foo.id}"
  vpc_id  = "${aws_vpc.bar.id}"
}

resource "aws_route53_zone_association" "bar" {
  provider = "aws.bar"

  zone_id = "${aws_route53_zone_association_authorization.foo.zone_id}"
  vpc_id  = "${aws_vpc.bar.id}"
}

should create VPCs in two different AWS accounts and associate them both with a hosted zone created in the first AWS account. In fact it does exactly that, but an error is reported:

terraform apply
aws_vpc.bar: Creating...
  assign_generated_ipv6_cidr_block: "" => "false"
  cidr_block:                       "" => "10.7.0.0/16"
  default_network_acl_id:           "" => "<computed>"
  default_route_table_id:           "" => "<computed>"
  default_security_group_id:        "" => "<computed>"
  dhcp_options_id:                  "" => "<computed>"
  enable_classiclink:               "" => "<computed>"
  enable_classiclink_dns_support:   "" => "<computed>"
  enable_dns_hostnames:             "" => "true"
  enable_dns_support:               "" => "true"
  instance_tenancy:                 "" => "<computed>"
  ipv6_association_id:              "" => "<computed>"
  ipv6_cidr_block:                  "" => "<computed>"
  main_route_table_id:              "" => "<computed>"
aws_vpc.foo: Creating...
  assign_generated_ipv6_cidr_block: "" => "false"
  cidr_block:                       "" => "10.6.0.0/16"
  default_network_acl_id:           "" => "<computed>"
  default_route_table_id:           "" => "<computed>"
  default_security_group_id:        "" => "<computed>"
  dhcp_options_id:                  "" => "<computed>"
  enable_classiclink:               "" => "<computed>"
  enable_classiclink_dns_support:   "" => "<computed>"
  enable_dns_hostnames:             "" => "true"
  enable_dns_support:               "" => "true"
  instance_tenancy:                 "" => "<computed>"
  ipv6_association_id:              "" => "<computed>"
  ipv6_cidr_block:                  "" => "<computed>"
  main_route_table_id:              "" => "<computed>"
aws_vpc.bar: Creation complete after 6s (ID: vpc-951bcaec)
aws_vpc.foo: Creation complete after 5s (ID: vpc-b018c9c9)
aws_route53_zone.foo: Creating...
  comment:        "" => "Managed by Terraform"
  force_destroy:  "" => "false"
  name:           "" => "example.com"
  name_servers.#: "" => "<computed>"
  vpc_id:         "" => "vpc-b018c9c9"
  vpc_region:     "" => "<computed>"
  zone_id:        "" => "<computed>"
aws_route53_zone.foo: Still creating... (10s elapsed)
aws_route53_zone.foo: Still creating... (20s elapsed)
aws_route53_zone.foo: Still creating... (30s elapsed)
aws_route53_zone.foo: Creation complete after 35s (ID: Z3UMIQBZQ9Y13C)
aws_route53_zone_association_authorization.foo: Creating...
  vpc_id:     "" => "vpc-951bcaec"
  vpc_region: "" => "<computed>"
  zone_id:    "" => "Z3UMIQBZQ9Y13C"
aws_route53_zone_association_authorization.foo: Creation complete after 0s (ID: Z3UMIQBZQ9Y13C:vpc-951bcaec)
aws_route53_zone_association.bar: Creating...
  vpc_id:     "" => "vpc-951bcaec"
  vpc_region: "" => "<computed>"
  zone_id:    "" => "Z3UMIQBZQ9Y13C"
aws_route53_zone_association.bar: Still creating... (10s elapsed)
aws_route53_zone_association.bar: Still creating... (20s elapsed)
aws_route53_zone_association.bar: Still creating... (30s elapsed)
Error applying plan:

1 error(s) occurred:

* aws_route53_zone_association.bar: 1 error(s) occurred:

* aws_route53_zone_association.bar: AccessDenied: User: arn:aws:iam::000000000000:user/kit is not authorized to access this resource
	status code: 403, request id: c1f53cc1-f6fe-11e7-8456-41d8d6fcb1f8

Terraform does not automatically rollback in the face of errors.
Instead, your Terraform state file has been partially updated with
any resources that successfully completed. Please address the error
above and apply again to incrementally change your infrastructure.

and subsequent terraform plans get the same error:

terraform plan
Refreshing Terraform state in-memory prior to plan...
The refreshed state will be used to calculate this plan, but will not be
persisted to local or remote state storage.

aws_vpc.bar: Refreshing state... (ID: vpc-951bcaec)
aws_vpc.foo: Refreshing state... (ID: vpc-b018c9c9)
aws_route53_zone.foo: Refreshing state... (ID: Z3UMIQBZQ9Y13C)
aws_route53_zone_association_authorization.foo: Refreshing state... (ID: Z3UMIQBZQ9Y13C:vpc-951bcaec)
aws_route53_zone_association.bar: Refreshing state... (ID: Z3UMIQBZQ9Y13C:vpc-951bcaec)
Error refreshing state: 1 error(s) occurred:

* aws_route53_zone_association.bar: 1 error(s) occurred:

* aws_route53_zone_association.bar: aws_route53_zone_association.bar: AccessDenied: User: arn:aws:iam::000000000000:user/kit is not authorized to access this resource
	status code: 403, request id: 22ab1eca-f700-11e7-aa35-9bd7d0c4ca7d

The problem is with the code that run under the credentials of the associator (i.e. NOT the AWS account that created the hosted zone) that is reading the state of the zone association https://github.com/terraform-providers/terraform-provider-aws/blob/17a320b90f85a7e98e19f2b405d0526b640f4880/aws/resource_aws_route53_zone_association.go#L94-L95
As there is no AWS zone associated resource the zone itself is queried and this fails with the AccessDenied error when called from the AWS account that didn't create the zone.

@RyanJarv
Copy link
Contributor

RyanJarv commented Jan 11, 2018

@ewbankkit Yeah, this is an issue with aws_route53_zone_association and is documented in my PR at https://github.com/terraform-providers/terraform-provider-aws/pull/2005/files#diff-f048cbf19e0fc509e5df5d05254f5bdbR13.

This was also the reason I held off on making that PR for a bit, some people where asking for it regardless, so short of a better fix I added a note on the issue (although looking at it now this should be added to the aws_route53_zone_association doc as well). I'm sure this could be worked around somehow, however I didn't come up with anything that didn't feel hacky to me at the time.

The core of the issue is that you can not enumerate Route53 zones attached to a VPC, so the aws_route53_zone_association resource checks to see if the VPC is attached by using GetHostedZone on the Route53 zone which the account that needs to do the association doesn't usually have access to.

@radeksimko radeksimko added the service/ec2 Issues and PRs that pertain to the ec2 service. label Jan 25, 2018
@JoshiiSinfield
Copy link

@RyanJarv
Hi, have you considered requiring a second provider for which to do the R53 api call with?

If it's not a TF coding anti-pattern / no-no I'd be happy with having to specifiy two providers to a resource. I'd expect the authorisation to be created at the same time as the association as the example above does, so the second provider should be available anyway.

A second idea I've had, but the answer doesn't seem obvious from the AssociateVPCWithHostedZone API reference, What error/response do you get when trying to associate an already associated VPC to a zone? Is the response suitable to be used in determining whether the VPC is already associated, rather than having to get the list of vpcs from the zone?

excuse my naivety if these are obvious no's! 😄

Cheers,
Josh

@psyvision
Copy link
Contributor

@JoshiiSinfield If I'm reading the above correctly then @ewbankkit has already tried doing this (hence the two provider "aws" statements at the top of his TF code.

From using the aws cli, from memory, I think you do get a different message when the zone has already been associated.

@JoshiiSinfield
Copy link

JoshiiSinfield commented Mar 12, 2018

@psyvision
Yes he has, except I was on about passing a second provider into the zone_association resource.

Something like this (assuming use of the rest of @ewbankkit's code)::

resource "aws_route53_zone_association" "bar" {
  provider = "aws.bar"
  r53_zone_provider = "aws"

  zone_id = "${aws_route53_zone_association_authorization.foo.zone_id}"
  vpc_id  = "${aws_vpc.bar.id}"
}

That way you're explicitly giving the zone_association access to the R53 zone to call GetHostedZones.

@RyanJarv
Copy link
Contributor

RyanJarv commented Jul 25, 2018 via email

@tdmalone
Copy link
Contributor

tdmalone commented Jun 8, 2019

Related: #585 and #8593

@RyanJarv
Copy link
Contributor

RyanJarv commented Jun 8, 2019

Hey all, haven't got around to looking into this again yet but did want to leave this here, turn's out the API issue thing is also a bit of a security problem. I reported this to AWS security about two years ago when I was working on this originally but am unsure of any timeline on fixing it.

https://blog.ryanjarv.sh/2019/05/24/backdooring-route53-with-cross-account-dns.html

@aeschright
Copy link
Contributor

Hi everyone, we've decided that there isn't a way we're happy to do this currently within the API constraints. Please don't submit new PRs for the resource right now. I'm going to leave the ticket open as an upstream issue to reconsider if something changes.

For a workaround, you can use the cli instructions instead: https://aws.amazon.com/premiumsupport/knowledge-center/private-hosted-zone-different-account/

@aeschright aeschright added the upstream Addresses functionality related to the cloud provider. label Sep 19, 2019
@mhaley-miovision
Copy link

Hi, I see that you guys don't want to go forward with this PR because the API does not have a good way of allowing an account to view vpc associations on a route53 zone that it does not own. I think that there are still uses for this resource and see no reason why limitation in associations API should stop you from implementing the authorizations API. All the pieces are there. And who knows, maybe once people get their hands on this, the path to full cross account route53 associations managed by terraform will be more clear.

@krogon
Copy link

krogon commented Dec 3, 2019

Hi, I was able to workaround this limitations using multiple data sources and resource. Please let me know if this would be accepted, as then I would need additional time for testing coverage.

@RyanJarv
Copy link
Contributor

RyanJarv commented Mar 5, 2020

@RyanJarv does any of this change your opinion on how this would be tackled?

I kinda forget what the issue is exactly every time I look at this post, so probably worth taking whatever I say here with a grain of salt.

The association needs to be run in the hosted zone account iirc, so the error is because this account can’t enumerate current associations. It can work but you start to run into cases where you don’t know the current state of stuff. It seems like this is still an issue I believe? If you wanted to only store state about associations locally that seems doable, I’m not sure I understand the impact of doing this though.

This doesn’t sound right, probably best to ignore me. I’ll try to look into this again soon though.

Edit: Quick update, I had that backwards I think. So authorization is done by the hosted zone account, association is done by the VPC account. It’s failing because terraform tries to figure out if a zone is associated or not first, but you can’t do that with the API, you don’t have permissions to read the zone. If that information was stored locally then you should be able to do this, but you can’t know the state of your account other then that (I think I keep getting confused about the terraform vs security part of this). So if you take out the read part of the CRUD stuff on the association resource this should work(?)

If the resource is ever managed outside of terraform you will run into issues though. Maybe this is OK, I’m not really sure. I think it was mostly decided we didn’t want to do that but maybe this part wasn’t clear before (actually pretty sure this wasn’t obvious before, I need to read this thread though).

You mentioned something about passing roles (on my phone so difficult to look rn) in your other post, if you could somehow grant access to read the zone and maybe include it in an example of how this should be used maybe that would work as well.

Edit2: The other part of this is AWS recommends removing the authorization after the association is complete. But tbh I’m not really sure I understand the reasoning for doing this, or why you wouldn’t want a VPC to be re-associated. I think it’s probably okay to just make note of it though in the docs, I thought there was discussion somewhere on this in the thread but not seeing it now.

Let me know if I missed anything here.

@miketwenty1
Copy link

@RyanJarv

So if you take out the read part of the CRUD stuff on the association resource this should work(?)

Are addressing the 403 error I put above? I believe so.

If the resource is ever managed outside of terraform you will run into issues though.

We are strictly speaking about just association of VPC-Account B to private hosted zone-Account A.. i think this is ok.

if you could somehow grant access to read the zone and maybe include it in an example of how
this should be used maybe that would work as well.

Without the idea of assuming more than 1 profile/alias within a resource/module (role-ception) this doesn't seem doable with terraform/aws. I question though how the above command works fine though specifying only one profile. Route53 and VPC's don't have the capability of a s3 bucket policy equivalent where you can grant access to IAM users/roles in different accounts.

aws route53 associate-vpc-with-hosted-zone \
--hosted-zone-id ZAZAPAPAXAXAXAXAXA10 \
--vpc VPCRegion=us-east-1,VPCId=vpc-000bb00bb00bb00bb \
--profile profile_with_access_to_vpc_in_secondary_account

I mainly point to the cli commands that I reference above. Both manual cases for applying and destroying work perfect with just 1 profile being used with each command. I would imagine this translates to the API.. given it only has the inputs I provide.
When running the associate cli command again after it's already associated. I get this.

An error occurred (ConflictingDomainExists) when calling the AssociateVPCWithHostedZone operation: The VPC that you chose, vpc-00000000000 in region us-east-1, is already associated with another private hosted zone that has an overlapping name space, somedomain.com..

Meaning it does plenty fine knowing it's already associated. This coming from the profile of the account with the VPC that doesn't have direct access to the private hosted zone in the "route53" account.

The other part of this is AWS recommends removing the authorization after the association is complete. But tbh I’m not really sure I understand the reasoning for doing this, or why you wouldn’t want a VPC to be re-associated.

This is because after it is associated you no longer need it authorized. I think like you mention this can be noted in the docs.. and probably ignored.

@miketwenty1
Copy link

I would like to point out.

Seems that this was first reported by @rginev on Nov 17, 2016 (roughly ~3.5 years ago)
hashicorp/terraform#10208

Since then:

hashicorp/terraform#11174 (closed -> ^10208)
hashicorp/terraform#12804 (closed -> #617)
hashicorp/terraform#20841 (closed no resolution)
hashicorp/terraform#22780 (closed -> #9453)
hashicorp/terraform#24286 (closed -> #384 here)

hashicorp/terraform#12553 (@RyanJarv your PR)

#384 (here)
#585 (open)
#617 (open)
#2005 (closed no resolution)
#7805 (closed no resolution)
#7812 (closed -> #7805)
#8593 (open)
#9453 (open)

There's probably more I missed, I'm just trying to point out that this has been wanted for a while.

Both @ewbankkit @FransUrbo seem to have a lot of history with this and might be interested in this still?
@bflad (maintainer?)
This also came up in some research:
https://forums.aws.amazon.com/thread.jspa?threadID=271250

@ewbankkit
Copy link
Contributor

I thought a lot about this a while back and my conclusion was that capturing the behaviour of this API in a resource doesn't match the way that the AWS provider works - i.e. the interactions for a single resource are done under the single AWS identity configured in the resource.
One solution may be to create separate provider that contains this new resource and this new provider is configured with both AWS identities. The complexity would all be in the myriad options for configuring those identities for the underlying AWS SDK.
https://github.com/hashicorp/aws-sdk-go-base could contain some reusable parts.

@miketwenty1
Copy link

@ewbankkit

the interactions for a single resource are done under the single AWS identity configured in the resource.

I'm not understanding the issue tbh.
looking over:
API_CreateVPCAssociationAuthorization
and
API_AssociateVPCWithHostedZone

Seems that this would only require a single aws identity per resource/api call/cli cmd.
I quote from the 2nd link.

Use the AWS account that created the private hosted zone to submit a 
CreateVPCAssociationAuthorization request. Then use the account that created the VPC to submit
 an AssociateVPCWithHostedZone request.

If a subnet in the VPC was shared with another account, you can use the account that the subnet 
was shared with to submit an AssociateVPCWithHostedZone request. For more information about 
sharing subnets, see Working with Shared VPCs.

Sounds like it follows suit with the commands I posted above. #384 (comment)

Would you be able to explain what the issue is exactly?

@miketwenty1
Copy link

miketwenty1 commented Mar 26, 2020

wanted to bump you on this @ewbankkit and maybe also @RyanJarv
Any thoughts on? this is kinda of a pain to manage when you have have many accounts utilizing a private hosted zone in another account.

@RyanJarv
Copy link
Contributor

Is anyone aware of any examples in terraform where the read part of CRUD is skipped, leaving other operations to depend only the data in the state file?

@evandam
Copy link

evandam commented Apr 10, 2020

I'm running into the same issue and would love to see a solution, or at least some extra documentation that outlines this scenario before more people end up running it and finding this issue.

Alternatively, would it be possible to have an IAM policy that would allow the account with the VPC to list hosted zones on the account with the hosted zone as a workaround?

@wstewartii
Copy link

wstewartii commented Apr 22, 2020

I'm running into this issue as well and I think anyone trying to make use of a private hosted zone across accounts with terraform is going to run into this issue. Managing multiple aws accounts is a very common use case in large companies and is what aws seems to recommend as an architecture within an organization. It's very disappointing to see this go unresolved for years.

@tony-kerz
Copy link

just encountering this issue myself.

there are ways to address using resolver-endpoints (inbound at phz-provider, outbound at phz-consumer), but those endpoints are charged separately by aws and it would be great to avoid that extra charge with the "direct" phz <-> vpc association alternative.

per this knowledge-base article it shows how to accomplish the authorization via cli.

i can/will try myself, but figured i would pose the question to the experienced participants in this thread:

assuming that the authorization part was done manually in the context of the phz-provider account, would use of aws_route53_zone_association work in the context of the phz-consumer account?

@RyanJarv
Copy link
Contributor

RyanJarv commented Apr 28, 2020

Hi all, I was looking into this again after @miketwenty1 pointed out that you can get the state of the aws_route53_zone_association from the error messages returned after repeated calls to that API.

I put something together to test this out in master...RyanJarv:cross-account-hostedzone-association.

This is all just a test right now, so any thoughts here are appreciated. In that branch I'm using a cross_account attribute on the aws_route53_zone_association resource to change the behavior of how the read and wait parts are done.

So in that branch if cross_account = true:

  • We only rely on local state for the Read function
  • Instead of calling get-wait to determine when Create is done we do repeated calls to AssociateVPCWithHostedZone and wait for the error message to inform us that this zone is already associated.

This seems to work ok but at the moment but has the following issues:

I don't think the second is really an issue but wanted to mention it since it was brought up before.
For the first there might be able to handle through something like always show a change during plan and somehow indicate that it may not actually result in a change. This behavior could potentially be toggled via something like the cross_account option as well.

Mostly wanted to post this now to see if anyone has any opinions on this behavior in the branch I linked and any thoughts on handling drift.

@RyanJarv
Copy link
Contributor

@evandam

Alternatively, would it be possible to have an IAM policy that would allow the account with the VPC to list hosted zones on the account with the hosted zone as a workaround?

Using assumeRole yes, however terraform afik isn't designed to connect to multiple accounts in a single resource. If it was possible to do this without assumeRole this would be more feasible. I wasn't able to figure either of these options out though at least in a way that made sense.

@tony-kerz

assuming that the authorization part was done manually in the context of the phz-provider account, would use of aws_route53_zone_association work in the context of the phz-consumer account?

This would not work, for the most part aws_route53_zone_association is the problem. If you want to try the branch in my last post that may work for you (warning: have not done much testing on it).

@hamishfor
Copy link

We have encountered this issue as well. Trying to build an ephemeral organization that has DNS is turning out to be quite the challenge.

This... bug? Will become more and more pertinent to businesses that have spawned in the era of IAC as they grow to incorporate multi account architectures, at AWS's recommendation I might add!

@avvi00
Copy link

avvi00 commented May 31, 2020

I'm also keen to see a clean resolution to this issue and I understand this is a complex one to solve!

I've tried using a null_resource to call the CLI and do the association. The problem is that when you create the zone, you can't specify the other account VPC or you get an error, so after everything has run the first time and the VPC is associated with the zone, terraforms seeks to remove the VPC from the hosted zone. It's all pretty ugly to handle at the moment.

One semi "clean" way to handle this now is to create a public hosted zone and record which points to the private DNS. Like the resolver-endpoint solution above, it costs more to implement of course depending on choice of domain.

For anyone interested the way I ended up implementing was as follows:

# new private zone in account_a
resource "aws_route53_zone" "private" {
  name     = local.zone_name
  tags     = local.tags
}

# This is run in context of account_a which has the hosted zone
resource "null_resource" "associate_zone_to_account_b" {
  triggers = {
      always = timestamp()
  }
  provisioner "local-exec" {
    command = "New-R53VPCAssociationAuthorization -HostedZoneId ${aws_route53_zone.private.id} -VPC_VPCId ${local.account_b_id} -VPC_VPCRegion ${var.account_b_region}"
    interpreter = ["PowerShell", "-Command"]
  }
}

# This is run in context of account_b which has the vpc - using STS
resource "null_resource" "associate_zone_to_account_b_authorise" {
  triggers = {
    resource_id = null_resource.associate_zone_to_account_b.id
  }
  provisioner "local-exec" {
    command = ". ${path.module}\\R53HostedZoneAssociation.ps1 ; Register-HostedZoneWithOtherAccountVpc -VpcId ${local.account_b_id} -VpcRegion ${local.account_b_region} -HostedZoneId ${aws_route53_zone.private.id} -STSRole ${local.sts_role}"
    interpreter = ["PowerShell", "-Command"]
  }
}

Effect of the above is I can re-run this terraform and reach the same outcome of the zone being associated with account_b VPC. It's not pretty because on every run it removes the association then re-adds, but it works.
New-R53VPCAssociationAuthorization calls the CreateVPCAssociationAuthorization API operation
Register-HostedZoneWithOtherAccountVpc uses the provided role to authenticate against account_b and then calls the AssociateVPCWithHostedZone API operation.

You need to have a role with the appropriate permission that the script can assume.

@tdmalone
Copy link
Contributor

https://aws.amazon.com/about-aws/whats-new/2020/06/amazon-route-53-launches-new-api-action-to-list-private-hosted-zones-associated-with-your-amazon-vpcs 🎉

@ewbankkit
Copy link
Contributor

@AzySir
Copy link

AzySir commented Jun 23, 2020

@tdmalone great timing with that post - has someone taken ownership to bring this home after the years of requests and posts :)

@arnvid
Copy link

arnvid commented Jun 30, 2020

Any chance this will get added into the provider anytime soon? The workarounds given uses local exec for aws cli and this is something we are trying very hard to avoid when using Terraform Enterprise. Also we are going into 100+ accounts now - and the less dependencies on externals the better :)

@tdmalone
Copy link
Contributor

tdmalone commented Aug 5, 2020

@arnvid Copying an update from Brian on the above PR:

Marking this for right after we complete our work for 3.0 in the next week or two, although review cycles might make it slightly after 3.1 for actual release. 👍

So, this is looking promising for pretty soon! 🎉

@bflad bflad added this to the v3.1.0 milestone Aug 5, 2020
@bflad bflad self-assigned this Aug 5, 2020
@bflad
Copy link
Member

bflad commented Aug 6, 2020

Support for Route 53 cross-account VPC Associations via a new aws_route53_vpc_association_authorization resource and updated aws_route53_zone_association resource handling has been merged and will release with version 3.1.0 of the Terraform AWS Provider, likely later today. Thanks to @goakley and @RyanJarv for implementation. 👍

@ghost
Copy link

ghost commented Aug 7, 2020

This has been released in version 3.1.0 of the Terraform AWS provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading.

For further feature requests or bug reports with this functionality, please create a new GitHub issue following the template for triage. Thanks!

@ghost
Copy link

ghost commented Sep 6, 2020

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thanks!

@ghost ghost locked and limited conversation to collaborators Sep 6, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement Requests to existing resources that expand the functionality or scope. new-resource Introduces a new resource. service/ec2 Issues and PRs that pertain to the ec2 service. upstream Addresses functionality related to the cloud provider.
Projects
None yet
Development

Successfully merging a pull request may close this issue.