pulumi / pulumi-java

Java support for Pulumi
Apache License 2.0
64 stars 19 forks source link

Importing wafv2 results in incorrect and missing code. #947

Open MitchellGerdisch opened 1 year ago

MitchellGerdisch commented 1 year ago

What happened?

Imported WafV2 ACL into Java and although the resource imported into state successfully, the generated code had errors.

Specifically, it generated code like this:

var importedAcl = new WebAcl("importedAcl", WebAclArgs.builder()        
            .defaultAction()
...

Where .defaultAction() is not valid. Similarly for the rules section (not shown above) it was missing a.action()` block which is needed for the code to work.

Note: Importing to Typescript and YAML also produced incorrect code for the analogous defaultAction block and missing action block for the rule.

See below for details steps related to the Java use-case.

Steps to reproduce

  1. Use the code in this file to deploy a stack that creates a WafV2 ACL: createWafv2Acl_ts.txt Note the output of the above program since it provides a pulumi import command you can use in later steps.
  2. In a separate folder, run pulumi new aws-java to create a base stack to use for the import.
  3. Run the pulumi import command generated by the create stack in step 1
  4. Copy/paste the generated code into the program generated in step 2
  5. Run pulumi up on the import stack and note the errors.
  6. Modify the import stack code to correctly specify the .defaultAction block and to add a required .action block to the rule. See the code in this file for a correct version: Corrected-Imported_java.txt

Expected Behavior

The generated import code should correctly specify all required properties.

Actual Behavior

The generated import code incorrectly specified .defaultAction and was missing the rule-level .action property altogether.

Output of pulumi about

CLI
Version 3.51.1 Go Version go1.19.4 Go Compiler gc

Plugins NAME VERSION aws 5.27.0 java unknown

Host
OS darwin Version 12.5.1 Arch x86_64

This project is written in java: executable='/usr/bin/java' version='java 19.0.2 2023-01-17 Java(TM) SE Runtime Environment (build 19.0.2+7-44) Java HotSpot(TM) 64-Bit Server VM (build 19.0.2+7-44, mixed mode, sharing)' gradle='7.4.2' java='/usr/bin/java' javac='19.0.2' maven='Apache Maven 3.8.6 (84538c9988a25aec085021c365c560670ad80f63)'

Current Stack: xxxxxx/import-java-2/dev

TYPE URN pulumi:pulumi:Stack urn:pulumi:dev::import-java-2::pulumi:pulumi:Stack::import-java-2-dev pulumi:providers:aws urn:pulumi:dev::import-java-2::pulumi:providers:aws::default_5_27_0 aws:wafv2/webAcl:WebAcl urn:pulumi:dev::import-java-2::aws:wafv2/webAcl:WebAcl::importedAcl

Found no pending operations associated with dev

Backend
Name pulumi.com

No dependencies found

Additional context

I noticed that running pulumi convert --language java for a properly defined yaml version of the code would produce better but still incorrect version of the java code.

Contributing

Vote on this issue by adding a 👍 reaction. To contribute a fix for this issue, leave a comment (and link to your pull request, if you've opened one already).

michaelwiezik commented 1 year ago

Please note that using work around as provided by the Pulumi team, namely initializing WebAcl with

WebAclArgs.builder() .defaultAction(WebAclDefaultActionArgs.builder() .allow(WebAclDefaultActionAllowArgs.builder() .build()) .build())

And each rule with

.action(WebAclRuleActionArgs.builder() .block(WebAclRuleActionBlockArgs.builder() .build()) .build())

Results with:

{ RespMetadata: { StatusCode: 400, RequestID: "2706f15a-6f1c-465e-a79f-ef5509d06735" }, Field: "RULE", Message_: "Error reason: A reference in your rule statement is not valid., field: RULE, parameter: Statement", Parameter: "Statement", Reason: "A reference in your rule statement is not valid."

The original code has been generated with the pulumi import.

Thanks & Regards,

Whizzy