hashicorp / terraform-cdk

Define infrastructure resources using programming constructs and provision them using HashiCorp Terraform
https://www.terraform.io/cdktf
Mozilla Public License 2.0
4.86k stars 454 forks source link

Keys of user supplied objects are snake cased #291

Closed sdmain closed 4 years ago

sdmain commented 4 years ago

Community Note

cdktf & Language Versions

Affected Resource(s)

CodePipeline - Source stage - CodeCommit 'configuration'

For sourceStage, I am unable to provide configuration for CodeCommit: configuration parameters 'RepositoyName' and 'BranchName' are not recognized by CDK for Terraform.

Debug Output

Expected Behavior

CodePipeline should be created without erroring out on CodeCommit configuration

Actual Behavior

Error: Error creating CodePipeline: InvalidActionDeclarationException: Action configuration for action 'sourceAction' contains unknown configuration 'repository_name' on cdk.tf.json

Steps to Reproduce

Code: Below is my main.ts code snippet.

new Codepipeline(this, 'myappPipeline',{
      name: 'myappPipeline',
      artifactStore:[{
        type: 'S3',
        location: 'codepipeline-us-east-1-xxxxx',
      }
        ], //defaults:  
      roleArn: 'arn:aws:iam::xxx-ToolChain', 
      stage: [
        {name: 'sourceStage', action: [
          {name: 'sourceAction',
          owner: 'AWS',
          category: 'Source',
          provider: 'CodeCommit',
          version: '1',
          outputArtifacts: ['source_output'],
          configuration:{'RepositoryName':'myappRepoSampleApp', 'BranchName': 'master'} //**ERROR**
            // ['Repo']: 'myappRepoSampleApp', //
            // ['Branch']: 'master'}
          }
        ]},
        {name: 'buildStage', action: [
          {name: 'buildAction',
          owner: 'AWS',
          category: 'Build',
          provider: 'CodeBuild',
          inputArtifacts: ['source_output'],
          outputArtifacts: ['build_output'],
          version: '1',
          configuration:{
            ['ProjectName']: myappCodeBuild.arn
          }
          }
        ]},
        {name: 'deployToEcsStage', action: [
          {name: 'deployAction',
          owner: 'AWS',
          category: 'Deploy',
          provider: 'CodeDeployToECS',
          inputArtifacts: ['build_output'],
          version: '1',
          configuration:{
            ['ClusterName']: ecsCluster.arn,
            ['ServiceName']: ecsService.name,
            ['FileName']: 'imagedefinitions.json'
          }
          }
       ]}
      ]
    });

Important Factoids

References

skorfmann commented 4 years ago

@sdmain thanks for opening this bug report. I think that's related to this issue, which will be tackled soon. In the meantime, you can use escape hatches as described in one of the issue comments as well. Hope that'll unblock you.

Let me know if there's anything unclear. Otherwise, please confirm it's working for you after testing the workaround.

sdmain commented 4 years ago

Thanks Sebastian! I will try that right now and will share the outcome.

One side question - at what point can we propose CDK for Terraform for production usage for our customers?

anubhavmishra commented 4 years ago

@sdmain CDK for Terraform is in alpha as we gather more feedback about the project and the feature set. We will announce a stable version when we are confident that the project is ready for supporting production stacks. Please continue to give us feedback as we go through this process. Thank you for using CDK for Terraform. :)

sdmain commented 4 years ago

@skorfmann I think I am a bit lost here. I have configuration defined for each stage within the pipeline. If I add pipeline.addOverride('configuration'..), I am not sure how that would work.

or I am thinking I should provide those specific configurations in override, but 'RepositoryName' and 'BranchName' are already supported parameters in native Terraform for 'CodeCommit' provider.

stage: [
        {name: 'sourceStage', action: [
          {name: 'sourceAction',
          owner: 'AWS',
          category: 'Source',
          provider: 'CodeCommit',
          version: '1',
          outputArtifacts: ['source_output'],
          configuration:{'RepositoryName':'myappRepoSampleApp', 'BranchName': 'master'} //**ERROR**
          }
        ]},
sdmain commented 4 years ago

tried these overrides:

 pipeline.addOverride('configuration', {'RepositoryName':'myappRepoSampleApp'});
 pipeline.addOverride('configuration', {'BranchName':'master'});

Error: Extraneous JSON object property

on cdk.tf.json line 362, in resource.aws_codepipeline.typescriptawsaz_fnmaPipeline_2BF044C5: 362: "configuration": {

No argument or block type is named "configuration".

skorfmann commented 4 years ago

or I am thinking I should provide those specific configurations in override, but 'RepositoryName' and 'BranchName' are already supported parameters in native Terraform for 'CodeCommit' provider.

I think this takes an arbitrary object and passes it directly through to the AWS API. The issue is, that we automatically convert all object keys to snake case, and the AWS API doesn't expect it that way. See here the provider docs https://registry.terraform.io/providers/hashicorp/aws/2.70.0/docs/resources/codepipeline#configuration

pipeline.addOverride('configuration', {'RepositoryName':'fnmaRepoSampleApp'});

The override takes a JSON path as well. Something like this could work pipeline.addOverride('stage.0.action.0.configuration', {'RepositoryName':'fnmaRepoSampleApp', 'BranchName': 'foo'});

sdmain commented 4 years ago

@skorfmann unfortunately this did not work. I am stuck at this error for a few hours now. I made a lot of progress with several other resources, but this specific error with codepipeline is killing me :(

pipeline.addOverride('stage.0.action.0.configuration', {'RepositoryName':'myappRepoSampleApp', 'BranchName': 'master'});

Error: Error creating CodePipeline: InvalidActionDeclarationException: Action configuration for action 'sourceAction' contains unknown configuration 'repository_name'

on cdk.tf.json line 385, in resource.aws_codepipeline.typescriptawsa

skorfmann commented 4 years ago

Let me quickly check

skorfmann commented 4 years ago

pipeline.addOverride('stage.0.action.0.configuration', {'RepositoryName':'myappRepoSampleApp', 'BranchName': 'master'});

Looks like addOverride is merging, not completely overwriting. I think that's on purpose, to allow partial overwrites. In this particular case this behaviour is not ideal though. When you remove the configuration block in the resource class itself, it should work.

sdmain commented 4 years ago

Thank you! Trying it now

sdmain commented 4 years ago

@skorfmann That worked!!! Thanks a bunch!!! I am unblocked with that error now.

skorfmann commented 4 years ago

That worked!!! Thanks a bunch!!! I am unblocked with that error now.

Cool, no worries - thanks for confirming. I'll close this issue as duplicate. If there's anything else, don't hesitate to create another issue.

github-actions[bot] commented 1 year ago

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.