Skip to content

Conversation

@bengesoff
Copy link
Contributor

@bengesoff bengesoff commented Jul 27, 2022

The https://pkg.go.dev/github.com/elastic/go-elasticsearch/v8 client supports both username/password auth, as well as API Key. However the Terraform provider currently only supports username/password. I've made a quick change to allow the API Key to be specified instead. It is mainly just a schema change, and then the API client config needs to use the value from the provider schema.

I've tested this with one of my local projects, and it successfully created the user and role resources using only the API Key. Also the acceptance tests pass:

TF_ACC=1 go test -v ./... -count 1 -parallel 10  -timeout 120m
?       github.com/elastic/terraform-provider-elasticstack      [no test files]
?       github.com/elastic/terraform-provider-elasticstack/internal/acctest     [no test files]
?       github.com/elastic/terraform-provider-elasticstack/internal/clients     [no test files]
=== RUN   TestAccResourceClusterSettings
--- PASS: TestAccResourceClusterSettings (14.60s)
=== RUN   TestAccResourceSLM
--- PASS: TestAccResourceSLM (14.59s)
=== RUN   TestAccDataSourceSnapRepoFs
--- PASS: TestAccDataSourceSnapRepoFs (9.49s)
=== RUN   TestAccDataSourceSnapRepoUrl
--- PASS: TestAccDataSourceSnapRepoUrl (9.49s)
=== RUN   TestAccResourceSnapRepoFs
--- PASS: TestAccResourceSnapRepoFs (6.98s)
=== RUN   TestAccResourceSnapRepoUrl
--- PASS: TestAccResourceSnapRepoUrl (10.43s)
PASS
ok      github.com/elastic/terraform-provider-elasticstack/internal/elasticsearch/cluster       65.782s
=== RUN   TestAccResourceComponentTemplate
--- PASS: TestAccResourceComponentTemplate (12.73s)
=== RUN   TestAccResourceDataStream
--- PASS: TestAccResourceDataStream (9.19s)
=== RUN   TestAccResourceILM
--- PASS: TestAccResourceILM (11.57s)
=== RUN   TestAccResourceIndex
--- PASS: TestAccResourceIndex (11.79s)
=== RUN   TestAccResourceIndexTemplate
--- PASS: TestAccResourceIndexTemplate (10.19s)
PASS
ok      github.com/elastic/terraform-provider-elasticstack/internal/elasticsearch/index 55.673s
=== RUN   TestAccResourceIngestPipeline
--- PASS: TestAccResourceIngestPipeline (14.66s)
=== RUN   TestAccDataSourceIngestProcessorAppend
--- PASS: TestAccDataSourceIngestProcessorAppend (10.00s)
=== RUN   TestAccDataSourceIngestProcessorBytes
--- PASS: TestAccDataSourceIngestProcessorBytes (8.86s)
=== RUN   TestAccDataSourceIngestProcessorCircle
--- PASS: TestAccDataSourceIngestProcessorCircle (9.30s)
=== RUN   TestAccDataSourceIngestProcessorCommunityId
--- PASS: TestAccDataSourceIngestProcessorCommunityId (5.90s)
=== RUN   TestAccDataSourceIngestProcessorConvert
--- PASS: TestAccDataSourceIngestProcessorConvert (8.71s)
=== RUN   TestAccDataSourceIngestProcessorCSV
--- PASS: TestAccDataSourceIngestProcessorCSV (9.53s)
=== RUN   TestAccDataSourceIngestProcessorDate
--- PASS: TestAccDataSourceIngestProcessorDate (8.04s)
=== RUN   TestAccDataSourceIngestProcessorDateIndexName
--- PASS: TestAccDataSourceIngestProcessorDateIndexName (11.23s)
=== RUN   TestAccDataSourceIngestProcessorDissect
--- PASS: TestAccDataSourceIngestProcessorDissect (5.55s)
=== RUN   TestAccDataSourceIngestProcessorDotExpander
--- PASS: TestAccDataSourceIngestProcessorDotExpander (5.16s)
=== RUN   TestAccDataSourceIngestProcessorDrop
--- PASS: TestAccDataSourceIngestProcessorDrop (5.13s)
=== RUN   TestAccDataSourceIngestProcessorFail
--- PASS: TestAccDataSourceIngestProcessorFail (5.12s)
=== RUN   TestAccDataSourceIngestProcessorFingerprint
--- PASS: TestAccDataSourceIngestProcessorFingerprint (4.84s)
=== RUN   TestAccDataSourceIngestProcessorForeach
--- PASS: TestAccDataSourceIngestProcessorForeach (3.85s)
=== RUN   TestAccDataSourceIngestProcessorGeoip
--- PASS: TestAccDataSourceIngestProcessorGeoip (4.74s)
=== RUN   TestAccDataSourceIngestProcessorGrok
--- PASS: TestAccDataSourceIngestProcessorGrok (3.88s)
=== RUN   TestAccDataSourceIngestProcessorGsub
--- PASS: TestAccDataSourceIngestProcessorGsub (4.20s)
=== RUN   TestAccDataSourceIngestProcessorHtmlStrip
--- PASS: TestAccDataSourceIngestProcessorHtmlStrip (4.38s)
=== RUN   TestAccDataSourceIngestProcessorJoin
--- PASS: TestAccDataSourceIngestProcessorJoin (3.94s)
=== RUN   TestAccDataSourceIngestProcessorJson
--- PASS: TestAccDataSourceIngestProcessorJson (3.94s)
=== RUN   TestAccDataSourceIngestProcessorKV
--- PASS: TestAccDataSourceIngestProcessorKV (3.95s)
=== RUN   TestAccDataSourceIngestProcessorLowercase
--- PASS: TestAccDataSourceIngestProcessorLowercase (3.60s)
=== RUN   TestAccDataSourceIngestProcessorNetworkDirection
--- PASS: TestAccDataSourceIngestProcessorNetworkDirection (3.92s)
=== RUN   TestAccDataSourceIngestProcessorPipeline
--- PASS: TestAccDataSourceIngestProcessorPipeline (4.27s)
=== RUN   TestAccDataSourceIngestProcessorRegisteredDomain
--- PASS: TestAccDataSourceIngestProcessorRegisteredDomain (3.50s)
=== RUN   TestAccDataSourceIngestProcessorRemove
--- PASS: TestAccDataSourceIngestProcessorRemove (3.73s)
=== RUN   TestAccDataSourceIngestProcessorRename
--- PASS: TestAccDataSourceIngestProcessorRename (3.74s)
=== RUN   TestAccDataSourceIngestProcessorScript
--- PASS: TestAccDataSourceIngestProcessorScript (3.56s)
=== RUN   TestAccDataSourceIngestProcessorSet
--- PASS: TestAccDataSourceIngestProcessorSet (3.39s)
=== RUN   TestAccDataSourceIngestProcessorSetSecurityUser
--- PASS: TestAccDataSourceIngestProcessorSetSecurityUser (3.73s)
=== RUN   TestAccDataSourceIngestProcessorSort
--- PASS: TestAccDataSourceIngestProcessorSort (3.65s)
=== RUN   TestAccDataSourceIngestProcessorSplit
--- PASS: TestAccDataSourceIngestProcessorSplit (4.85s)
=== RUN   TestAccDataSourceIngestProcessorTrim
--- PASS: TestAccDataSourceIngestProcessorTrim (3.41s)
=== RUN   TestAccDataSourceIngestProcessorUppercase
--- PASS: TestAccDataSourceIngestProcessorUppercase (4.14s)
=== RUN   TestAccDataSourceIngestProcessorUriParts
--- PASS: TestAccDataSourceIngestProcessorUriParts (4.40s)
=== RUN   TestAccDataSourceIngestProcessorUrldecode
--- PASS: TestAccDataSourceIngestProcessorUrldecode (4.42s)
=== RUN   TestAccDataSourceIngestProcessorUserAgent
--- PASS: TestAccDataSourceIngestProcessorUserAgent (4.75s)
PASS
ok      github.com/elastic/terraform-provider-elasticstack/internal/elasticsearch/ingest        208.315s
=== RUN   TestAccResourceSecurityRole
--- PASS: TestAccResourceSecurityRole (15.28s)
=== RUN   TestAccDataSourceSecurityUser
--- PASS: TestAccDataSourceSecurityUser (13.49s)
=== RUN   TestAccResourceSecurityUser
--- PASS: TestAccResourceSecurityUser (10.84s)
PASS
ok      github.com/elastic/terraform-provider-elasticstack/internal/elasticsearch/security      39.764s
?       github.com/elastic/terraform-provider-elasticstack/internal/models      [no test files]
=== RUN   TestProvider
--- PASS: TestProvider (0.01s)
PASS
ok      github.com/elastic/terraform-provider-elasticstack/internal/provider    0.021s
=== RUN   TestFlattenMap
=== PAUSE TestFlattenMap
=== RUN   TestDiffIndexTemplateSuppress
=== PAUSE TestDiffIndexTemplateSuppress
=== CONT  TestFlattenMap
--- PASS: TestFlattenMap (0.00s)
=== CONT  TestDiffIndexTemplateSuppress
--- PASS: TestDiffIndexTemplateSuppress (0.00s)
PASS
ok      github.com/elastic/terraform-provider-elasticstack/internal/utils       0.031s

Fixes #71

@elasticmachine
Copy link

Since this is a community submitted pull request, a Jenkins build has not been kicked off automatically. Can an Elastic organization member please verify the contents of this patch and then kick off a build manually?

@cla-checker-service
Copy link

cla-checker-service bot commented Jul 27, 2022

💚 CLA has been signed

@ivan-penchev
Copy link

Great work @bengesoff this is literally what my organization had need of. @tobio could you please look into this?

@tobio
Copy link
Member

tobio commented Jul 28, 2022

jenkins test this

tobio
tobio previously approved these changes Jul 28, 2022
Copy link
Member

@tobio tobio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this, it's incredibly useful!

@bengesoff can you add a changelog entry for this PR as well.

@tobio tobio dismissed their stale review July 28, 2022 11:12

Because I only think of the changelog .5s after hitting the approve button.

@bengesoff
Copy link
Contributor Author

@tobio thanks for taking a look! I have updated the changelog - does it look ok?

@tobio
Copy link
Member

tobio commented Jul 28, 2022

jenkins test this

@bengesoff
Copy link
Contributor Author

@tobio looks like the tests were ok - is there anything else I need to do? 🙂

@tobio tobio merged commit 6e929b4 into elastic:main Jul 28, 2022
@tobio
Copy link
Member

tobio commented Jul 28, 2022

is there anything else I need to do?

Nope, this is great thanks!

@bengesoff bengesoff deleted the add-api-key-option branch July 29, 2022 08:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]Need API key to authenticate from terraform to Elasticstack

4 participants