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.85k stars 450 forks source link

RemoteBackend not working with artifactory terraform backend repository #2450

Closed JasonCubic closed 1 year ago

JasonCubic commented 1 year ago

Community Note

cdktf & Language Versions

v0.14.3 TypeScript

Affected Resource(s)

The standard RemoteBackend

Debug Output

1 Stack deploying     0 Stacks done     0 Stacks waiting
[2022-12-24T13:13:43.599] [WARN] default - Error in Workspace: {}
[2022-12-24T13:13:43.600] [WARN] default - Error in IsRemoteWorkspace: {}
TerraformCloud returned an HTTP 404 error. Please make sure the configured organization (test-terraform-backend-repo) and workspace (cdktf-az-hub-spoke-demo_hub-demo) exist and you have the correct access rights.

Expected Behavior

connects to an artifactory terraform RemoteBackend successfully. With the same level of success that the terraform cli has.

These terraform commands work:

terraform -chdir=./cdktf.out/stacks/<stack-name> init
terraform -chdir=./cdktf.out/stacks/hub-demo apply --auto-approve

This cdktf deploy command does not: cdktf deploy <stack-name> -auto-approve

Actual Behavior

works using terraform cli but not using cdktf cli

Steps to Reproduce

setup an artifactory terraform backend free trial and try to connect to it using CDKTF RemoteBackend

Important Factoids

It seems like the correct url's might not be getting used? Maybe??

This is the URL of a repo in artifactory: https://<artifactory jfrog domain>/artifactory/<repo name>/workspaces/<workspace name>/

This seems to be the url being used: https://<artifactory jfrog domain>/api/v2/organizations/<repo name>/workspaces/<workspace name>

jsteinich commented 1 year ago

The RemoteBackend is used for connecting to Terraform Cloud (though CloudBackend has replaced it). ArtifactoryBackend is what is used for connecting to an artifactory backend. Note that this backend has been removed in the latest versions of Terraform.

JasonCubic commented 1 year ago

Its my understanding that artifactory now uses the remote_backend in terraform. It works in terraform. It's just cdktf where it doesn't seem to work.

https://www.jfrog.com/confluence/display/JFROG/Terraform+Backend+Repository

JasonCubic commented 1 year ago

I made a simpler repo to show the problem. https://github.com/JasonCubic/cdktf-remote-backend-artifactory

If you fill in the .env file with values then you will see that the cdktf fails and terraform works.

If you look at the scripts in package.json, these commands fail:

npm run cdktf:plan
npm run cdktf:apply
npm run cdktf:destroy

These command work:

npm run tf:init
npm run tf:plan
npm run tf:apply
npm run tf:state:pull
npm run tf:destroy

If you look at the contents of the scripts in package.json I hope it helps clarify.

Thank You,

jsteinich commented 1 year ago

@JasonCubic thanks for the additional information. cdktf does/did rely on using an api for performing actions when using RemoteBackend or CloudBackend. These pieces must not be compatible with using a non TFC/TFE backend. That API usage is being replaced with direct Terraform CLI usage, which may cover a fix for this. https://github.com/hashicorp/terraform-cdk/pull/2424 and https://github.com/hashicorp/terraform-cdk/pull/2427 are a couple in-progress PRs which may fully resolve this.

DanielMSchmidt commented 1 year ago

Those should be fixed in the upcoming 0.15 release (should be ready latest by end of the week)

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.