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

Multiple stacks #289

Closed
Tirke opened this issue Aug 6, 2020 · 4 comments · Fixed by #636
Closed

Multiple stacks #289

Tirke opened this issue Aug 6, 2020 · 4 comments · Fixed by #636
Labels
bug Something isn't working duplicate This issue or pull request already exists

Comments

@Tirke
Copy link

Tirke commented Aug 6, 2020

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

cdktf & Language Versions

cdktf --version
0.0.13-pre.2f0b966cb25b6dc5066ee1551fdb32ff47a9c0fd

Affected Resource(s)

Multiple stacks.

Debug Output

Expected Behavior

I'm trying to see if I can use multiple stacks in multiple files like in CDK.
This is my current program

file1.ts

import {IamRole} from "./.gen/providers/aws";
import {TerraformStack} from 'cdktf'
import {Construct} from "constructs";


export class SecStack extends TerraformStack {
    constructor(scope: Construct, id: string) {
        super(scope, id);
        new IamRole(this, "cdk-tf-module-role", {
            name: "cdk-tf-module-role",
            assumeRolePolicy: JSON.stringify({
                "Version": "2012-10-17",
                "Statement": [
                    {
                        "Action": "sts:AssumeRole",
                        "Principal": {
                            "Service": "lambda.amazonaws.com"
                        },
                        "Effect": "Allow",
                    }
                ]
            })
        })
    }
}

file2.ts

import {Construct} from 'constructs';
import {App, TerraformOutput, TerraformStack} from 'cdktf';
import {AwsProvider, LambdaFunction, IamRole} from "./.gen/providers/aws";
import {SecStack} from "./role";

class MainStack extends TerraformStack {
    constructor(scope: Construct, id: string) {
        super(scope, id);

        new AwsProvider(this, "aws", {
            region: "eu-west-1",
        });

        const lambdaRole = new IamRole(this, "cdk-tf-lambda-role", {
            name: "cdk-tf-lambda-role",
            assumeRolePolicy: JSON.stringify({
                "Version": "2012-10-17",
                "Statement": [
                    {
                        "Action": "sts:AssumeRole",
                        "Principal": {
                            "Service": "lambda.amazonaws.com"
                        },
                        "Effect": "Allow",
                    }
                ]
            })
        })

        const lambda = new LambdaFunction(this, "cdk-tf-lambda", {
            filename: '../lambda/lambda.zip',
            functionName: 'cdk-tf',
            handler: 'index.handler',
            role: lambdaRole.arn,
            runtime: 'nodejs12.x'
        });

        new TerraformOutput(this, 'cdk-tf-lambda-arn', {
            value: lambda.arn
        });
    }
}

const app = new App();
new MainStack(app, 'dec-imp-main-stack');
new SecStack(app, 'dec-imp-sec-stack')
app.synth();

When cdktf deploy it appears that only the second stack is synth

cdk.tf.json

{
  "//": {
    "metadata": {
      "version": "0.0.13-pre.2f0b966cb25b6dc5066ee1551fdb32ff47a9c0fd",
      "stackName": "dec-imp-sec-stack"
    }
  },
  "resource": {
    "aws_iam_role": {
      "decimpsecstack_cdktfmodulerole_72EFC78B": {
        "assume_role_policy": "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Action\":\"sts:AssumeRole\",\"Principal\":{\"Service\":\"lambda.amazonaws.com\"},\"Effect\":\"Allow\"}]}",
        "name": "cdk-tf-module-role",
        "//": {
          "metadata": {
            "path": "dec-imp-sec-stack/cdk-tf-module-role",
            "uniqueId": "decimpsecstack_cdktfmodulerole_72EFC78B",
            "stackTrace": [
              "new TerraformElement (/Users/thomas.schersach/code/dec-imp/node_modules/cdktf/lib/terraform-element.js:11:28)",
              "new TerraformResource (/Users/thomas.schersach/code/dec-imp/node_modules/cdktf/lib/terraform-resource.js:9:9)",
              "new IamRole (/Users/thomas.schersach/code/dec-imp/.gen/providers/aws/iam-role.js:13:9)",
              "new SecStack (/Users/thomas.schersach/code/dec-imp/role.js:9:9)",
              "Object.<anonymous> (/Users/thomas.schersach/code/dec-imp/main.js:48:1)",
              "Module._compile (internal/modules/cjs/loader.js:1137:30)",
              "Object.Module._extensions..js (internal/modules/cjs/loader.js:1157:10)",
              "Module.load (internal/modules/cjs/loader.js:985:32)",
              "Function.Module._load (internal/modules/cjs/loader.js:878:14)",
              "Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)",
              "internal/main/run_main_module.js:17:47"
            ]
          }
        }
      }
    }
  }
}

Actual Behavior

The deploy is running forever (plan stage), it doesn't seem to work.

Steps to Reproduce

See program

@Tirke Tirke added the bug Something isn't working label Aug 6, 2020
@cmclaughlin
Copy link
Contributor

I wonder if this duplicates - Handling of Multiple Stacks #35?

The examples there seem to be multiple stacks in one file, but here the example involves multiple files.
Sounds like the current recommendation is "dedicated folder per stack"

@skorfmann
Copy link
Contributor

I wonder if this duplicates - Handling of Multiple Stacks #35?

Yes , it looks like it is 👍

Sounds like the current recommendation is "dedicated folder per stack"

That's actually a good point and totally doable. The important part is, that the cdktf deploy/destroy command would run in separate folders to separate the stack output file and its state. Could be easily automated in a monorepo setup. Conceptually, that's pretty close how I think it'd be abstracted in the CLI as well.

@skorfmann skorfmann added the duplicate This issue or pull request already exists label Aug 6, 2020
@skorfmann
Copy link
Contributor

Closing as duplicate

@github-actions
Copy link
Contributor

github-actions bot commented Dec 8, 2022

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've found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 8, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working duplicate This issue or pull request already exists
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants