diff --git a/.changelog/703.txt b/.changelog/703.txt new file mode 100644 index 000000000..71714ca92 --- /dev/null +++ b/.changelog/703.txt @@ -0,0 +1,9 @@ +```release-note: enhancement +platform_connector_github.md - Added documentation for custom health connector +resource.tf - Example of github_app in credentials for github connector +go.mod - upgraded harness-go-sdk version to v0.3.52 +github.go - Added Schema and CRUD for github_app credentials in github connector +github_test.go - Test for schema and CRUD for github_app credentials in github connector +github_data_source.go - Added Schema for github_app credentials in github connector +github_data_source_test.go - Added test for Schema of github_app credentials in github connector +``` \ No newline at end of file diff --git a/docs/resources/platform_connector_github.md b/docs/resources/platform_connector_github.md index c926d94cf..f788a05d3 100644 --- a/docs/resources/platform_connector_github.md +++ b/docs/resources/platform_connector_github.md @@ -76,6 +76,34 @@ resource "harness_platform_connector_github" "test" { } } } + +resource "harness_platform_connector_github" "test" { + identifier = "identifier" + name = "name" + description = "test" + tags = ["foo:bar"] + + url = "https://github.com/account" + connection_type = "Account" + validation_repo = "some_repo" + delegate_selectors = ["harness-delegate"] + credentials { + http { + github_app { + installation_id = "installation_id" + application_id = "application_id" + private_key_ref = "account.secret_id" + } + } + } + api_authentication { + github_app { + installation_id = "installation_id" + application_id = "application_id" + private_key_ref = "account.secret_id" + } + } +} ``` @@ -123,6 +151,7 @@ Optional: - `username` (String) Username to use for authentication. - `username_ref` (String) Reference to a secret containing the username to use for authentication. To reference a secret at the organization scope, prefix 'org' to the expression: org.{identifier}. To reference a secret at the account scope, prefix 'account` to the expression: account.{identifier}. +- `github_app` (Block List, Max: 1) Configuration for using the github app for interacting with the github api. (see [below for nested schema](#nestedblock--api_authentication--github_app)) diff --git a/examples/resources/harness_platform_connector_github/resource.tf b/examples/resources/harness_platform_connector_github/resource.tf index f5d595ef5..ef9f85314 100644 --- a/examples/resources/harness_platform_connector_github/resource.tf +++ b/examples/resources/harness_platform_connector_github/resource.tf @@ -61,3 +61,31 @@ resource "harness_platform_connector_github" "test" { } } } + +resource "harness_platform_connector_github" "test" { + identifier = "identifier" + name = "name" + description = "test" + tags = ["foo:bar"] + + url = "https://github.com/account" + connection_type = "Account" + validation_repo = "some_repo" + delegate_selectors = ["harness-delegate"] + credentials { + http { + github_app { + installation_id = "installation_id" + application_id = "application_id" + private_key_ref = "account.secret_id" + } + } + api_authentication { + github_app { + installation_id = "installation_id" + application_id = "application_id" + private_key_ref = "account.secret_id" + } + } + } +} diff --git a/go.mod b/go.mod index 1c4795b0a..8699dfc78 100644 --- a/go.mod +++ b/go.mod @@ -4,8 +4,8 @@ go 1.18 require ( github.com/antihax/optional v1.0.0 - github.com/docker/docker v24.0.5+incompatible - github.com/harness/harness-go-sdk v0.3.49 + github.com/docker/docker v24.0.6+incompatible + github.com/harness/harness-go-sdk v0.3.52 github.com/harness/harness-openapi-go-client v0.0.19 github.com/hashicorp/go-cleanhttp v0.5.2 github.com/hashicorp/go-retryablehttp v0.7.4 @@ -71,7 +71,7 @@ require ( github.com/mitchellh/reflectwalk v1.0.2 // indirect github.com/oklog/run v1.1.0 // indirect github.com/opencontainers/go-digest v1.0.0 // indirect - github.com/opencontainers/image-spec v1.1.0-rc4 // indirect + github.com/opencontainers/image-spec v1.1.0-rc5 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect github.com/posener/complete v1.2.3 // indirect github.com/russross/blackfriday v1.6.0 // indirect @@ -82,15 +82,15 @@ require ( github.com/vmihailenco/msgpack/v5 v5.3.5 // indirect github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect github.com/zclconf/go-cty v1.13.2 // indirect - golang.org/x/crypto v0.12.0 // indirect + golang.org/x/crypto v0.13.0 // indirect golang.org/x/exp v0.0.0-20230626212559-97b1e661b5df // indirect golang.org/x/mod v0.12.0 // indirect - golang.org/x/net v0.14.0 // indirect - golang.org/x/oauth2 v0.11.0 // indirect - golang.org/x/sys v0.11.0 // indirect - golang.org/x/text v0.12.0 // indirect - golang.org/x/tools v0.12.0 // indirect - google.golang.org/appengine v1.6.7 // indirect + golang.org/x/net v0.15.0 // indirect + golang.org/x/oauth2 v0.12.0 // indirect + golang.org/x/sys v0.12.0 // indirect + golang.org/x/text v0.13.0 // indirect + golang.org/x/tools v0.13.0 // indirect + google.golang.org/appengine v1.6.8 // indirect google.golang.org/genproto/googleapis/rpc v0.0.0-20230822172742-b8732ec3820d // indirect google.golang.org/grpc v1.57.0 // indirect google.golang.org/protobuf v1.31.0 // indirect diff --git a/go.sum b/go.sum index 790c96cc3..fb2bbfa00 100644 --- a/go.sum +++ b/go.sum @@ -38,6 +38,8 @@ github.com/docker/distribution v2.8.2+incompatible h1:T3de5rq0dB1j30rp0sA2rER+m3 github.com/docker/distribution v2.8.2+incompatible/go.mod h1:J2gT2udsDAN96Uj4KfcMRqY0/ypR+oyYUYmja8H+y+w= github.com/docker/docker v24.0.5+incompatible h1:WmgcE4fxyI6EEXxBRxsHnZXrO1pQ3smi0k/jho4HLeY= github.com/docker/docker v24.0.5+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk= +github.com/docker/docker v24.0.6+incompatible h1:hceabKCtUgDqPu+qm0NgsaXf28Ljf4/pWFL7xjWWDgE= +github.com/docker/docker v24.0.6+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk= github.com/docker/go-connections v0.4.0 h1:El9xVISelRB7BuFusrZozjnkIM5YnzCViNKohAFqRJQ= github.com/docker/go-connections v0.4.0/go.mod h1:Gbd7IOopHjR8Iph03tsViu4nIes5XhDvyHbTtUxmeec= github.com/docker/go-units v0.5.0 h1:69rxXcBk27SvSaaxTtLh/8llcHD8vYHT7WSdRZ/jvr4= @@ -48,6 +50,7 @@ github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYF github.com/fatih/color v1.15.0 h1:kOqh6YHBtK8aywxGerMG2Eq3H6Qgoqeo13Bk2Mv/nBs= github.com/fatih/color v1.15.0/go.mod h1:0h5ZqXfHYED7Bhv2ZJamyIOUej9KtShiJESRwBDUSsw= github.com/go-git/gcfg v1.5.0 h1:Q5ViNfGF8zFgyJWPqYwA7qGFoMTEiBmdlkcfRmpIMa4= +github.com/go-git/gcfg v1.5.0/go.mod h1:5m20vg6GwYabIxaOonVkTdrILxQMpEShl1xiMF4ua+E= github.com/go-git/go-billy/v5 v5.4.1 h1:Uwp5tDRkPr+l/TnbHOQzp+tmJfLceOlbVucgpTz8ix4= github.com/go-git/go-git/v5 v5.6.1 h1:q4ZRqQl4pR/ZJHc1L5CFjGA1a10u76aV1iC+nh+bHsk= github.com/go-test/deep v1.0.3 h1:ZrJSEWsXzPOxaZnFteGEfooLba+ju3FYIbOrS+rQd68= @@ -56,6 +59,7 @@ github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69 github.com/golang/protobuf v1.1.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= +github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg= github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= @@ -70,6 +74,12 @@ github.com/harness/harness-go-sdk v0.3.48 h1:j/c52s/GwABtoetw35MfzEDqWZO85lZgdB+ github.com/harness/harness-go-sdk v0.3.48/go.mod h1:CPXydorp4zd5Dz2u2FXiHyWL4yd5PQafOMN69cgPSvk= github.com/harness/harness-go-sdk v0.3.49 h1:wtgo8/GEMjEjXyhfliKl1qlNqOGrnLpq8gdRghY1G9M= github.com/harness/harness-go-sdk v0.3.49/go.mod h1:CPXydorp4zd5Dz2u2FXiHyWL4yd5PQafOMN69cgPSvk= +github.com/harness/harness-go-sdk v0.3.52-0.20230926060052-2f31b439e1b5 h1:9xn/zlSiPS+PH/FIIqoG/eNwtW7X3+BgWldqUzF2E9Y= +github.com/harness/harness-go-sdk v0.3.52-0.20230926060052-2f31b439e1b5/go.mod h1:CPXydorp4zd5Dz2u2FXiHyWL4yd5PQafOMN69cgPSvk= +github.com/harness/harness-go-sdk v0.3.52-0.20230926100809-9d31d2a3e28f h1:oSytqFjklc0stiRDbuERWHl6PJ75pTCPOpbQK5DalRY= +github.com/harness/harness-go-sdk v0.3.52-0.20230926100809-9d31d2a3e28f/go.mod h1:CPXydorp4zd5Dz2u2FXiHyWL4yd5PQafOMN69cgPSvk= +github.com/harness/harness-go-sdk v0.3.52 h1:jXeGkBFBNRhQ3VvEcFZFl8+T5mVNPTrkeGAvqjgz3Ro= +github.com/harness/harness-go-sdk v0.3.52/go.mod h1:CPXydorp4zd5Dz2u2FXiHyWL4yd5PQafOMN69cgPSvk= github.com/harness/harness-openapi-go-client v0.0.19 h1:8XuZvSPZrNqKRLh7Qksdz78WvRMRzRf88LgzxoT5u7k= github.com/harness/harness-openapi-go-client v0.0.19/go.mod h1:u0vqYb994BJGotmEwJevF4L3BNAdU9i8ui2d22gmLPA= github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= @@ -128,6 +138,7 @@ github.com/imdario/mergo v0.3.11/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH github.com/imdario/mergo v0.3.13 h1:lFzP57bqS/wsqKssCGmtLAb8A0wKjLGrve2q3PPVcBk= github.com/imdario/mergo v0.3.13/go.mod h1:4lJ1jqUDcsbIECGy0RUJAXNIhg+6ocWgb1ALK2O4oXg= github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 h1:BQSFePA1RWJOlocH6Fxy8MmwDt+yVQYULKfN0RoTN8A= +github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99/go.mod h1:1lJo3i6rXxKeerYnT8Nvf0QmHCRC1n8sfWVwXF2Frvo= github.com/jhump/protoreflect v1.6.1 h1:4/2yi5LyDPP7nN+Hiird1SAJ6YoxUm13/oxHGRnbPd8= github.com/jhump/protoreflect v1.6.1/go.mod h1:RZQ/lnuN+zqeRVpQigTwO6o0AJUkxbnSnpuG7toUTG4= github.com/jinzhu/copier v0.4.0 h1:w3ciUoD19shMCRargcpm0cm91ytaBhDvuRpz1ODO/U8= @@ -162,6 +173,7 @@ github.com/mitchellh/cli v1.1.5/go.mod h1:v8+iFts2sPIKUV1ltktPXMCC8fumSKFItNcD2c github.com/mitchellh/copystructure v1.0.0/go.mod h1:SNtv71yrdKgLRyLFxmLdkAbkKEFWgYaq1OVrnRcwhnw= github.com/mitchellh/copystructure v1.2.0 h1:vpKXTN4ewci03Vljg/q9QvCGUDttBOGBIa15WveJJGw= github.com/mitchellh/copystructure v1.2.0/go.mod h1:qLl+cE2AmVv+CoeAwDPye/v+N2HKCj9FbZEVFJRxO9s= +github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= github.com/mitchellh/go-testing-interface v1.14.1 h1:jrgshOhYAUVNMAJiKbEu7EqAwgJJ2JqpQmpLJOu07cU= github.com/mitchellh/go-testing-interface v1.14.1/go.mod h1:gfgS7OtZj6MA4U1UrDRp04twqAjfvlZyCfX3sDjEym8= github.com/mitchellh/go-wordwrap v1.0.1 h1:TLuKupo69TCn6TQSyGxwI1EblZZEsQ0vMlAFQflz0v0= @@ -174,12 +186,15 @@ github.com/mitchellh/reflectwalk v1.0.2/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx github.com/moby/term v0.0.0-20221205130635-1aeaba878587 h1:HfkjXDfhgVaN5rmueG8cL8KKeFNecRCXFhaJ2qZ5SKA= github.com/morikuni/aec v1.0.0 h1:nP9CBfwrvYnBRgY6qfDQkygYDmYwOilePFkwzv4dU8A= github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs= +github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno= github.com/oklog/run v1.1.0 h1:GEenZ1cK0+q0+wsJew9qUg/DyD8k3JzYsZAi5gYi2mA= github.com/oklog/run v1.1.0/go.mod h1:sVPdnTZT1zYwAJeCMu2Th4T21pA3FPOQRfWjQlk7DVU= github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U= github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM= github.com/opencontainers/image-spec v1.1.0-rc4 h1:oOxKUJWnFC4YGHCCMNql1x4YaDfYBTS5Y4x/Cgeo1E0= github.com/opencontainers/image-spec v1.1.0-rc4/go.mod h1:X4pATf0uXsnn3g5aiGIsVnJBR4mxhKzfwmvK/B2NTm8= +github.com/opencontainers/image-spec v1.1.0-rc5 h1:Ygwkfw9bpDvs+c9E34SdgGOj41dX/cbdlwvlWt0pnFI= +github.com/opencontainers/image-spec v1.1.0-rc5/go.mod h1:X4pATf0uXsnn3g5aiGIsVnJBR4mxhKzfwmvK/B2NTm8= github.com/pjbgf/sha1cd v0.3.0 h1:4D5XXmUUBUl/xQ6IjCkEAbqXskkq/4O7LmGn0AqMDs4= github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= @@ -193,6 +208,7 @@ github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZV github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs= github.com/russross/blackfriday v1.6.0 h1:KqfZb0pUVN2lYqZUYRddxF4OR8ZMURnJIG5Y3VRLtww= github.com/russross/blackfriday v1.6.0/go.mod h1:ti0ldHuxg49ri4ksnFxlkCfN+hvslNlmVHqNRXXJNAY= +github.com/sebdah/goldie v1.0.0/go.mod h1:jXP4hmWywNEwZzhMuv2ccnqTSFpuq8iyQhtQdkkZBH4= github.com/sergi/go-diff v1.2.0 h1:XU+rvMAioB0UC3q1MFrIQy4Vo5/4VsRDQQXHsEya6xQ= github.com/shopspring/decimal v1.2.0/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o= github.com/shopspring/decimal v1.3.1 h1:2Usl1nmF/WZucqkFZhnfFYxxxu8LG21F6nPQBE5gKV8= @@ -234,6 +250,7 @@ github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9dec github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= github.com/zclconf/go-cty v1.13.2 h1:4GvrUxe/QUDYuJKAav4EYqdM47/kZa672LwmXFmEKT0= github.com/zclconf/go-cty v1.13.2/go.mod h1:YKQzy/7pZ7iq2jNFzy5go57xdxdWoLLpaEp4u238AE0= +github.com/zclconf/go-cty-debug v0.0.0-20191215020915-b22d67c1ba0b/go.mod h1:ZRKQfBXbGkpdV6QMzT3rU1kSTAnfu1dO8dPKjYprgj8= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20200414173820-0848c9571904/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= @@ -244,6 +261,8 @@ golang.org/x/crypto v0.3.1-0.20221117191849-2c476679df9a/go.mod h1:hebNnKkNXi2Uz golang.org/x/crypto v0.7.0/go.mod h1:pYwdfH91IfpZVANVyUOhSIPZaFoJGxTFbZhFTx+dXZU= golang.org/x/crypto v0.12.0 h1:tFM/ta59kqch6LlvYnPa0yx5a83cL2nHflFhYKvv9Yk= golang.org/x/crypto v0.12.0/go.mod h1:NF0Gs7EO5K4qLn+Ylc+fih8BSTeIjAP05siRnAh98yw= +golang.org/x/crypto v0.13.0 h1:mvySKfSWJ+UKUii46M40LOvyWfN0s2U+46/jDd0e6Ck= +golang.org/x/crypto v0.13.0/go.mod h1:y6Z2r+Rw4iayiXXAIxJIDAJ1zMW4yaTpebo8fPOliYc= golang.org/x/exp v0.0.0-20230626212559-97b1e661b5df h1:UA2aFVmmsIlefxMk29Dp2juaUSth8Pyn3Tq5Y5mJGME= golang.org/x/exp v0.0.0-20230626212559-97b1e661b5df/go.mod h1:FXUEEKJgO7OQYeo8N01OfiKP8RXMtf6e8aTskBGqWdc= golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= @@ -265,8 +284,12 @@ golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= golang.org/x/net v0.8.0/go.mod h1:QVkue5JL9kW//ek3r6jTKnTFis1tRmNAW2P1shuFdJc= golang.org/x/net v0.14.0 h1:BONx9s002vGdD9umnlX1Po8vOZmrgH34qlHcD1MfK14= golang.org/x/net v0.14.0/go.mod h1:PpSgVXXLK0OxS0F31C1/tv6XNguvCrnXIDrFMspZIUI= +golang.org/x/net v0.15.0 h1:ugBLEUaxABaB5AJqW9enI0ACdci2RUd4eP51NTBvuJ8= +golang.org/x/net v0.15.0/go.mod h1:idbUs1IY1+zTqbi8yxTbhexhEEk5ur9LInksu6HrEpk= golang.org/x/oauth2 v0.11.0 h1:vPL4xzxBM4niKCW6g9whtaWVXTJf1U5e4aZxxFx/gbU= golang.org/x/oauth2 v0.11.0/go.mod h1:LdF7O/8bLR/qWK9DrpXmbHLTouvRHK0SgJl0GmDBchk= +golang.org/x/oauth2 v0.12.0 h1:smVPGxink+n1ZI5pkQa8y6fZT0RW0MgCO5bFpepy4B4= +golang.org/x/oauth2 v0.12.0/go.mod h1:A74bZ3aGXgCY0qaIC9Ahg6Lglin4AMAco8cIv9baba4= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= @@ -298,6 +321,8 @@ golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.11.0 h1:eG7RXZHdqOJ1i+0lgLgCpSXAp6M3LYlAo6osgSi0xOM= golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.12.0 h1:CM0HF96J0hcLAwsHPJZjfdNzs0gftsLfgKt57wWHJ0o= +golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.1.0/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= @@ -308,11 +333,14 @@ golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= +golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ= golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= golang.org/x/text v0.8.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= golang.org/x/text v0.12.0 h1:k+n5B8goJNdU7hSvEtMUz3d1Q6D/XW4COJSJR6fN0mc= golang.org/x/text v0.12.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= +golang.org/x/text v0.13.0 h1:ablQoSUd0tRdKxZewP80B+BaqeKJuVhuRxj/dkrun3k= +golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= golang.org/x/time v0.0.0-20210723032227-1f47c861a9ac h1:7zkz7BUtwNFFqcowJ+RIgu2MaV/MapERkDIy+mwPyjs= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= @@ -324,6 +352,8 @@ golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU= golang.org/x/tools v0.12.0 h1:YW6HUoUmYBpwSgyaGaZq1fHjrBjX1rlpZ54T6mu2kss= golang.org/x/tools v0.12.0/go.mod h1:Sc0INKfu04TlqNoRA1hgpFZbhYXHPr4V5DzpSBTPqQM= +golang.org/x/tools v0.13.0 h1:Iey4qkscZuv0VvIt8E0neZjtPVQFSc870HQ448QgEmQ= +golang.org/x/tools v0.13.0/go.mod h1:HvlwmtVNQAhOuCjW7xxvovg8wbNq7LwfXh/k7wXUl58= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= @@ -331,6 +361,8 @@ golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8T google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= google.golang.org/appengine v1.6.7 h1:FZR1q0exgwxzPzp/aF+VccGrSfxfPpkBqjIIEq3ru6c= google.golang.org/appengine v1.6.7/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc= +google.golang.org/appengine v1.6.8 h1:IhEN5q69dyKagZPYMSdIjS2HqprW324FRQZJcGqPAsM= +google.golang.org/appengine v1.6.8/go.mod h1:1jJ3jBArFh5pcgW8gCtRJnepW8FzD1V44FJffLiz/Ds= google.golang.org/genproto v0.0.0-20170818010345-ee236bd376b0/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= google.golang.org/genproto/googleapis/rpc v0.0.0-20230822172742-b8732ec3820d h1:uvYuEyMHKNt+lT4K3bN6fGswmK8qSvcreM3BwjDh+y4= google.golang.org/genproto/googleapis/rpc v0.0.0-20230822172742-b8732ec3820d/go.mod h1:+Bk1OCOj40wS2hwAMA+aCW9ypzm63QTBBHp6lQ3p+9M= @@ -344,7 +376,9 @@ google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqw gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f h1:BLraFXnmrev5lT+xlilqcH8XK9/i0At2xKjWk4p6zsU= +gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/warnings.v0 v0.1.2 h1:wFXVbFY8DY5/xOe1ECiWdKCzZlxgshcYVNkBHstARME= +gopkg.in/warnings.v0 v0.1.2/go.mod h1:jksf8JmL6Qr/oQM2OXTHunEvvTAsrWBLb6OOjuVWRNI= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= diff --git a/internal/service/platform/connector/github.go b/internal/service/platform/connector/github.go index 2c0d1e97c..8bc9eeef1 100644 --- a/internal/service/platform/connector/github.go +++ b/internal/service/platform/connector/github.go @@ -134,19 +134,63 @@ func ResourceConnectorGithub() *schema.Resource { Type: schema.TypeString, Optional: true, ConflictsWith: []string{"credentials.0.http.0.username_ref"}, - ExactlyOneOf: []string{"credentials.0.http.0.username", "credentials.0.http.0.username_ref"}, + ExactlyOneOf: []string{"credentials.0.http.0.username", "credentials.0.http.0.username_ref", "credentials.0.http.0.github_app"}, }, "username_ref": { Description: "Reference to a secret containing the username to use for authentication." + secret_ref_text, Type: schema.TypeString, Optional: true, ConflictsWith: []string{"credentials.0.http.0.username"}, - ExactlyOneOf: []string{"credentials.0.http.0.username", "credentials.0.http.0.username_ref"}, + ExactlyOneOf: []string{"credentials.0.http.0.username", "credentials.0.http.0.username_ref", "credentials.0.http.0.github_app"}, }, "token_ref": { Description: "Reference to a secret containing the personal access to use for authentication." + secret_ref_text, Type: schema.TypeString, - Required: true, + Optional: true, + }, + "github_app": { + Description: "Configuration for using the github app for interacting with the github api.", + Type: schema.TypeList, + Optional: true, + MaxItems: 1, + ExactlyOneOf: []string{"credentials.0.http.0.username", "credentials.0.http.0.username_ref", "credentials.0.http.0.github_app"}, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "installation_id": { + Description: "Enter the Installation ID located in the URL of the installed GitHub App.", + Type: schema.TypeString, + Optional: true, + ConflictsWith: []string{"credentials.0.http.0.github_app.0.installation_id_ref"}, + ExactlyOneOf: []string{"credentials.0.http.0.github_app.0.installation_id", "credentials.0.http.0.github_app.0.installation_id_ref"}, + }, + "application_id": { + Description: "Enter the GitHub App ID from the GitHub App General tab.", + Type: schema.TypeString, + Optional: true, + ConflictsWith: []string{"credentials.0.http.0.github_app.0.application_id_ref"}, + ExactlyOneOf: []string{"credentials.0.http.0.github_app.0.application_id", "credentials.0.http.0.github_app.0.application_id_ref"}, + }, + "application_id_ref": { + Description: "Reference to the secret containing application id" + secret_ref_text, + Type: schema.TypeString, + Optional: true, + ConflictsWith: []string{"credentials.0.http.0.github_app.0.application_id"}, + ExactlyOneOf: []string{"credentials.0.http.0.github_app.0.application_id", "credentials.0.http.0.github_app.0.application_id_ref"}, + }, + "installation_id_ref": { + Description: "Reference to the secret containing installation id." + secret_ref_text, + Type: schema.TypeString, + Optional: true, + ConflictsWith: []string{"credentials.0.http.0.github_app.0.installation_id"}, + ExactlyOneOf: []string{"credentials.0.http.0.github_app.0.installation_id", "credentials.0.http.0.github_app.0.installation_id_ref"}, + }, + "private_key_ref": { + Description: "Reference to the secret containing the private key." + secret_ref_text, + Type: schema.TypeString, + Required: true, + }, + }, + }, }, }, }, @@ -260,6 +304,37 @@ func buildConnectorGithub(d *schema.ResourceData) *nextgen.ConnectorInfo { if attr, ok := httpConfig["token_ref"]; ok { connector.Github.Authentication.Http.UsernameToken.TokenRef = attr.(string) } + + if attr, ok := httpConfig["github_app"].([]interface{}); ok && len(attr) > 0 { + httpConfig := attr[0].(map[string]interface{}) + connector.Github.Authentication.Http.Type_ = nextgen.GithubHttpCredentialTypes.GithubApp + connector.Github.Authentication.Http = &nextgen.GithubHttpCredentials{ + Type_: nextgen.GithubHttpCredentialTypes.GithubApp, + GithubApp: &nextgen.GithubAppSpec{}, + } + + if attr, ok := httpConfig["installation_id"]; ok { + connector.Github.Authentication.Http.GithubApp.InstallationId = attr.(string) + } + + if attr, ok := httpConfig["application_id"]; ok { + connector.Github.Authentication.Http.GithubApp.ApplicationId = attr.(string) + } + + if attr, ok := httpConfig["private_key_ref"]; ok { + connector.Github.Authentication.Http.GithubApp.PrivateKeyRef = attr.(string) + } + + if attr, ok := httpConfig["installation_id_ref"]; ok { + connector.Github.Authentication.Http.GithubApp.InstallationIdRef = attr.(string) + } + + if attr, ok := httpConfig["application_id_ref"]; ok { + connector.Github.Authentication.Http.GithubApp.ApplicationIdRef = attr.(string) + } + + } + } if attr := credConfig["ssh"].([]interface{}); len(attr) > 0 { @@ -339,6 +414,26 @@ func readConnectorGithub(d *schema.ResourceData, connector *nextgen.ConnectorInf }, }, }) + break + case nextgen.GithubHttpCredentialTypes.GithubApp: + d.Set("credentials", []map[string]interface{}{ + { + "http": []map[string]interface{}{ + { + "github_app": []map[string]interface{}{ + { + "installation_id": connector.Github.Authentication.Http.GithubApp.InstallationId, + "application_id": connector.Github.Authentication.Http.GithubApp.ApplicationId, + "private_key_ref": connector.Github.Authentication.Http.GithubApp.PrivateKeyRef, + "installation_id_ref": connector.Github.Authentication.Http.GithubApp.InstallationIdRef, + "application_id_ref": connector.Github.Authentication.Http.GithubApp.ApplicationIdRef, + }, + }, + }, + }, + }, + }) + break default: return fmt.Errorf("unsupported github http authentication type: %s", connector.Github.Authentication.Type_) } diff --git a/internal/service/platform/connector/github_data_source.go b/internal/service/platform/connector/github_data_source.go index 31913d3cc..30ba4d82d 100644 --- a/internal/service/platform/connector/github_data_source.go +++ b/internal/service/platform/connector/github_data_source.go @@ -116,6 +116,40 @@ func DatasourceConnectorGithub() *schema.Resource { Type: schema.TypeString, Computed: true, }, + "github_app": { + Description: "Configuration for using the github app for interacting with the github api.", + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "installation_id": { + Description: "Enter the Installation ID located in the URL of the installed GitHub App.", + Type: schema.TypeString, + Computed: true, + }, + "application_id": { + Description: "Enter the GitHub App ID from the GitHub App General tab.", + Type: schema.TypeString, + Computed: true, + }, + "application_id_ref": { + Description: "Reference to the secret containing application id" + secret_ref_text, + Type: schema.TypeString, + Computed: true, + }, + "installation_id_ref": { + Description: "Reference to the secret containing installation id." + secret_ref_text, + Type: schema.TypeString, + Computed: true, + }, + "private_key_ref": { + Description: "Reference to the secret containing the private key." + secret_ref_text, + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, }, }, }, diff --git a/internal/service/platform/connector/github_data_source_test.go b/internal/service/platform/connector/github_data_source_test.go index b61855acb..784e8e362 100644 --- a/internal/service/platform/connector/github_data_source_test.go +++ b/internal/service/platform/connector/github_data_source_test.go @@ -42,6 +42,40 @@ func TestAccDataSourceConnectorGithub(t *testing.T) { }) } +func TestAccDataSourceConnectorGithub_github_app(t *testing.T) { + + var ( + name = fmt.Sprintf("%s_%s", t.Name(), utils.RandStringBytes(4)) + resourceName = "data.harness_platform_connector_github.test" + ) + + resource.UnitTest(t, resource.TestCase{ + PreCheck: func() { acctest.TestAccPreCheck(t) }, + ProviderFactories: acctest.ProviderFactories, + ExternalProviders: map[string]resource.ExternalProvider{ + "time": {}, + }, + Steps: []resource.TestStep{ + { + Config: testAccDataSourceConnectorGithub_github_app(name), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr(resourceName, "id", name), + resource.TestCheckResourceAttr(resourceName, "identifier", name), + resource.TestCheckResourceAttr(resourceName, "name", name), + resource.TestCheckResourceAttr(resourceName, "description", "test"), + resource.TestCheckResourceAttr(resourceName, "tags.#", "1"), + resource.TestCheckResourceAttr(resourceName, "url", "https://github.com/account"), + resource.TestCheckResourceAttr(resourceName, "connection_type", "Account"), + resource.TestCheckResourceAttr(resourceName, "validation_repo", "some_repo"), + resource.TestCheckResourceAttr(resourceName, "delegate_selectors.#", "1"), + resource.TestCheckResourceAttr(resourceName, "credentials.0.http.0.github_app.0.installation_id", "install123"), + resource.TestCheckResourceAttr(resourceName, "credentials.0.http.0.github_app.0.application_id", "app123"), + ), + }, + }, + }) +} + func testAccDataSourceConnectorGithub(name string) string { return fmt.Sprintf(` resource "harness_platform_secret_text" "test" { @@ -84,3 +118,49 @@ func testAccDataSourceConnectorGithub(name string) string { } `, name) } + +func testAccDataSourceConnectorGithub_github_app(name string) string { + return fmt.Sprintf(` + resource "harness_platform_secret_text" "test" { + identifier = "%[1]s" + name = "%[1]s" + description = "test" + tags = ["foo:bar"] + + secret_manager_identifier = "harnessSecretManager" + value_type = "Inline" + value = "secret" + } + + resource "harness_platform_connector_github" "test" { + identifier = "%[1]s" + name = "%[1]s" + description = "test" + tags = ["foo:bar"] + + url = "https://github.com/account" + connection_type = "Account" + validation_repo = "some_repo" + delegate_selectors = ["harness-delegate"] + credentials { + http { + github_app { + installation_id = "install123" + application_id = "app123" + private_key_ref = "account.${harness_platform_secret_text.test.id}" + } + } + } + depends_on = [time_sleep.wait_4_seconds] + } + + resource "time_sleep" "wait_4_seconds" { + depends_on = [harness_platform_secret_text.test] + destroy_duration = "4s" + } + + data "harness_platform_connector_github" "test" { + identifier = harness_platform_connector_github.test.identifier + } + `, name) +} diff --git a/internal/service/platform/connector/github_test.go b/internal/service/platform/connector/github_test.go index 1cc539a09..0e705692b 100644 --- a/internal/service/platform/connector/github_test.go +++ b/internal/service/platform/connector/github_test.go @@ -306,6 +306,63 @@ func TestAccResourceConnectorGithub_api_app_1(t *testing.T) { }) } +func TestAccResourceConnectorGithub_app_credential(t *testing.T) { + + id := fmt.Sprintf("%s_%s", t.Name(), utils.RandStringBytes(5)) + name := id + updatedName := fmt.Sprintf("%s_updated", name) + resourceName := "harness_platform_connector_github.test" + + resource.UnitTest(t, resource.TestCase{ + PreCheck: func() { acctest.TestAccPreCheck(t) }, + ProviderFactories: acctest.ProviderFactories, + ExternalProviders: map[string]resource.ExternalProvider{ + "time": {}, + }, + CheckDestroy: testAccConnectorDestroy(resourceName), + + Steps: []resource.TestStep{ + { + Config: testAccResourceConnectorGithub_app_credential(id, name), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr(resourceName, "id", id), + resource.TestCheckResourceAttr(resourceName, "identifier", id), + resource.TestCheckResourceAttr(resourceName, "name", name), + resource.TestCheckResourceAttr(resourceName, "description", "test"), + resource.TestCheckResourceAttr(resourceName, "tags.#", "1"), + resource.TestCheckResourceAttr(resourceName, "url", "https://github.com/account"), + resource.TestCheckResourceAttr(resourceName, "connection_type", "Account"), + resource.TestCheckResourceAttr(resourceName, "validation_repo", "some_repo"), + resource.TestCheckResourceAttr(resourceName, "delegate_selectors.#", "1"), + resource.TestCheckResourceAttr(resourceName, "credentials.0.http.0.github_app.0.installation_id", "install123"), + resource.TestCheckResourceAttr(resourceName, "credentials.0.http.0.github_app.0.application_id", "app123"), + resource.TestCheckResourceAttr(resourceName, "api_authentication.0.github_app.0.installation_id", "install123"), + resource.TestCheckResourceAttr(resourceName, "api_authentication.0.github_app.0.application_id", "app123"), + ), + }, + { + Config: testAccResourceConnectorGithub_app_credential(id, updatedName), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr(resourceName, "id", id), + resource.TestCheckResourceAttr(resourceName, "identifier", id), + resource.TestCheckResourceAttr(resourceName, "name", updatedName), + resource.TestCheckResourceAttr(resourceName, "description", "test"), + resource.TestCheckResourceAttr(resourceName, "tags.#", "1"), + resource.TestCheckResourceAttr(resourceName, "credentials.0.http.0.github_app.0.installation_id", "install123"), + resource.TestCheckResourceAttr(resourceName, "credentials.0.http.0.github_app.0.application_id", "app123"), + resource.TestCheckResourceAttr(resourceName, "api_authentication.0.github_app.0.installation_id", "install123"), + resource.TestCheckResourceAttr(resourceName, "api_authentication.0.github_app.0.application_id", "app123"), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + func TestAccResourceConnectorGithub_token(t *testing.T) { id := fmt.Sprintf("%s_%s", t.Name(), utils.RandStringBytes(5)) @@ -680,3 +737,55 @@ func testAccResourceConnectorGithub_api_app_ref(id string, name string) string { } `, id, name) } + +func testAccResourceConnectorGithub_app_credential(id string, name string) string { + return fmt.Sprintf(` + resource "harness_platform_secret_text" "test" { + identifier = "%[1]s" + name = "%[2]s" + description = "test" + tags = ["foo:bar"] + + secret_manager_identifier = "harnessSecretManager" + value_type = "Inline" + value = "secret" + } + + resource "harness_platform_connector_github" "test" { + identifier = "%[1]s" + name = "%[2]s" + description = "test" + tags = ["foo:bar"] + + url = "https://github.com/account" + connection_type = "Account" + validation_repo = "some_repo" + delegate_selectors = ["harness-delegate"] + credentials { + http { + github_app { + installation_id = "install123" + application_id = "app123" + private_key_ref = "account.${harness_platform_secret_text.test.id}" + } + // username = "admin" + // token_ref = "account.${harness_platform_secret_text.test.id}" + } + + } + api_authentication { + github_app { + installation_id = "install123" + application_id = "app123" + private_key_ref = "account.${harness_platform_secret_text.test.id}" + } + } + depends_on = [time_sleep.wait_4_seconds] + } + + resource "time_sleep" "wait_4_seconds" { + depends_on = [harness_platform_secret_text.test] + destroy_duration = "4s" + } +`, id, name) +}