terraform-cdk icon indicating copy to clipboard operation
terraform-cdk copied to clipboard

Issue with @cdktf/provider-postgresql Grant (Add terraform-parallelism flag)

Open Joe-Kollin opened this issue 2 years ago • 18 comments

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/provider-aws": "^7.0.13" "@cdktf/provider-postgresql": "^0.4.12" "@cdktf/provider-random": "^0.2.12" "cdktf": "^0.10"

"ts-node": "^10.7.0", "typescript": "^4.6.2"

Affected Resource(s)

PostgresqlProvider Grant Resource

Debug Output

Error: could not execute revoke query: pq: tuple concurrently updated

Expected Behavior

Successfully created each role grant for each role.

Actual Behavior

Concurrency error in spite of trying both the --parallelism=0 and --parallelism=1 flags

Steps to Reproduce

roles.forEach((role) => {

     ...doStuff

      role.grants.forEach((grant) => {
        new Grant(this, `${this.deploymentPrefix}-${role.name}-${grant.objectType}-grant`, {
          role: role.name,
          database: role.database,
          objectType: grant.objectType,
          privileges: grant.privileges,
        });
      });

})

Important Factoids

I've done some research and tried the concurrency flag which doesn't seem to be fixing anything. My assumption is that either something is wrong with the flag implementation in CDKTF or the Grant object itself.

Joe-Kollin avatar Apr 12 '22 17:04 Joe-Kollin

You could try setting an environment variable as described here. cdktf doesn't currently support passing flags to Terraform, but you can also run Terraform directly from the stack output directory.

jsteinich avatar Apr 13 '22 02:04 jsteinich

This PR added a parallelism flag to the cdktf-cli, however that one addresses deploying multiple stacks in parallel and does not show the same behaviour as the parallelism flag of the Terraform CLI. To me it would make sense to e.g. expose a --terraform-parallelism flag or similar to allow setting this flag, when required as a workaround for underlying provider issues.

ansgarm avatar Apr 13 '22 08:04 ansgarm

Thanks @jsteinich that worked for me. For anyone referencing this do:

TF_CLI_ARGS_apply="-parallelism=1" cdktf deploy <stack name>

@ansgarm having a direct flag like that would definitely be nice though

Joe-Kollin avatar Apr 13 '22 14:04 Joe-Kollin

#734 is asking for the same flag.

jsteinich avatar Apr 14 '22 10:04 jsteinich

Thanks @jsteinich that worked for me. For anyone referencing this do:

TF_CLI_ARGS_apply="-parallelism=1" cdktf deploy <stack name>

@ansgarm having a direct flag like that would definitely be nice though

cdktf command, Don't take effect

jaty613 avatar Apr 21 '22 14:04 jaty613

Hi @jaty613, could you explain a bit more what you did that did not work? Which command did you try? What operating system are you using?

ansgarm avatar Apr 21 '22 14:04 ansgarm

Hi @jaty613, could you explain a bit more what you did that did not work? Which command did you try? What operating system are you using?

env: Terraform v1.1.7 on windows_386

terraform apply --auto-approve (parallelism parameters to take effect)

cdktf deploy (Don't take effect)

image

jaty613 avatar Apr 22 '22 01:04 jaty613

Hi @jaty613, where do you set those environment variables? Are you using an IDE, a terminal (which one?) or something else? What do you do to confirm that parallelism does not take effect? Terraform will only run things in parallel that have no dependencies onto each other – maybe that's what you are experiencing? Could you share your CLI output in a Github Gist or send us an reproduction case?

ansgarm avatar Apr 25 '22 12:04 ansgarm

Hi @jaty613, where do you set those environment variables? Are you using an IDE, a terminal (which one?) or something else? What do you do to confirm that parallelism does not take effect? Terraform will only run things in parallel that have no dependencies onto each other – maybe that's what you are experiencing? Could you share your CLI output in a Github Gist or send us an reproduction case?

In the Windows operating system, set the environment variables as system environment variables and ensure that the environment variables take effect。

jaty613 avatar Apr 28 '22 05:04 jaty613

@jaty613 What terminal application are you using on windows?

ansgarm avatar Apr 28 '22 08:04 ansgarm

@jaty613 What terminal application are you using on windows? cmd & powshell

jaty613 avatar Apr 29 '22 12:04 jaty613

What does running echo %TF_CLI_ARGS_apply% return?

ansgarm avatar Apr 29 '22 12:04 ansgarm

C:\Users\root>echo %TF_CLI_ARGS_apply% -parallelism=800

jaty613 avatar Apr 29 '22 13:04 jaty613

C:\Users\root>echo %TF_CLI_ARGS_apply% -parallelism=800

The actual maximum number of parallelism runs is the default value of 10

jaty613 avatar Apr 29 '22 14:04 jaty613

You mentioned Powershell. Is it correctly returning the -parallelism=800 in the Powershell as well? How many resources do you apply (of which only 10 apply in parallel)?

ansgarm avatar Apr 29 '22 14:04 ansgarm

You mentioned Powershell. Is it correctly returning the -parallelism=800 in the Powershell as well? How many resources do you apply (of which only 10 apply in parallel)?

PS C:\Users\root> $env:TF_CLI_ARGS_apply -parallelism=800

One stack has 200 resources

jaty613 avatar Apr 29 '22 14:04 jaty613

The terraform apply command parallelizes the maximum number of resources, but the CDKTF deploy command does not

jaty613 avatar Apr 29 '22 14:04 jaty613

Could you try setting the CDKTF_LOG_LEVEL environment variable and see if that has an effect (it should create more output logging while running e.g. deploy or diff).

ansgarm avatar May 05 '22 12:05 ansgarm

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[bot] avatar Nov 24 '22 01:11 github-actions[bot]