Gigs
Gigs

Reputation: 369

Share AWS resources between Terraform and CDK

My team has two completely different environments: a Terraform one (which allow us to create and manage some AWS resources as databases) and a CDK one, with contains API resources and its logics as well.

We would like to use databases resources created with Terraform in the CDK app.

I was looking for some simple way to import outputs or tfstate from Terraform into CDK app, but I've found nothing.

I'd like to know how'd you achieve something like that?

Upvotes: 2

Views: 293

Answers (2)

Adam Anderson
Adam Anderson

Reputation: 21

This can be solved by putting the output in Parameter Store.

resource "aws_ssm_parameter" "rds_endpoint" {
  name  = "/rds/example/endpoint"
  type  = "String"
  value = aws_rds_cluster.example.endpoint
}

Then in CDK;

const rdsEndpoint = ssm.StringParameter.valueForStringParameter(
    this, '/rds/example/endpoint');

Upvotes: 2

Gigs
Gigs

Reputation: 369

So, I finally solved this issue by using the tfstate file on CDK : our Remote Backend is AWS, so the tfstate is stored on S3. When we run the CDK app we fetch this file from S3 and we inject its outputs into an application service.

It allows to always get the updated outputs from resources generated with Terraform.

Upvotes: 0

Related Questions