ewilde / terraform-provider-openfaas

Terraform OpenFaaS provider
Mozilla Public License 2.0
47 stars 8 forks source link

Fix OpenFaaS client authentication to use authentication from Terraform provider initialization #9

Closed hugomcfonseca closed 4 years ago

hugomcfonseca commented 4 years ago

Currently, this provider was accepting user_name and password in Terraform provider initialization, but there is no reference in the code that uses it to instantiate the OpenFaaS client.

This commit adds a credentials chain so it tries to get the authentication in the following order:

  1. Authentication with basic-auth using username and password from Terraform provider initialization
  2. Authentication with basic-auth using OpenFaaS config file created from faas-cli login
  3. Authentication with token using OpenFaaS config file created from faas-cli login

Also, adds a few log messages to help understand which credential is choosen from the chain.


In addition, this pull-request also solves an issue with updating an existing function Deployment and whitelists the label uid so it does not trigger a diff, even if the Terraform is up-to-dated.

laxgoalie392 commented 4 years ago

I just wasted hours trying to figure out why I was getting 401 errors using 0.3.1! Thankfully I checked out the PRs since there were no github issues and found this! Reverting back to 0.3.0 worked as a temporary fix but do we know where things are at with this PR?

hugomcfonseca commented 4 years ago

🙇 @ewilde when can we expect a release of the provider?

ewilde commented 4 years ago

@hugomcfonseca https://github.com/ewilde/terraform-provider-openfaas/pull/9/files#diff-0c265caa79e32560be818a2035276ac1R174

what is your setup for running the tests?

faas version
  ___                   _____           ____
 / _ \ _ __   ___ _ __ |  ___|_ _  __ _/ ___|
| | | | '_ \ / _ \ '_ \| |_ / _` |/ _` \___ \
| |_| | |_) |  __/ | | |  _| (_| | (_| |___) |
 \___/| .__/ \___|_| |_|_|  \__,_|\__,_|____/
      |_|

CLI:
 commit:  f7c29ea19b5df9d7aa87e9c70aacf4d9315da2cd
 version: 0.12.4

Gateway
 uri:     http://127.0.0.1:8080
 version: 0.18.13
 sha:     f6526929665cb05ceaca7c9c90a6bd7c5f32dca2
 commit:  Fix test on help description message

Provider
 name:          faas-swarm
 orchestration: swarm
 version:       0.8.5 
 sha:           bb8b883758b07c23314bea83195642a38f4b6301

I expected the tests to be run locally against docker swarm which adds and extra 2 labels, don't know if you are running against a different provider?

ewilde commented 4 years ago

Test run passes (with changing https://github.com/ewilde/terraform-provider-openfaas/pull/9/files#diff-0c265caa79e32560be818a2035276ac1R174 back to '2' )

make testacc
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./... -v  -timeout 120m
?       github.com/ewilde/terraform-provider-openfaas   [no test files]
2020/06/04 16:18:04 [DEBUG] returning provider schema
=== RUN   TestAccDataSourceOpenFaaSFunction_basic

Deployed. 202 Accepted.
URL: http://localhost:8080/function/testaccopenfaasfunction-basic-w4v2apny3h

Removing old function.
--- PASS: TestAccDataSourceOpenFaaSFunction_basic (0.17s)
=== RUN   TestAccOpenFaaSFunction_importBasic
    TestAccOpenFaaSFunction_importBasic: import_openfaas_function_test.go:12: Not working at the moment needs investigation
--- SKIP: TestAccOpenFaaSFunction_importBasic (0.00s)
=== RUN   TestProvider
--- PASS: TestProvider (0.00s)
=== RUN   TestAccResourceOpenFaaSFunction_basic

Deployed. 202 Accepted.
URL: http://localhost:8080/function/testaccopenfaasfunction-basic-finwjgdide

Removing old function.
--- PASS: TestAccResourceOpenFaaSFunction_basic (0.14s)
PASS
ok      github.com/ewilde/terraform-provider-openfaas/openfaas  0.323s
ewilde commented 4 years ago

@hugomcfonseca @laxgoalie392 release 3.2 is now available

laxgoalie392 commented 4 years ago

@ewilde wow thanks for the quick turn around time on this!

hugomcfonseca commented 4 years ago

@ewilde is it expected the bump from version v0.3.1 to version v3.2? I am assuming that was a typo and you were looking to release version v0.3.2

hugomcfonseca commented 4 years ago

@hugomcfonseca https://github.com/ewilde/terraform-provider-openfaas/pull/9/files#diff-0c265caa79e32560be818a2035276ac1R174

what is your setup for running the tests?

faas version
  ___                   _____           ____
 / _ \ _ __   ___ _ __ |  ___|_ _  __ _/ ___|
| | | | '_ \ / _ \ '_ \| |_ / _` |/ _` \___ \
| |_| | |_) |  __/ | | |  _| (_| | (_| |___) |
 \___/| .__/ \___|_| |_|_|  \__,_|\__,_|____/
      |_|

CLI:
 commit:  f7c29ea19b5df9d7aa87e9c70aacf4d9315da2cd
 version: 0.12.4

Gateway
 uri:     http://127.0.0.1:8080
 version: 0.18.13
 sha:     f6526929665cb05ceaca7c9c90a6bd7c5f32dca2
 commit:  Fix test on help description message

Provider
 name:          faas-swarm
 orchestration: swarm
 version:       0.8.5 
 sha:           bb8b883758b07c23314bea83195642a38f4b6301

I expected the tests to be run locally against docker swarm which adds and extra 2 labels, don't know if you are running against a different provider?

I run the tests against a Kubernetes cluster that was created using AWS EKS service, after installing the OpenFaaS using static manifests (still not using the Operator).

GitHub
Fix OpenFaaS client authentication to use authentication from Terraform provider initialization by hugomcfonseca · Pull Request #9 · ewilde/terraform-provider-openfaas
Currently, this provider was accepting user_name and password in Terraform provider initialization, but there is no reference in the code that uses it to instantiate the OpenFaaS client. This commi...