diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 9776db7..4b8afc1 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -28,7 +28,7 @@ jobs: name: Set up Go uses: actions/setup-go@v2 with: - go-version: 1.14 + go-version: 1.20 - name: Import GPG key id: import_gpg diff --git a/LICENSE b/LICENSE index 9dc617f..774910c 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,7 @@ MIT License Copyright (c) 2018 cognotekt GmbH +Copyright (c) 2023 Enthought, Inc. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index 54ef3f6..5ac248b 100644 --- a/README.md +++ b/README.md @@ -3,22 +3,22 @@ ## Requirements - [Terraform](https://www.terraform.io/downloads.html) 0.13+ -- [Go](https://golang.org/doc/install) 1.14 (to build the provider plugin) +- [Go](https://golang.org/doc/install) 1.20 ## Building The Provider -Clone repository to: `$GOPATH/src/github.com/cognotektgmbh/terraform-provider-jumpcloud` +Clone repository to: `$GOPATH/src/github.com/enthought/terraform-provider-jumpcloud` ```sh -mkdir -p $GOPATH/src/github.com/cognotektgmbh -cd $GOPATH/src/github.com/cognotektgmbh -git clone git@github.com:cognotektgmbh/terraform-provider-jumpcloud +mkdir -p $GOPATH/src/github.com/enthought +cd $GOPATH/src/github.com/enthought +git clone git@github.com:enthought/terraform-provider-jumpcloud ``` Enter the provider directory and build the provider ```sh -cd $GOPATH/src/github.com/cognotektgmbh/terraform-provider-jumpcloud +cd $GOPATH/src/github.com/enthought/terraform-provider-jumpcloud make build ``` diff --git a/examples/system-groups/users.tf b/examples/system-groups/users.tf index 5783e51..176bbd3 100644 --- a/examples/system-groups/users.tf +++ b/examples/system-groups/users.tf @@ -1,8 +1,5 @@ resource "jumpcloud_user_group" "test_group" { name = "test_group" - attributes = { - posix_groups = "32:testerino" - } } resource "jumpcloud_user" "test_user1" { diff --git a/examples/user-groups-with-ldap/main.tf b/examples/user-groups-with-ldap/main.tf index 87b3104..8a07308 100644 --- a/examples/user-groups-with-ldap/main.tf +++ b/examples/user-groups-with-ldap/main.tf @@ -1,8 +1,5 @@ resource "jumpcloud_user_group" "test_group" { name = "test_group" - attributes = { - posix_groups = "32:testerino" - } } resource "jumpcloud_user" "test_user1" { diff --git a/examples/user-groups/main.tf b/examples/user-groups/main.tf index c4b870d..df6cddf 100644 --- a/examples/user-groups/main.tf +++ b/examples/user-groups/main.tf @@ -1,8 +1,5 @@ resource "jumpcloud_user_group" "test_group" { name = "test_group" - attributes = { - posix_groups = "32:testerino" - } } resource "jumpcloud_user" "test_user1" { diff --git a/go.mod b/go.mod index 3a03b77..9c59576 100644 --- a/go.mod +++ b/go.mod @@ -1,9 +1,59 @@ -module github.com/cognotektgmbh/terraform-provider-jumpcloud +module github.com/enthought/terraform-provider-jumpcloud -go 1.15 +go 1.20 require ( - github.com/TheJumpCloud/jcapi-go v2.4.0+incompatible - github.com/hashicorp/terraform-plugin-sdk v1.13.1 - github.com/stretchr/testify v1.5.1 + github.com/TheJumpCloud/jcapi-go v3.0.0+incompatible + github.com/hashicorp/terraform-plugin-sdk/v2 v2.27.0 +) + +require ( + github.com/ProtonMail/go-crypto v0.0.0-20230217124315-7d5c6f04bbb8 // indirect + github.com/agext/levenshtein v1.2.2 // indirect + github.com/apparentlymart/go-textseg/v13 v13.0.0 // indirect + github.com/cloudflare/circl v1.3.3 // indirect + github.com/fatih/color v1.13.0 // indirect + github.com/golang/protobuf v1.5.3 // indirect + github.com/google/go-cmp v0.5.9 // indirect + github.com/hashicorp/errwrap v1.0.0 // indirect + github.com/hashicorp/go-checkpoint v0.5.0 // indirect + github.com/hashicorp/go-cleanhttp v0.5.2 // indirect + github.com/hashicorp/go-cty v1.4.1-0.20200414143053-d3edf31b6320 // indirect + github.com/hashicorp/go-hclog v1.5.0 // indirect + github.com/hashicorp/go-multierror v1.1.1 // indirect + github.com/hashicorp/go-plugin v1.4.10 // indirect + github.com/hashicorp/go-uuid v1.0.3 // indirect + github.com/hashicorp/go-version v1.6.0 // indirect + github.com/hashicorp/hc-install v0.5.2 // indirect + github.com/hashicorp/hcl/v2 v2.17.0 // indirect + github.com/hashicorp/logutils v1.0.0 // indirect + github.com/hashicorp/terraform-exec v0.18.1 // indirect + github.com/hashicorp/terraform-json v0.17.0 // indirect + github.com/hashicorp/terraform-plugin-go v0.16.0 // indirect + github.com/hashicorp/terraform-plugin-log v0.9.0 // indirect + github.com/hashicorp/terraform-registry-address v0.2.1 // indirect + github.com/hashicorp/terraform-svchost v0.1.1 // indirect + github.com/hashicorp/yamux v0.0.0-20181012175058-2f1d1f20f75d // indirect + github.com/mattn/go-colorable v0.1.12 // indirect + github.com/mattn/go-isatty v0.0.14 // indirect + github.com/mitchellh/copystructure v1.2.0 // indirect + github.com/mitchellh/go-testing-interface v1.14.1 // indirect + github.com/mitchellh/go-wordwrap v1.0.0 // indirect + github.com/mitchellh/mapstructure v1.5.0 // indirect + github.com/mitchellh/reflectwalk v1.0.2 // indirect + github.com/oklog/run v1.0.0 // indirect + github.com/vmihailenco/msgpack v4.0.4+incompatible // indirect + 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.10.0 // indirect + golang.org/x/mod v0.10.0 // indirect + golang.org/x/net v0.11.0 // indirect + golang.org/x/oauth2 v0.7.0 // indirect + golang.org/x/sys v0.9.0 // indirect + golang.org/x/text v0.10.0 // indirect + google.golang.org/appengine v1.6.7 // indirect + google.golang.org/genproto v0.0.0-20230410155749-daa745c078e1 // indirect + google.golang.org/grpc v1.56.0 // indirect + google.golang.org/protobuf v1.30.0 // indirect ) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..9810d1b --- /dev/null +++ b/go.sum @@ -0,0 +1,175 @@ +github.com/Microsoft/go-winio v0.5.2 h1:a9IhgEQBCUEk6QCdml9CiJGhAws+YwffDHEMp1VMrpA= +github.com/ProtonMail/go-crypto v0.0.0-20230217124315-7d5c6f04bbb8 h1:wPbRQzjjwFc0ih8puEVAOFGELsn1zoIIYdxvML7mDxA= +github.com/ProtonMail/go-crypto v0.0.0-20230217124315-7d5c6f04bbb8/go.mod h1:I0gYDMZ6Z5GRU7l58bNFSkPTFN6Yl12dsUlAZ8xy98g= +github.com/TheJumpCloud/jcapi-go v3.0.0+incompatible h1:hqcTK6ZISdip65SR792lwYJTa/axESA0889D3UlZbLo= +github.com/TheJumpCloud/jcapi-go v3.0.0+incompatible/go.mod h1:6B1nuc1MUs6c62ODZDl7hVE5Pv7O2XGSkgg2olnq34I= +github.com/acomagu/bufpipe v1.0.4 h1:e3H4WUzM3npvo5uv95QuJM3cQspFNtFBzvJ2oNjKIDQ= +github.com/agext/levenshtein v1.2.2 h1:0S/Yg6LYmFJ5stwQeRp6EeOcCbj7xiqQSdNelsXvaqE= +github.com/agext/levenshtein v1.2.2/go.mod h1:JEDfjyjHDjOF/1e4FlBE/PkbqA9OfWu2ki2W0IB5558= +github.com/apparentlymart/go-textseg/v12 v12.0.0/go.mod h1:S/4uRK2UtaQttw1GenVJEynmyUenKwP++x/+DdGV/Ec= +github.com/apparentlymart/go-textseg/v13 v13.0.0 h1:Y+KvPE1NYz0xl601PVImeQfFyEy6iT90AvPUL1NNfNw= +github.com/apparentlymart/go-textseg/v13 v13.0.0/go.mod h1:ZK2fH7c4NqDTLtiYLvIkEghdlcqw7yxLeM89kiTRPUo= +github.com/bwesterb/go-ristretto v1.2.0/go.mod h1:fUIoIZaG73pV5biE2Blr2xEzDoMj7NFEuV9ekS419A0= +github.com/cloudflare/circl v1.1.0/go.mod h1:prBCrKB9DV4poKZY1l9zBXg2QJY7mvgRvtMxxK7fi4I= +github.com/cloudflare/circl v1.3.3 h1:fE/Qz0QdIGqeWfnwq0RE0R7MI51s0M2E4Ga9kq5AEMs= +github.com/cloudflare/circl v1.3.3/go.mod h1:5XYMA4rFBvNIrhs50XuiBJ15vF2pZn4nnUKZrLbUZFA= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/emirpasic/gods v1.18.1 h1:FXtiHYKDGKCW2KzwZKx0iC0PQmdlorYgdFG9jPXJ1Bc= +github.com/fatih/color v1.13.0 h1:8LOYc1KYPPmyKMuN8QV2DNRWNbLo6LZ0iLs8+mlH53w= +github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk= +github.com/go-git/gcfg v1.5.0 h1:Q5ViNfGF8zFgyJWPqYwA7qGFoMTEiBmdlkcfRmpIMa4= +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= +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.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= +github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= +github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= +github.com/hashicorp/errwrap v1.0.0 h1:hLrqtEDnRye3+sgx6z4qVLNuviH3MR5aQ0ykNJa/UYA= +github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= +github.com/hashicorp/go-checkpoint v0.5.0 h1:MFYpPZCnQqQTE18jFwSII6eUQrD/oxMFp3mlgcqk5mU= +github.com/hashicorp/go-checkpoint v0.5.0/go.mod h1:7nfLNL10NsxqO4iWuW6tWW0HjZuDrwkBuEQsVcpCOgg= +github.com/hashicorp/go-cleanhttp v0.5.0/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80= +github.com/hashicorp/go-cleanhttp v0.5.2 h1:035FKYIWjmULyFRBKPs8TBQoi0x6d9G4xc9neXJWAZQ= +github.com/hashicorp/go-cleanhttp v0.5.2/go.mod h1:kO/YDlP8L1346E6Sodw+PrpBSV4/SoxCXGY6BqNFT48= +github.com/hashicorp/go-cty v1.4.1-0.20200414143053-d3edf31b6320 h1:1/D3zfFHttUKaCaGKZ/dR2roBXv0vKbSCnssIldfQdI= +github.com/hashicorp/go-cty v1.4.1-0.20200414143053-d3edf31b6320/go.mod h1:EiZBMaudVLy8fmjf9Npq1dq9RalhveqZG5w/yz3mHWs= +github.com/hashicorp/go-hclog v1.5.0 h1:bI2ocEMgcVlz55Oj1xZNBsVi900c7II+fWDyV9o+13c= +github.com/hashicorp/go-hclog v1.5.0/go.mod h1:W4Qnvbt70Wk/zYJryRzDRU/4r0kIg0PVHBcfoyhpF5M= +github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+lD48awMYo= +github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9/fmwbPZ6JB6eMoM= +github.com/hashicorp/go-plugin v1.4.10 h1:xUbmA4jC6Dq163/fWcp8P3JuHilrHHMLNRxzGQJ9hNk= +github.com/hashicorp/go-plugin v1.4.10/go.mod h1:6/1TEzT0eQznvI/gV2CM29DLSkAK/e58mUWKVsPaph0= +github.com/hashicorp/go-uuid v1.0.0/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= +github.com/hashicorp/go-uuid v1.0.3 h1:2gKiV6YVmrJ1i2CKKa9obLvRieoRGviZFL26PcT/Co8= +github.com/hashicorp/go-uuid v1.0.3/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= +github.com/hashicorp/go-version v1.6.0 h1:feTTfFNnjP967rlCxM/I9g701jU+RN74YKx2mOkIeek= +github.com/hashicorp/go-version v1.6.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA= +github.com/hashicorp/hc-install v0.5.2 h1:SfwMFnEXVVirpwkDuSF5kymUOhrUxrTq3udEseZdOD0= +github.com/hashicorp/hc-install v0.5.2/go.mod h1:9QISwe6newMWIfEiXpzuu1k9HAGtQYgnSH8H9T8wmoI= +github.com/hashicorp/hcl/v2 v2.17.0 h1:z1XvSUyXd1HP10U4lrLg5e0JMVz6CPaJvAgxM0KNZVY= +github.com/hashicorp/hcl/v2 v2.17.0/go.mod h1:gJyW2PTShkJqQBKpAmPO3yxMxIuoXkOF2TpqXzrQyx4= +github.com/hashicorp/logutils v1.0.0 h1:dLEQVugN8vlakKOUE3ihGLTZJRB4j+M2cdTm/ORI65Y= +github.com/hashicorp/logutils v1.0.0/go.mod h1:QIAnNjmIWmVIIkWDTG1z5v++HQmx9WQRO+LraFDTW64= +github.com/hashicorp/terraform-exec v0.18.1 h1:LAbfDvNQU1l0NOQlTuudjczVhHj061fNX5H8XZxHlH4= +github.com/hashicorp/terraform-exec v0.18.1/go.mod h1:58wg4IeuAJ6LVsLUeD2DWZZoc/bYi6dzhLHzxM41980= +github.com/hashicorp/terraform-json v0.17.0 h1:EiA1Wp07nknYQAiv+jIt4dX4Cq5crgP+TsTE45MjMmM= +github.com/hashicorp/terraform-json v0.17.0/go.mod h1:Huy6zt6euxaY9knPAFKjUITn8QxUFIe9VuSzb4zn/0o= +github.com/hashicorp/terraform-plugin-go v0.16.0 h1:DSOQ0rz5FUiVO4NUzMs8ln9gsPgHMTsfns7Nk+6gPuE= +github.com/hashicorp/terraform-plugin-go v0.16.0/go.mod h1:4sn8bFuDbt+2+Yztt35IbOrvZc0zyEi87gJzsTgCES8= +github.com/hashicorp/terraform-plugin-log v0.9.0 h1:i7hOA+vdAItN1/7UrfBqBwvYPQ9TFvymaRGZED3FCV0= +github.com/hashicorp/terraform-plugin-log v0.9.0/go.mod h1:rKL8egZQ/eXSyDqzLUuwUYLVdlYeamldAHSxjUFADow= +github.com/hashicorp/terraform-plugin-sdk/v2 v2.27.0 h1:I8efBnjuDrgPjNF1MEypHy48VgcTIUY4X6rOFunrR3Y= +github.com/hashicorp/terraform-plugin-sdk/v2 v2.27.0/go.mod h1:cUEP4ly/nxlHy5HzD6YRrHydtlheGvGRJDhiWqqVik4= +github.com/hashicorp/terraform-registry-address v0.2.1 h1:QuTf6oJ1+WSflJw6WYOHhLgwUiQ0FrROpHPYFtwTYWM= +github.com/hashicorp/terraform-registry-address v0.2.1/go.mod h1:BSE9fIFzp0qWsJUUyGquo4ldV9k2n+psif6NYkBRS3Y= +github.com/hashicorp/terraform-svchost v0.1.1 h1:EZZimZ1GxdqFRinZ1tpJwVxxt49xc/S52uzrw4x0jKQ= +github.com/hashicorp/terraform-svchost v0.1.1/go.mod h1:mNsjQfZyf/Jhz35v6/0LWcv26+X7JPS+buii2c9/ctc= +github.com/hashicorp/yamux v0.0.0-20181012175058-2f1d1f20f75d h1:kJCB4vdITiW1eC1vq2e6IsrXKrZit1bv/TDYFGMp4BQ= +github.com/hashicorp/yamux v0.0.0-20181012175058-2f1d1f20f75d/go.mod h1:+NfK9FKeTrX5uv1uIXGdwYDTeHna2qgaIlx54MXqjAM= +github.com/imdario/mergo v0.3.13 h1:lFzP57bqS/wsqKssCGmtLAb8A0wKjLGrve2q3PPVcBk= +github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 h1:BQSFePA1RWJOlocH6Fxy8MmwDt+yVQYULKfN0RoTN8A= +github.com/jhump/protoreflect v1.6.0 h1:h5jfMVslIg6l29nsMs0D8Wj17RDVdNYti0vDN/PZZoE= +github.com/kevinburke/ssh_config v1.2.0 h1:x584FjTGwHzMwvHx18PXxbBVzfnxogHaAReU4gf13a4= +github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= +github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= +github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= +github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= +github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= +github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc= +github.com/mattn/go-colorable v0.1.9/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= +github.com/mattn/go-colorable v0.1.12 h1:jF+Du6AlPIjs2BiUiQlKOX0rt3SujHxPnksPKZbaA40= +github.com/mattn/go-colorable v0.1.12/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4= +github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= +github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y= +github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94= +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-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.0 h1:6GlHJ/LTGMrIJbwgdqdl2eEH8o+Exx/0m8ir9Gns0u4= +github.com/mitchellh/go-wordwrap v1.0.0/go.mod h1:ZXFpozHsX6DPmq2I0TCekCxypsnAUbP2oI0UX1GXzOo= +github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY= +github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= +github.com/mitchellh/reflectwalk v1.0.2 h1:G2LzWKi524PWgd3mLHV8Y5k7s6XUvT0Gef6zxSIeXaQ= +github.com/mitchellh/reflectwalk v1.0.2/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw= +github.com/oklog/run v1.0.0 h1:Ru7dDtJNOyC66gQ5dQmaCa0qIsAUFY3sFpK1Xk8igrw= +github.com/oklog/run v1.0.0/go.mod h1:dlhp/R75TPv97u0XWUtDeV/lRKWPKSdTuV0TZvrmrQA= +github.com/pjbgf/sha1cd v0.3.0 h1:4D5XXmUUBUl/xQ6IjCkEAbqXskkq/4O7LmGn0AqMDs4= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/sergi/go-diff v1.2.0 h1:XU+rvMAioB0UC3q1MFrIQy4Vo5/4VsRDQQXHsEya6xQ= +github.com/skeema/knownhosts v1.1.0 h1:Wvr9V0MxhjRbl3f9nMnKnFfiWTJmtECJ9Njkea3ysW0= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.7.2 h1:4jaiDzPyXQvSd7D0EjG45355tLlV3VOECpq10pLC+8s= +github.com/stretchr/testify v1.7.2/go.mod h1:R6va5+xMeoiuVRoj+gSkQ7d3FALtqAAGI1FQKckRals= +github.com/vmihailenco/msgpack v3.3.3+incompatible/go.mod h1:fy3FlTQTDXWkZ7Bh6AcGMlsjHatGryHQYUTf1ShIgkk= +github.com/vmihailenco/msgpack v4.0.4+incompatible h1:dSLoQfGFAo3F6OoNhwUmLwVgaUXK79GlxNBwueZn0xI= +github.com/vmihailenco/msgpack v4.0.4+incompatible/go.mod h1:fy3FlTQTDXWkZ7Bh6AcGMlsjHatGryHQYUTf1ShIgkk= +github.com/vmihailenco/msgpack/v5 v5.3.5 h1:5gO0H1iULLWGhs2H5tbAHIZTV8/cYafcFOr9znI5mJU= +github.com/vmihailenco/msgpack/v5 v5.3.5/go.mod h1:7xyJ9e+0+9SaZT0Wt1RGleJXzli6Q/V5KbhBonMG9jc= +github.com/vmihailenco/tagparser/v2 v2.0.0 h1:y09buUbR+b5aycVFQs/g70pqKVZNBmxwAhO7/IwNM9g= +github.com/vmihailenco/tagparser/v2 v2.0.0/go.mod h1:Wri+At7QHww0WTrCBeu4J6bNtoV6mEfg5OIWRZA9qds= +github.com/xanzy/ssh-agent v0.3.3 h1:+/15pJfg/RsTxqYcX6fHqOXZwwMP+2VyYWJeWM2qQFM= +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= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= +golang.org/x/crypto v0.10.0 h1:LKqV2xt9+kDzSTfOhx4FrkEBcMrAgHSYgzywV9zcGmM= +golang.org/x/crypto v0.10.0/go.mod h1:o4eNf7Ede1fv+hwOwZsTHl9EsPFO6q6ZvYR8vYfY45I= +golang.org/x/mod v0.10.0 h1:lFO9qtOdlre5W1jxS3r/4szv2/6iXxScdzjoBMXNhYk= +golang.org/x/mod v0.10.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= +golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= +golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= +golang.org/x/net v0.11.0 h1:Gi2tvZIJyBtO9SDr1q9h5hEQCp/4L2RQ+ar0qjx2oNU= +golang.org/x/net v0.11.0/go.mod h1:2L/ixqYpgIVXmeoSA/4Lu7BzTG4KIyPIryS4IsOd1oQ= +golang.org/x/oauth2 v0.7.0 h1:qe6s0zUXlPX80/dITx3440hWZ7GwMwgDDyrSGTPJG/g= +golang.org/x/oauth2 v0.7.0/go.mod h1:hPLQkd9LyjfXTiRohC/41GhcFqxisoUQ99sCUOHO9x4= +golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20211007075335-d3039528d8ac/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220503163025-988cb79eb6c6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.9.0 h1:KS/R3tvhPqvJvwcKfnBHJwwthS11LRhmM5D59eEXa0s= +golang.org/x/sys v0.9.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= +golang.org/x/term v0.9.0 h1:GRRCnKYhdQrD8kfRAdQ6Zcw1P0OcELxGLKJvtjVMZ28= +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.10.0 h1:UpjohKhiEgNc0CSauXmwYftY1+LlaC75SJwh0SgCX58= +golang.org/x/text v0.10.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +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/genproto v0.0.0-20230410155749-daa745c078e1 h1:KpwkzHKEF7B9Zxg18WzOa7djJ+Ha5DzthMyZYQfEn2A= +google.golang.org/genproto v0.0.0-20230410155749-daa745c078e1/go.mod h1:nKE/iIaLqn2bQwXBg8f1g2Ylh6r5MN5CmZvuzZCgsCU= +google.golang.org/grpc v1.56.0 h1:+y7Bs8rtMd07LeXmL3NxcTLn7mUkbKZqEpPhMNkwJEE= +google.golang.org/grpc v1.56.0/go.mod h1:I9bI3vqKfayGqPUAwGdOSu7kt6oIJLixfffKrpXqQ9s= +google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= +google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= +google.golang.org/protobuf v1.30.0 h1:kPPoIgf3TsEvrm0PFe15JQ+570QVxYzEvvHqChK+cng= +google.golang.org/protobuf v1.30.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY= +gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/warnings.v0 v0.1.2 h1:wFXVbFY8DY5/xOe1ECiWdKCzZlxgshcYVNkBHstARME= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/jumpcloud/config.go b/jumpcloud/config.go index ed2383e..0e677d7 100644 --- a/jumpcloud/config.go +++ b/jumpcloud/config.go @@ -14,7 +14,7 @@ type Config struct { // Client instantiates a jcapiv2.Configuration struct that is passed // to every Resource operation -func (c *Config) Client() (interface{}, error) { +func (c *Config) Client() interface{} { config := jcapiv2.NewConfiguration() config.AddDefaultHeader("x-api-key", c.APIKey) @@ -22,5 +22,5 @@ func (c *Config) Client() (interface{}, error) { config.AddDefaultHeader("x-org-id", c.OrgID) } // Instantiate the API client - return config, nil + return config } diff --git a/jumpcloud/data_source_application.go b/jumpcloud/data_source_application.go new file mode 100644 index 0000000..639fe92 --- /dev/null +++ b/jumpcloud/data_source_application.go @@ -0,0 +1,61 @@ +package jumpcloud + +import ( + "context" + + jcapiv1 "github.com/TheJumpCloud/jcapi-go/v1" + jcapiv2 "github.com/TheJumpCloud/jcapi-go/v2" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" +) + +func dataSourceApplication() *schema.Resource { + return &schema.Resource{ + ReadContext: dataSourceApplicationRead, + Schema: map[string]*schema.Schema{ + "name": { + Description: "The (display) name of the application.", + Type: schema.TypeString, + Optional: true, + }, + "display_label": { + Description: "The display label of the application.", + Type: schema.TypeString, + Optional: true, + }, + "id": { + Description: "The ID of the application.", + Type: schema.TypeString, + Computed: true, + }, + }, + } +} + +func dataSourceApplicationRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { + configv1 := convertV2toV1Config(m.(*jcapiv2.Configuration)) + client := jcapiv1.NewAPIClient(configv1) + applicationName, nameExists := d.GetOk("name") + displayLabel, displayLabelExists := d.GetOk("display_label") + + if !nameExists && !displayLabelExists { + return diag.Errorf("either name or display_label must be provided") + } + + applicationsResponse, _, err := client.ApplicationsApi.ApplicationsList(ctx, "_id, displayName, displayLabel", "", nil) + + if err != nil { + return diag.FromErr(err) + } + + applications := applicationsResponse.Results + + for _, application := range applications { + if (nameExists && application.DisplayName == applicationName) || (displayLabelExists && application.DisplayLabel == displayLabel) { + d.SetId(application.Id) + return nil + } + } + + return diag.Errorf("no application found with the provided name or display_label") +} diff --git a/jumpcloud/data_source_application_test.go b/jumpcloud/data_source_application_test.go new file mode 100644 index 0000000..40d9e68 --- /dev/null +++ b/jumpcloud/data_source_application_test.go @@ -0,0 +1,34 @@ +package jumpcloud + +import ( + "fmt" + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" +) + +func TestAccDataApplication(t *testing.T) { + const cName = "OpenID Connect" + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: nil, + Steps: []resource.TestStep{ + { + Config: testAccDataApplication(cName), + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("data.jumpcloud_application.test_application", "name", cName), + ), + }, + }, + }) +} + +func testAccDataApplication(name string) string { + return fmt.Sprintf(` + data "jumpcloud_application" "test_application" { + name = "%s" + }`, name, + ) +} diff --git a/jumpcloud/data_source_ldapserver.go b/jumpcloud/data_source_ldapserver.go index cb61e2b..0db4ea6 100644 --- a/jumpcloud/data_source_ldapserver.go +++ b/jumpcloud/data_source_ldapserver.go @@ -2,15 +2,15 @@ package jumpcloud import ( "context" - "fmt" jcapiv2 "github.com/TheJumpCloud/jcapi-go/v2" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) func dataResourceLdapServer() *schema.Resource { return &schema.Resource{ - Read: dataResourceLdapServerRead, + ReadContext: dataResourceLdapServerRead, Schema: map[string]*schema.Schema{ "name": { Type: schema.TypeString, @@ -32,8 +32,7 @@ func dataResourceLdapServer() *schema.Resource { } } -func dataResourceLdapServerRead(d *schema.ResourceData, m interface{}) error { - +func dataResourceLdapServerRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { config := m.(*jcapiv2.Configuration) client := jcapiv2.NewAPIClient(config) @@ -44,7 +43,7 @@ func dataResourceLdapServerRead(d *schema.ResourceData, m interface{}) error { } else if len(d.Get("name").(string)) > 0 { ldap_filter = append(ldap_filter, "name:eq:"+d.Get("name").(string)) } else { - return fmt.Errorf("ldap_id or name must be set for jumpcloud_ldap_server") + return diag.Errorf("ldap_id or name must be set for jumpcloud_ldap_server") } payload := map[string]interface{}{ @@ -55,27 +54,27 @@ func dataResourceLdapServerRead(d *schema.ResourceData, m interface{}) error { "body": payload, } - res, _, err := client.LDAPServersApi.LdapserversList(context.TODO(), "", headerAccept, req) + res, _, err := client.LDAPServersApi.LdapserversList(ctx, "", headerAccept, req) if err != nil { - return err + return diag.FromErr(err) } if err := d.Set("name", res[0].Name); err != nil { - return err + return diag.FromErr(err) } if err := d.Set("ldap_id", res[0].Id); err != nil { - return err + return diag.FromErr(err) } d.SetId(d.Get("ldap_id").(string)) if err := d.Set("user_lockout_action", res[0].UserLockoutAction); err != nil { - return err + return diag.FromErr(err) } if err := d.Set("user_password_expiration_action", res[0].UserPasswordExpirationAction); err != nil { - return err + return diag.FromErr(err) } return nil diff --git a/jumpcloud/data_source_ldapserver_test.go b/jumpcloud/data_source_ldapserver_test.go new file mode 100644 index 0000000..5198e4c --- /dev/null +++ b/jumpcloud/data_source_ldapserver_test.go @@ -0,0 +1,34 @@ +package jumpcloud + +import ( + "fmt" + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" +) + +func TestAccDataLdapServer(t *testing.T) { + const cName = "jumpcloud" + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: nil, + Steps: []resource.TestStep{ + { + Config: testAccDataLdapServer(cName), + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("data.jumpcloud_ldap_server.test_ldap_server", "name", cName), + ), + }, + }, + }) +} + +func testAccDataLdapServer(name string) string { + return fmt.Sprintf(` + data "jumpcloud_ldap_server" "test_ldap_server" { + name = "%s" + }`, name, + ) +} diff --git a/jumpcloud/provider.go b/jumpcloud/provider.go index 48ec8ad..c2048e5 100644 --- a/jumpcloud/provider.go +++ b/jumpcloud/provider.go @@ -1,6 +1,11 @@ package jumpcloud -import "github.com/hashicorp/terraform-plugin-sdk/helper/schema" +import ( + "context" + + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" +) // Provider instantiates a terraform provider for Jumpcloud // This includes all operations on all supported resources and @@ -27,12 +32,14 @@ func Provider() *schema.Provider { "jumpcloud_user_group": resourceUserGroup(), "jumpcloud_user_group_membership": resourceUserGroupMembership(), "jumpcloud_user_group_ldap_membership": resourceUserGroupLdapMembership(), + "jumpcloud_user_group_association": resourceUserGroupAssociation(), "jumpcloud_system_group": resourceGroupsSystem(), }, - ConfigureFunc: providerConfigure, DataSourcesMap: map[string]*schema.Resource{ "jumpcloud_ldap_server": dataResourceLdapServer(), + "jumpcloud_application": dataSourceApplication(), }, + ConfigureContextFunc: providerConfigure, } } @@ -45,11 +52,11 @@ func init() { } } -func providerConfigure(d *schema.ResourceData) (interface{}, error) { +func providerConfigure(_ context.Context, d *schema.ResourceData) (interface{}, diag.Diagnostics) { config := Config{ APIKey: d.Get("api_key").(string), OrgID: d.Get("org_id").(string), } - return config.Client() + return config.Client(), nil } diff --git a/jumpcloud/provider_test.go b/jumpcloud/provider_test.go index 7b895b7..7b66c63 100644 --- a/jumpcloud/provider_test.go +++ b/jumpcloud/provider_test.go @@ -5,18 +5,17 @@ package jumpcloud import ( "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/terraform" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) var ( - testAccProviders map[string]terraform.ResourceProvider + testAccProviders map[string]*schema.Provider testAccProvider *schema.Provider ) func init() { testAccProvider = Provider() - testAccProviders = map[string]terraform.ResourceProvider{ + testAccProviders = map[string]*schema.Provider{ "jumpcloud": testAccProvider, } } diff --git a/jumpcloud/resource_system_group.go b/jumpcloud/resource_system_group.go index ba8ccf2..93e4b1d 100644 --- a/jumpcloud/resource_system_group.go +++ b/jumpcloud/resource_system_group.go @@ -5,15 +5,16 @@ import ( "fmt" jcapiv2 "github.com/TheJumpCloud/jcapi-go/v2" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) func resourceGroupsSystem() *schema.Resource { return &schema.Resource{ - Create: resourceGroupsSystemCreate, - Read: resourceGroupsSystemRead, - Update: resourceGroupsSystemUpdate, - Delete: resourceGroupsSystemDelete, + CreateContext: resourceGroupsSystemCreate, + ReadContext: resourceGroupsSystemRead, + UpdateContext: resourceGroupsSystemUpdate, + DeleteContext: resourceGroupsSystemDelete, Schema: map[string]*schema.Schema{ "name": { Type: schema.TypeString, @@ -25,12 +26,12 @@ func resourceGroupsSystem() *schema.Resource { }, }, Importer: &schema.ResourceImporter{ - State: schema.ImportStatePassthrough, + StateContext: schema.ImportStatePassthroughContext, }, } } -func resourceGroupsSystemCreate(d *schema.ResourceData, m interface{}) error { +func resourceGroupsSystemCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { config := m.(*jcapiv2.Configuration) client := jcapiv2.NewAPIClient(config) @@ -39,22 +40,21 @@ func resourceGroupsSystemCreate(d *schema.ResourceData, m interface{}) error { req := map[string]interface{}{ "body": body, } - group, res, err := client.SystemGroupsApi.GroupsSystemPost(context.TODO(), - "", headerAccept, req) + group, res, err := client.SystemGroupsApi.GroupsSystemPost(ctx, "", headerAccept, req) if err != nil { // TODO: sort out error essentials - return fmt.Errorf("error creating system group %s: %s - response = %+v", + return diag.Errorf("error creating system group %s: %s - response = %+v", (req["body"].(jcapiv2.SystemGroupData)).Name, err, res) } d.SetId(group.Name) d.Set("name", group.Name) d.Set("jc_id", group.Id) - return resourceGroupsSystemRead(d, m) + return resourceGroupsSystemRead(ctx, d, m) } // Helper to look up a system group by name -func resourceGroupsSystemList_match(d *schema.ResourceData, m interface{}) (jcapiv2.SystemGroup, error) { +func resourceGroupsSystemList_match(ctx context.Context, d *schema.ResourceData, m interface{}) (jcapiv2.SystemGroup, error) { config := m.(*jcapiv2.Configuration) client := jcapiv2.NewAPIClient(config) @@ -66,11 +66,10 @@ func resourceGroupsSystemList_match(d *schema.ResourceData, m interface{}) (jcap "filter": filter, } - result, _, err := client.SystemGroupsApi.GroupsSystemList(context.TODO(), - "", headerAccept, optional) + result, _, err := client.SystemGroupsApi.GroupsSystemList(ctx, "", headerAccept, optional) if err == nil { if len(result) < 1 { - return jcapiv2.SystemGroup{}, fmt.Errorf("System Group \"%s\" not found.", d.Id()) + return jcapiv2.SystemGroup{}, fmt.Errorf("system group \"%s\" not found", d.Id()) } else { return result[0], nil } @@ -79,19 +78,16 @@ func resourceGroupsSystemList_match(d *schema.ResourceData, m interface{}) (jcap } } -func resourceGroupsSystemRead(d *schema.ResourceData, m interface{}) error { +func resourceGroupsSystemRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { config := m.(*jcapiv2.Configuration) client := jcapiv2.NewAPIClient(config) - var id string - - id = d.Get("jc_id").(string) + var id string = d.Get("jc_id").(string) if id == "" { - id_lookup, err := resourceGroupsSystemList_match(d, m) + id_lookup, err := resourceGroupsSystemList_match(ctx, d, m) if err != nil { - return fmt.Errorf("Unable to locate ID for group %s, %+v", - d.Get("name"), err) + return diag.Errorf("unable to locate ID for group %s, %+v", d.Get("name"), err) } id = id_lookup.Id d.SetId(id_lookup.Name) @@ -99,12 +95,10 @@ func resourceGroupsSystemRead(d *schema.ResourceData, m interface{}) error { d.Set("jc_id", id_lookup.Id) } - group, res, err := client.SystemGroupsApi.GroupsSystemGet(context.TODO(), - id, "", headerAccept, nil) + group, res, err := client.SystemGroupsApi.GroupsSystemGet(ctx, id, "", headerAccept, nil) if err != nil { // TODO: sort out error essentials - return fmt.Errorf("error reading system group ID %s: %s - response = %+v", - d.Id(), err, res) + return diag.Errorf("error reading system group ID %s: %s - response = %+v", d.Id(), err, res) } d.SetId(group.Name) @@ -113,12 +107,11 @@ func resourceGroupsSystemRead(d *schema.ResourceData, m interface{}) error { return nil } -func resourceGroupsSystemUpdate(d *schema.ResourceData, m interface{}) error { +func resourceGroupsSystemUpdate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { config := m.(*jcapiv2.Configuration) client := jcapiv2.NewAPIClient(config) - var id string - id = d.Get("jc_id").(string) + var id string = d.Get("jc_id").(string) body := jcapiv2.SystemGroupData{Name: d.Get("name").(string)} @@ -126,32 +119,28 @@ func resourceGroupsSystemUpdate(d *schema.ResourceData, m interface{}) error { "body": body, } - group, res, err := client.SystemGroupsApi.GroupsSystemPut(context.TODO(), - id, "", headerAccept, req) + group, res, err := client.SystemGroupsApi.GroupsSystemPut(ctx, id, "", headerAccept, req) if err != nil { // TODO: sort out error essentials - return fmt.Errorf("error updating system group %s: %s - response = %+v", - d.Get("name"), err, res) + return diag.Errorf("error updating system group %s: %s - response = %+v", d.Get("name"), err, res) } d.SetId(group.Name) d.Set("name", group.Name) d.Set("jc_id", group.Id) - return resourceGroupsSystemRead(d, m) + return resourceGroupsSystemRead(ctx, d, m) } -func resourceGroupsSystemDelete(d *schema.ResourceData, m interface{}) error { +func resourceGroupsSystemDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { config := m.(*jcapiv2.Configuration) client := jcapiv2.NewAPIClient(config) - var id string - id = d.Get("jc_id").(string) + var id string = d.Get("jc_id").(string) - res, err := client.SystemGroupsApi.GroupsSystemDelete(context.TODO(), - id, "", headerAccept, nil) + res, err := client.SystemGroupsApi.GroupsSystemDelete(ctx, id, "", headerAccept, nil) if err != nil { // TODO: sort out error essentials - return fmt.Errorf("error deleting system group:%s; response = %+v", err, res) + return diag.Errorf("error deleting system group:%s; response = %+v", err, res) } d.SetId("") return nil diff --git a/jumpcloud/resource_system_group_test.go b/jumpcloud/resource_system_group_test.go index 184df85..e10c09e 100644 --- a/jumpcloud/resource_system_group_test.go +++ b/jumpcloud/resource_system_group_test.go @@ -2,21 +2,14 @@ package jumpcloud import ( "fmt" - "net/http" - "net/http/httptest" "testing" - jcapiv2 "github.com/TheJumpCloud/jcapi-go/v2" - "github.com/hashicorp/terraform-plugin-sdk/helper/acctest" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/suite" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" ) func TestAccSystemGroup(t *testing.T) { rName := acctest.RandStringFromCharSet(10, acctest.CharSetAlpha) - posixName := acctest.RandStringFromCharSet(10, acctest.CharSetAlpha) - gid := acctest.RandIntRange(1, 1000) resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -24,65 +17,17 @@ func TestAccSystemGroup(t *testing.T) { CheckDestroy: nil, Steps: []resource.TestStep{ { - Config: testAccSystemGroup(rName, gid, posixName), - Check: resource.ComposeAggregateTestCheckFunc( - resource.TestCheckResourceAttr("jumpcloud_system_group.test_group", "name", rName), - resource.TestCheckResourceAttr("jumpcloud_system_group.test_group", - "attributes.posix_groups", fmt.Sprintf("%d:%s", gid, posixName)), - ), + Config: testAccSystemGroup(rName), + Check: resource.TestCheckResourceAttr("jumpcloud_system_group.test_system_group", "name", rName), }, }, }) } -func testAccSystemGroup(name string, gid int, posixName string) string { +func testAccSystemGroup(name string) string { return fmt.Sprintf(` - resource "jumpcloud_system_group" "test_group" { + resource "jumpcloud_system_group" "test_system_group" { name = "%s" - }`, name, gid, posixName, + }`, name, ) } - -func TestResourceSystemGroup(t *testing.T) { - suite.Run(t, new(ResourceSystemGroupSuite)) -} - -type ResourceSystemGroupSuite struct { - suite.Suite - A *assert.Assertions - TestHTTPServer *httptest.Server -} - -func (s *ResourceSystemGroupSuite) SetupSuite() { - s.A = assert.New(s.Suite.T()) -} - -func (s *ResourceSystemGroupSuite) TestTrueSystemGroupRead() { - cases := []struct { - ResponseStatus int - SystemGroupNil bool - OK bool - ErrorNil bool - Payload []byte - }{ - {http.StatusNotFound, true, false, true, []byte("irrelevant")}, - {http.StatusOK, false, true, true, []byte("{}")}, - } - - for _, c := range cases { - testServer := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) { - rw.WriteHeader(c.ResponseStatus) - rw.Write(c.Payload) - })) - - config := &jcapiv2.Configuration{ - BasePath: testServer.URL, - } - - ug, ok, err := systemGroupReadHelper(config, "id") - s.A.Equal(c.OK, ok) - s.A.Equal(c.SystemGroupNil, ug == nil) - s.A.Equal(c.ErrorNil, err == nil) - testServer.Close() - } -} diff --git a/jumpcloud/resource_system_group_user_group_membership.go b/jumpcloud/resource_system_group_user_group_membership.go deleted file mode 100644 index 081e450..0000000 --- a/jumpcloud/resource_system_group_user_group_membership.go +++ /dev/null @@ -1,126 +0,0 @@ -package jumpcloud - -import ( - "context" - "fmt" - "strings" - - jcapiv2 "github.com/TheJumpCloud/jcapi-go/v2" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" -) - -func resourceSystemGroupUserGroupMembership() *schema.Resource { - return &schema.Resource{ - Create: resourceSystemGroupUserGroupMembershipCreate, - Read: resourceSystemGroupUserGroupMembershipRead, - Delete: resourceSystemGroupUserGroupMembershipDelete, - Schema: map[string]*schema.Schema{ - "systems_group_id": { - Type: schema.TypeString, - Required: true, - ForceNew: true, - }, - "users_group_id": { - Type: schema.TypeString, - Required: true, - ForceNew: true, - }, - "active": { - Type: schema.TypeBool, - Computed: true, - ForceNew: true, - }, - }, - Importer: &schema.ResourceImporter{ - State: schema.ImportStatePassthrough, - }, - } -} - -func resourceSystemGroupUserGroupMembershipCreate(d *schema.ResourceData, m interface{}) error { - config := m.(*jcapiv2.Configuration) - client := jcapiv2.NewAPIClient(config) - - body := jcapiv2.SystemGroupGraphManagementReq{ - Id: d.Get("users_group_id").(string), - Op: "add", - Type_: "user_group", - } - - id := d.Get("systems_group_id").(string) - - optional := map[string]interface{}{ - "groupId": id, - "body": body, - } - res, err := client.GraphApi.GraphSystemGroupAssociationsPost(context.TODO(), - id, "", headerAccept, optional) - if err != nil { - // TODO: sort out error essentials - return fmt.Errorf("error creating system group association %+v: = %+v", - err, res) - } - - d.SetId(d.Get("systems_group_id").(string) + ":" + d.Get("users_group_id").(string)) - d.Set("active", true) - return nil -} - -func resourceSystemGroupUserGroupMembershipRead(d *schema.ResourceData, m interface{}) error { - config := m.(*jcapiv2.Configuration) - client := jcapiv2.NewAPIClient(config) - - split_id := strings.Split(d.Id(), ":") - - system_group_id := split_id[0] - user_group_id := split_id[1] - - var targets []string - - targets = append(targets, "user_group") - - associations, res, err := client.GraphApi.GraphSystemAssociationsList(context.TODO(), - system_group_id, "", headerAccept, targets, nil) - if err != nil { - // TODO: sort out error essentials - return fmt.Errorf("error reading system group associations %s: %s - response = %+v", - system_group_id, err, res) - } - - d.Set("active", false) - for _, association := range associations { - if association.To.Id == user_group_id { - d.Set("active", true) - } - } - - return nil -} - -func resourceSystemGroupUserGroupMembershipDelete(d *schema.ResourceData, m interface{}) error { - config := m.(*jcapiv2.Configuration) - client := jcapiv2.NewAPIClient(config) - - body := jcapiv2.SystemGroupGraphManagementReq{ - Id: d.Get("users_group_id").(string), - Op: "remove", - Type_: "user_group", - } - - var id string - id = d.Get("systems_group_id").(string) - - req := map[string]interface{}{ - "body": body, - } - res, err := client.GraphApi.GraphSystemGroupAssociationsPost(context.TODO(), - id, "", headerAccept, req) - if err != nil { - // TODO: sort out error essentials - return fmt.Errorf("error deleting system group %s: response = %+v", - err, res) - } - - d.SetId("") - return nil -} diff --git a/jumpcloud/resource_system_group_user_group_membership_test.go b/jumpcloud/resource_system_group_user_group_membership_test.go deleted file mode 100644 index 184df85..0000000 --- a/jumpcloud/resource_system_group_user_group_membership_test.go +++ /dev/null @@ -1,88 +0,0 @@ -package jumpcloud - -import ( - "fmt" - "net/http" - "net/http/httptest" - "testing" - - jcapiv2 "github.com/TheJumpCloud/jcapi-go/v2" - "github.com/hashicorp/terraform-plugin-sdk/helper/acctest" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/suite" -) - -func TestAccSystemGroup(t *testing.T) { - rName := acctest.RandStringFromCharSet(10, acctest.CharSetAlpha) - posixName := acctest.RandStringFromCharSet(10, acctest.CharSetAlpha) - gid := acctest.RandIntRange(1, 1000) - - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: nil, - Steps: []resource.TestStep{ - { - Config: testAccSystemGroup(rName, gid, posixName), - Check: resource.ComposeAggregateTestCheckFunc( - resource.TestCheckResourceAttr("jumpcloud_system_group.test_group", "name", rName), - resource.TestCheckResourceAttr("jumpcloud_system_group.test_group", - "attributes.posix_groups", fmt.Sprintf("%d:%s", gid, posixName)), - ), - }, - }, - }) -} - -func testAccSystemGroup(name string, gid int, posixName string) string { - return fmt.Sprintf(` - resource "jumpcloud_system_group" "test_group" { - name = "%s" - }`, name, gid, posixName, - ) -} - -func TestResourceSystemGroup(t *testing.T) { - suite.Run(t, new(ResourceSystemGroupSuite)) -} - -type ResourceSystemGroupSuite struct { - suite.Suite - A *assert.Assertions - TestHTTPServer *httptest.Server -} - -func (s *ResourceSystemGroupSuite) SetupSuite() { - s.A = assert.New(s.Suite.T()) -} - -func (s *ResourceSystemGroupSuite) TestTrueSystemGroupRead() { - cases := []struct { - ResponseStatus int - SystemGroupNil bool - OK bool - ErrorNil bool - Payload []byte - }{ - {http.StatusNotFound, true, false, true, []byte("irrelevant")}, - {http.StatusOK, false, true, true, []byte("{}")}, - } - - for _, c := range cases { - testServer := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) { - rw.WriteHeader(c.ResponseStatus) - rw.Write(c.Payload) - })) - - config := &jcapiv2.Configuration{ - BasePath: testServer.URL, - } - - ug, ok, err := systemGroupReadHelper(config, "id") - s.A.Equal(c.OK, ok) - s.A.Equal(c.SystemGroupNil, ug == nil) - s.A.Equal(c.ErrorNil, err == nil) - testServer.Close() - } -} diff --git a/jumpcloud/resource_user.go b/jumpcloud/resource_user.go index da0ad42..049f6df 100644 --- a/jumpcloud/resource_user.go +++ b/jumpcloud/resource_user.go @@ -2,19 +2,19 @@ package jumpcloud import ( "context" - "fmt" jcapiv1 "github.com/TheJumpCloud/jcapi-go/v1" jcapiv2 "github.com/TheJumpCloud/jcapi-go/v2" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) func resourceUser() *schema.Resource { return &schema.Resource{ - Create: resourceUserCreate, - Read: resourceUserRead, - Update: resourceUserUpdate, - Delete: resourceUserDelete, + CreateContext: resourceUserCreate, + ReadContext: resourceUserRead, + UpdateContext: resourceUserUpdate, + DeleteContext: resourceUserDelete, Schema: map[string]*schema.Schema{ "username": { Type: schema.TypeString, @@ -44,23 +44,12 @@ func resourceUser() *schema.Resource { // JumpCloud offers a lot more }, Importer: &schema.ResourceImporter{ - State: schema.ImportStatePassthrough, + StateContext: schema.ImportStatePassthroughContext, }, } } -// We receive a v2config from the TF base code but need a v1config to continue. So, we take the only -// preloaded element (the x-api-key) and populate the v1config with it. -func convertV2toV1Config(v2config *jcapiv2.Configuration) *jcapiv1.Configuration { - configv1 := jcapiv1.NewConfiguration() - configv1.AddDefaultHeader("x-api-key", v2config.DefaultHeader["x-api-key"]) - if v2config.DefaultHeader["x-org-id"] != "" { - configv1.AddDefaultHeader("x-org-id", v2config.DefaultHeader["x-org-id"]) - } - return configv1 -} - -func resourceUserCreate(d *schema.ResourceData, m interface{}) error { +func resourceUserCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { configv1 := convertV2toV1Config(m.(*jcapiv2.Configuration)) client := jcapiv1.NewAPIClient(configv1) @@ -75,21 +64,19 @@ func resourceUserCreate(d *schema.ResourceData, m interface{}) error { req := map[string]interface{}{ "body": payload, } - returnstruc, _, err := client.SystemusersApi.SystemusersPost(context.TODO(), - "", "", req) + returnstruc, _, err := client.SystemusersApi.SystemusersPost(ctx, "", "", req) if err != nil { - return err + return diag.FromErr(err) } d.SetId(returnstruc.Id) - return resourceUserRead(d, m) + return resourceUserRead(ctx, d, m) } -func resourceUserRead(d *schema.ResourceData, m interface{}) error { +func resourceUserRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { configv1 := convertV2toV1Config(m.(*jcapiv2.Configuration)) client := jcapiv1.NewAPIClient(configv1) - res, _, err := client.SystemusersApi.SystemusersGet(context.TODO(), - d.Id(), "", "", nil) + res, _, err := client.SystemusersApi.SystemusersGet(ctx, d.Id(), "", "", nil) // If the object does not exist in our infrastructure, we unset the ID // Unfortunately, the http request returns 200 even if the resource does not exist @@ -98,30 +85,30 @@ func resourceUserRead(d *schema.ResourceData, m interface{}) error { d.SetId("") return nil } - return err + return diag.FromErr(err) } d.SetId(res.Id) if err := d.Set("username", res.Username); err != nil { - return err + return diag.FromErr(err) } if err := d.Set("email", res.Email); err != nil { - return err + return diag.FromErr(err) } if err := d.Set("firstname", res.Firstname); err != nil { - return err + return diag.FromErr(err) } if err := d.Set("lastname", res.Lastname); err != nil { - return err + return diag.FromErr(err) } if err := d.Set("enable_mfa", res.EnableUserPortalMultifactor); err != nil { - return err + return diag.FromErr(err) } return nil } -func resourceUserUpdate(d *schema.ResourceData, m interface{}) error { +func resourceUserUpdate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { configv1 := convertV2toV1Config(m.(*jcapiv2.Configuration)) client := jcapiv1.NewAPIClient(configv1) @@ -139,23 +126,21 @@ func resourceUserUpdate(d *schema.ResourceData, m interface{}) error { req := map[string]interface{}{ "body": payload, } - _, _, err := client.SystemusersApi.SystemusersPut(context.TODO(), - d.Id(), "", "", req) + _, _, err := client.SystemusersApi.SystemusersPut(ctx, d.Id(), "", "", req) if err != nil { - return err + return diag.FromErr(err) } - return resourceUserRead(d, m) + return resourceUserRead(ctx, d, m) } -func resourceUserDelete(d *schema.ResourceData, m interface{}) error { +func resourceUserDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { configv1 := convertV2toV1Config(m.(*jcapiv2.Configuration)) client := jcapiv1.NewAPIClient(configv1) - res, _, err := client.SystemusersApi.SystemusersDelete(context.TODO(), - d.Id(), "", headerAccept, nil) + res, _, err := client.SystemusersApi.SystemusersDelete(ctx, d.Id(), "", headerAccept, nil) if err != nil { // TODO: sort out error essentials - return fmt.Errorf("error deleting user group:%s; response = %+v", err, res) + return diag.Errorf("error deleting user:%s; response = %+v", err, res) } d.SetId("") return nil diff --git a/jumpcloud/resource_user_group.go b/jumpcloud/resource_user_group.go index 0a9804b..27ef7a7 100644 --- a/jumpcloud/resource_user_group.go +++ b/jumpcloud/resource_user_group.go @@ -2,173 +2,94 @@ package jumpcloud import ( "context" - "encoding/json" - "errors" - "fmt" - "net/http" jcapiv2 "github.com/TheJumpCloud/jcapi-go/v2" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) func resourceUserGroup() *schema.Resource { return &schema.Resource{ - Create: resourceUserGroupCreate, - Read: resourceUserGroupRead, - Update: resourceUserGroupUpdate, - Delete: resourceUserGroupDelete, + CreateContext: resourceUserGroupCreate, + ReadContext: resourceUserGroupRead, + UpdateContext: resourceUserGroupUpdate, + DeleteContext: resourceUserGroupDelete, Schema: map[string]*schema.Schema{ "name": { Type: schema.TypeString, Required: true, }, - "attributes": { - Type: schema.TypeMap, - Optional: true, - Computed: true, - ForceNew: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "posix_groups": { - Type: schema.TypeString, - // PosixGroups cannot be edited after group creation. - ForceNew: true, - Optional: true, - }, - // enable_samba has a more complicated lifecycle, - // Commenting out for now as it is ignored in CRU by the JCAPI - // From Jumpcloud UI: - // Samba Authentication must be configured in the - // JumpCloud LDAP Directory and LDAP sync must be enabled - // on this group before Samba Authentication can be enabled. - // "enable_samba": { - // Type: schema.TypeBool, - // Optional: true, - // }, - }, - }, - }, }, Importer: &schema.ResourceImporter{ - State: schema.ImportStatePassthrough, + StateContext: schema.ImportStatePassthroughContext, }, } } -func resourceUserGroupCreate(d *schema.ResourceData, m interface{}) error { +func resourceUserGroupCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { config := m.(*jcapiv2.Configuration) client := jcapiv2.NewAPIClient(config) body := jcapiv2.UserGroupPost{Name: d.Get("name").(string)} - // For Attributes.PosixGroups, only the first member of the slice - // is considered by the JCAPI - if attr, ok := expandAttributes(d.Get("attributes")); ok { - body.Attributes = attr - } - req := map[string]interface{}{ "body": body, } - group, res, err := client.UserGroupsApi.GroupsUserPost(context.TODO(), - "", headerAccept, req) + group, res, err := client.UserGroupsApi.GroupsUserPost(ctx, "", headerAccept, req) if err != nil { // TODO: sort out error essentials - return fmt.Errorf("error creating user group %s: %s - response = %+v", + return diag.Errorf("error creating user group %s: %s - response = %+v", (req["body"].(jcapiv2.UserGroupPost)).Name, err, res) } d.SetId(group.Id) - return resourceUserGroupRead(d, m) + return resourceUserGroupRead(ctx, d, m) } -// resourceUserGroupRead uses a helper function that consumes the -// JC's HTTP API directly; the groups' attributes need to be kept in state -// as they are required for resourceUserGroupUpdate and the current -// implementation of the JC SDK doesn't support their retrieval -func resourceUserGroupRead(d *schema.ResourceData, m interface{}) error { +func resourceUserGroupRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { config := m.(*jcapiv2.Configuration) + client := jcapiv2.NewAPIClient(config) - group, ok, err := userGroupReadHelper(config, d.Id()) - if err != nil { - return err - } - - if !ok { - // not found - d.SetId("") - return nil - } - - d.SetId(group.ID) - if err := d.Set("name", group.Name); err != nil { - return err - } - if err := d.Set("attributes", flattenAttributes(&group.Attributes)); err != nil { - return err - } - - return nil -} - -func userGroupReadHelper(config *jcapiv2.Configuration, id string) (ug *UserGroup, - ok bool, err error) { + res, _, err := client.UserGroupsApi.GroupsUserGet(context.TODO(), d.Id(), "", headerAccept, nil) - req, err := http.NewRequest(http.MethodGet, - config.BasePath+"/usergroups/"+id, nil) if err != nil { - return + if err.Error() == "EOF" { + d.SetId("") + return nil + } + return diag.FromErr(err) } - req.Header.Add("x-api-key", config.DefaultHeader["x-api-key"]) - if config.DefaultHeader["x-org-id"] != "" { - req.Header.Add("x-org-id", config.DefaultHeader["x-org-id"]) - } - req.Header.Add("Content-Type", "application/json") - req.Header.Add("Accept", "application/json") + d.SetId(res.Id) - res, err := http.DefaultClient.Do(req) - if err != nil { - return + if err := d.Set("name", res.Name); err != nil { + return diag.FromErr(err) } - defer res.Body.Close() - if res.StatusCode == http.StatusNotFound { - return - } - - ok = true - err = json.NewDecoder(res.Body).Decode(&ug) - return + return nil } -func resourceUserGroupUpdate(d *schema.ResourceData, m interface{}) error { +func resourceUserGroupUpdate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { config := m.(*jcapiv2.Configuration) client := jcapiv2.NewAPIClient(config) body := jcapiv2.UserGroupPost{Name: d.Get("name").(string)} - if attr, ok := expandAttributes(d.Get("attributes")); ok { - body.Attributes = attr - } else { - return errors.New("unable to update, attributes not expandable") - } req := map[string]interface{}{ "body": body, } - // behaves like PUT, will fail if - // attributes.posixGroups isn't sent, see GODOC + _, res, err := client.UserGroupsApi.GroupsUserPatch(context.TODO(), d.Id(), "", headerAccept, req) if err != nil { // TODO: sort out error essentials - return fmt.Errorf("error deleting user group:%s; response = %+v", err, res) + return diag.Errorf("error updating user group:%s; response = %+v", err, res) } - return resourceUserGroupRead(d, m) + return resourceUserGroupRead(ctx, d, m) } -func resourceUserGroupDelete(d *schema.ResourceData, m interface{}) error { +func resourceUserGroupDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { config := m.(*jcapiv2.Configuration) client := jcapiv2.NewAPIClient(config) @@ -176,7 +97,7 @@ func resourceUserGroupDelete(d *schema.ResourceData, m interface{}) error { d.Id(), "", headerAccept, nil) if err != nil { // TODO: sort out error essentials - return fmt.Errorf("error deleting user group:%s; response = %+v", err, res) + return diag.Errorf("error deleting user group:%s; response = %+v", err, res) } d.SetId("") return nil diff --git a/jumpcloud/resource_user_group_association.go b/jumpcloud/resource_user_group_association.go new file mode 100644 index 0000000..202b5f3 --- /dev/null +++ b/jumpcloud/resource_user_group_association.go @@ -0,0 +1,110 @@ +package jumpcloud + +import ( + "context" + "strings" + + jcapiv2 "github.com/TheJumpCloud/jcapi-go/v2" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" +) + +func resourceUserGroupAssociation() *schema.Resource { + return &schema.Resource{ + CreateContext: resourceUserGroupAssociationCreate, + ReadContext: resourceUserGroupAssociationRead, + UpdateContext: nil, + DeleteContext: resourceUserGroupAssociationDelete, + Schema: map[string]*schema.Schema{ + "groupid": { + Description: "The ID of the `resource_user_group` resource.", + Type: schema.TypeString, + Required: true, + ForceNew: true, + }, + "appid": { + Description: "The ID of the application to associate to the group.", + Type: schema.TypeString, + Required: true, + ForceNew: true, + }, + }, + Importer: &schema.ResourceImporter{ + StateContext: userGroupAssociationImporter, + }, + } +} + +func userGroupAssociationImporter(_ context.Context, d *schema.ResourceData, m interface{}) ([]*schema.ResourceData, error) { + s := strings.Split(d.Id(), "/") + d.Set("groupid", s[0]) + d.Set("appid", s[1]) + return []*schema.ResourceData{d}, nil +} + +func modifyUserGroupAssociation(ctx context.Context, client *jcapiv2.APIClient, d *schema.ResourceData, action string) error { + payload := jcapiv2.UserGroupGraphManagementReq{ + Op: action, + Type_: "application", + Id: d.Get("appid").(string), + } + + req := map[string]interface{}{ + "body": payload, + } + + _, err := client.UserGroupAssociationsApi.GraphUserGroupAssociationsPost(ctx, d.Get("groupid").(string), "", "", req) + + return err +} + +func resourceUserGroupAssociationCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + config := meta.(*jcapiv2.Configuration) + client := jcapiv2.NewAPIClient(config) + + err := modifyUserGroupAssociation(ctx, client, d, "add") + if err != nil { + return diag.FromErr(err) + } + return resourceUserGroupAssociationRead(ctx, d, meta) +} + +func resourceUserGroupAssociationRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + config := meta.(*jcapiv2.Configuration) + client := jcapiv2.NewAPIClient(config) + + optionals := map[string]interface{}{ + "groupId": d.Get("groupid").(string), + "limit": int32(100), + } + + graphconnect, _, err := client.UserGroupAssociationsApi.GraphUserGroupAssociationsList( + ctx, d.Get("groupid").(string), "", "", []string{"application"}, optionals) + if err != nil { + return diag.FromErr(err) + } + + for _, v := range graphconnect { + if v.To.Id == d.Get("appid") { + resourceId := d.Get("groupid").(string) + "/" + d.Get("appid").(string) + d.SetId(resourceId) + return nil + } + } + + d.SetId("") + return nil +} + +func resourceUserGroupAssociationDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + config := meta.(*jcapiv2.Configuration) + client := jcapiv2.NewAPIClient(config) + + err := modifyUserGroupAssociation(ctx, client, d, "remove") + + if err != nil { + return diag.FromErr(err) + } + + return nil +} diff --git a/jumpcloud/resource_user_group_association_test.go b/jumpcloud/resource_user_group_association_test.go new file mode 100644 index 0000000..4c3732a --- /dev/null +++ b/jumpcloud/resource_user_group_association_test.go @@ -0,0 +1,43 @@ +package jumpcloud + +import ( + "fmt" + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" +) + +func TestAccUserGroupAssociation(t *testing.T) { + rName := acctest.RandStringFromCharSet(10, acctest.CharSetAlpha) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: nil, + Steps: []resource.TestStep{ + { + Config: testAccUserGroupAssociation(rName), + Check: resource.TestCheckResourceAttrSet("jumpcloud_user_group_association.test_user_group_association_"+rName, + "appid"), + }, + }, + }) +} + +func testAccUserGroupAssociation(name string) string { + return fmt.Sprintf(` + data "jumpcloud_application" "test_application_%s" { + name = "OpenID Connect" + } + + resource "jumpcloud_user_group" "test_user_group_%s" { + name = "testgroup_%s" + } + + resource "jumpcloud_user_group_association" "test_user_group_association_%s" { + groupid = jumpcloud_user_group.test_user_group_%s.id + appid = data.jumpcloud_application.test_application_%s.id + } + `, name, name, name, name, name, name) +} diff --git a/jumpcloud/resource_user_group_ldap_membership.go b/jumpcloud/resource_user_group_ldap_membership.go index 414ebad..287f8ab 100644 --- a/jumpcloud/resource_user_group_ldap_membership.go +++ b/jumpcloud/resource_user_group_ldap_membership.go @@ -5,14 +5,15 @@ import ( "strings" jcapiv2 "github.com/TheJumpCloud/jcapi-go/v2" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) func resourceUserGroupLdapMembership() *schema.Resource { return &schema.Resource{ - Create: resourceUserGroupLdapMembershipCreate, - Read: resourceUserGroupLdapMembershipRead, - Delete: resourceUserGroupLdapMembershipDelete, + CreateContext: resourceUserGroupLdapMembershipCreate, + ReadContext: resourceUserGroupLdapMembershipRead, + DeleteContext: resourceUserGroupLdapMembershipDelete, Schema: map[string]*schema.Schema{ "ldap_id": { Type: schema.TypeString, @@ -26,13 +27,12 @@ func resourceUserGroupLdapMembership() *schema.Resource { }, }, Importer: &schema.ResourceImporter{ - State: schema.ImportStatePassthrough, + StateContext: schema.ImportStatePassthroughContext, }, } } -func resourceUserGroupLdapMembershipCreate(d *schema.ResourceData, m interface{}) error { - +func resourceUserGroupLdapMembershipCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { config := m.(*jcapiv2.Configuration) client := jcapiv2.NewAPIClient(config) @@ -49,19 +49,18 @@ func resourceUserGroupLdapMembershipCreate(d *schema.ResourceData, m interface{} "body": payload, } - _, err := client.UserGroupsApi.GraphUserGroupAssociationsPost(context.TODO(), - ugId, "", headerAccept, req) + _, err := client.UserGroupsApi.GraphUserGroupAssociationsPost(ctx, ugId, "", headerAccept, req) if err != nil { - return err + return diag.FromErr(err) } d.SetId(ugId + ":" + ldapId) - return resourceUserGroupLdapMembershipRead(d, m) + return resourceUserGroupLdapMembershipRead(ctx, d, m) } -func resourceUserGroupLdapMembershipRead(d *schema.ResourceData, m interface{}) error { +func resourceUserGroupLdapMembershipRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { config := m.(*jcapiv2.Configuration) client := jcapiv2.NewAPIClient(config) @@ -74,23 +73,22 @@ func resourceUserGroupLdapMembershipRead(d *schema.ResourceData, m interface{}) "targets": ldapId, } - _, _, err := client.UserGroupsApi.GraphUserGroupTraverseLdapServer(context.TODO(), - ugId, "", "", req) + _, _, err := client.UserGroupsApi.GraphUserGroupTraverseLdapServer(ctx, ugId, "", "", req) if err != nil { - return err + return diag.FromErr(err) } if err := d.Set("usergroup_id", ugId); err != nil { - return err + return diag.FromErr(err) } if err := d.Set("ldap_id", ldapId[0]); err != nil { - return err + return diag.FromErr(err) } return nil } -func resourceUserGroupLdapMembershipDelete(d *schema.ResourceData, m interface{}) error { +func resourceUserGroupLdapMembershipDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { config := m.(*jcapiv2.Configuration) client := jcapiv2.NewAPIClient(config) @@ -109,11 +107,10 @@ func resourceUserGroupLdapMembershipDelete(d *schema.ResourceData, m interface{} "body": payload, } - _, err := client.UserGroupsApi.GraphUserGroupAssociationsPost(context.TODO(), - ugId, "", headerAccept, req) + _, err := client.UserGroupsApi.GraphUserGroupAssociationsPost(ctx, ugId, "", headerAccept, req) if err != nil { - return err + return diag.FromErr(err) } d.SetId("") diff --git a/jumpcloud/resource_user_group_ldap_membership_test.go b/jumpcloud/resource_user_group_ldap_membership_test.go new file mode 100644 index 0000000..286bd49 --- /dev/null +++ b/jumpcloud/resource_user_group_ldap_membership_test.go @@ -0,0 +1,43 @@ +package jumpcloud + +import ( + "fmt" + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" +) + +func TestAccUserGroupLdapMembership(t *testing.T) { + rName := acctest.RandStringFromCharSet(10, acctest.CharSetAlpha) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: nil, + Steps: []resource.TestStep{ + { + Config: testAccUserGroupLdapMembership(rName), + Check: resource.TestCheckResourceAttrSet("jumpcloud_user_group_ldap_membership.test_user_group_ldap_membership_"+rName, + "ldap_id"), + }, + }, + }) +} + +func testAccUserGroupLdapMembership(name string) string { + return fmt.Sprintf(` + resource "jumpcloud_user_group" "test_user_group_%s" { + name = "testgroup_%s" + } + + data "jumpcloud_ldap_server" "test_ldap_server_%s" { + name="jumpcloud" + } + + resource "jumpcloud_user_group_ldap_membership" "test_user_group_ldap_membership_%s" { + usergroup_id = jumpcloud_user_group.test_user_group_%s.id + ldap_id = data.jumpcloud_ldap_server.test_ldap_server_%s.ldap_id + } + `, name, name, name, name, name, name) +} diff --git a/jumpcloud/resource_user_group_membership.go b/jumpcloud/resource_user_group_membership.go index 5940944..4143779 100644 --- a/jumpcloud/resource_user_group_membership.go +++ b/jumpcloud/resource_user_group_membership.go @@ -5,17 +5,18 @@ import ( "strings" jcapiv2 "github.com/TheJumpCloud/jcapi-go/v2" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) func resourceUserGroupMembership() *schema.Resource { return &schema.Resource{ - Create: resourceUserGroupMembershipCreate, - Read: resourceUserGroupMembershipRead, + CreateContext: resourceUserGroupMembershipCreate, + ReadContext: resourceUserGroupMembershipRead, // We must not have an update routine as the association cannot be updated. // Any change in one of the elements forces a recreation of the resource - Update: nil, - Delete: resourceUserGroupMembershipDelete, + UpdateContext: nil, + DeleteContext: resourceUserGroupMembershipDelete, Schema: map[string]*schema.Schema{ "userid": { Type: schema.TypeString, @@ -29,7 +30,7 @@ func resourceUserGroupMembership() *schema.Resource { }, }, Importer: &schema.ResourceImporter{ - State: userGroupMembershipImporter, + StateContext: userGroupMembershipImporter, }, } } @@ -38,16 +39,14 @@ func resourceUserGroupMembership() *schema.Resource { // populated.- In our case, we need the group ID and user ID to do the read - But since our // artificial resource ID is simply the concatenation of user ID group ID seperated by a '/', // we can derive both values during our import process -func userGroupMembershipImporter(d *schema.ResourceData, m interface{}) ([]*schema.ResourceData, error) { +func userGroupMembershipImporter(_ context.Context, d *schema.ResourceData, m interface{}) ([]*schema.ResourceData, error) { s := strings.Split(d.Id(), "/") d.Set("groupid", s[0]) d.Set("userid", s[1]) return []*schema.ResourceData{d}, nil } -func modifyUserGroupMembership(client *jcapiv2.APIClient, - d *schema.ResourceData, action string) error { - +func modifyUserGroupMembership(ctx context.Context, client *jcapiv2.APIClient, d *schema.ResourceData, action string) error { payload := jcapiv2.UserGroupMembersReq{ Op: action, Type_: "user", @@ -58,24 +57,23 @@ func modifyUserGroupMembership(client *jcapiv2.APIClient, "body": payload, } - _, err := client.UserGroupMembersMembershipApi.GraphUserGroupMembersPost( - context.TODO(), d.Get("groupid").(string), "", "", req) + _, err := client.UserGroupMembersMembershipApi.GraphUserGroupMembersPost(ctx, d.Get("groupid").(string), "", "", req) return err } -func resourceUserGroupMembershipCreate(d *schema.ResourceData, m interface{}) error { +func resourceUserGroupMembershipCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { config := m.(*jcapiv2.Configuration) client := jcapiv2.NewAPIClient(config) - err := modifyUserGroupMembership(client, d, "add") + err := modifyUserGroupMembership(ctx, client, d, "add") if err != nil { - return err + return diag.FromErr(err) } - return resourceUserGroupMembershipRead(d, m) + return resourceUserGroupMembershipRead(ctx, d, m) } -func resourceUserGroupMembershipRead(d *schema.ResourceData, m interface{}) error { +func resourceUserGroupMembershipRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { config := m.(*jcapiv2.Configuration) client := jcapiv2.NewAPIClient(config) @@ -84,10 +82,9 @@ func resourceUserGroupMembershipRead(d *schema.ResourceData, m interface{}) erro "limit": int32(100), } - graphconnect, _, err := client.UserGroupMembersMembershipApi.GraphUserGroupMembersList( - context.TODO(), d.Get("groupid").(string), "", "", optionals) + graphconnect, _, err := client.UserGroupMembersMembershipApi.GraphUserGroupMembersList(ctx, d.Get("groupid").(string), "", "", optionals) if err != nil { - return err + return diag.FromErr(err) } // The Userids are hidden in a super-complex construct, see @@ -105,8 +102,15 @@ func resourceUserGroupMembershipRead(d *schema.ResourceData, m interface{}) erro return nil } -func resourceUserGroupMembershipDelete(d *schema.ResourceData, m interface{}) error { +func resourceUserGroupMembershipDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { config := m.(*jcapiv2.Configuration) client := jcapiv2.NewAPIClient(config) - return modifyUserGroupMembership(client, d, "remove") + + err := modifyUserGroupMembership(ctx, client, d, "remove") + + if err != nil { + return diag.FromErr(err) + } + + return nil } diff --git a/jumpcloud/resource_user_group_membership_test.go b/jumpcloud/resource_user_group_membership_test.go index 275e872..6b5c28a 100644 --- a/jumpcloud/resource_user_group_membership_test.go +++ b/jumpcloud/resource_user_group_membership_test.go @@ -4,8 +4,8 @@ import ( "fmt" "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/acctest" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" ) func TestAccUserGroupMembership(t *testing.T) { diff --git a/jumpcloud/resource_user_group_test.go b/jumpcloud/resource_user_group_test.go index b820087..2c22255 100644 --- a/jumpcloud/resource_user_group_test.go +++ b/jumpcloud/resource_user_group_test.go @@ -2,15 +2,10 @@ package jumpcloud import ( "fmt" - "net/http" - "net/http/httptest" "testing" - jcapiv2 "github.com/TheJumpCloud/jcapi-go/v2" - "github.com/hashicorp/terraform-plugin-sdk/helper/acctest" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/suite" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" ) func TestAccUserGroup(t *testing.T) { @@ -27,8 +22,6 @@ func TestAccUserGroup(t *testing.T) { Config: testAccUserGroup(rName, gid, posixName), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("jumpcloud_user_group.test_group", "name", rName), - resource.TestCheckResourceAttr("jumpcloud_user_group.test_group", - "attributes.posix_groups", fmt.Sprintf("%d:%s", gid, posixName)), ), }, }, @@ -39,53 +32,6 @@ func testAccUserGroup(name string, gid int, posixName string) string { return fmt.Sprintf(` resource "jumpcloud_user_group" "test_group" { name = "%s" - attributes = { - posix_groups = "%d:%s" - } - }`, name, gid, posixName, + }`, name, ) } - -func TestResourceUserGroup(t *testing.T) { - suite.Run(t, new(ResourceUserGroupSuite)) -} - -type ResourceUserGroupSuite struct { - suite.Suite - A *assert.Assertions - TestHTTPServer *httptest.Server -} - -func (s *ResourceUserGroupSuite) SetupSuite() { - s.A = assert.New(s.Suite.T()) -} - -func (s *ResourceUserGroupSuite) TestTrueUserGroupRead() { - cases := []struct { - ResponseStatus int - UserGroupNil bool - OK bool - ErrorNil bool - Payload []byte - }{ - {http.StatusNotFound, true, false, true, []byte("irrelevant")}, - {http.StatusOK, false, true, true, []byte("{}")}, - } - - for _, c := range cases { - testServer := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) { - rw.WriteHeader(c.ResponseStatus) - rw.Write(c.Payload) - })) - - config := &jcapiv2.Configuration{ - BasePath: testServer.URL, - } - - ug, ok, err := userGroupReadHelper(config, "id") - s.A.Equal(c.OK, ok) - s.A.Equal(c.UserGroupNil, ug == nil) - s.A.Equal(c.ErrorNil, err == nil) - testServer.Close() - } -} diff --git a/jumpcloud/resource_user_test.go b/jumpcloud/resource_user_test.go index 9031d84..e7f08d2 100644 --- a/jumpcloud/resource_user_test.go +++ b/jumpcloud/resource_user_test.go @@ -5,8 +5,8 @@ import ( "os" "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/acctest" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" ) func TestAccUser(t *testing.T) { diff --git a/jumpcloud/structures_user_group.go b/jumpcloud/structures_user_group.go deleted file mode 100644 index 40f8455..0000000 --- a/jumpcloud/structures_user_group.go +++ /dev/null @@ -1,74 +0,0 @@ -package jumpcloud - -// see https://www.terraform.io/docs/extend/writing-custom-providers.html#implementing-a-more-complex-read - -import ( - "fmt" - "strconv" - "strings" - - jcapiv2 "github.com/TheJumpCloud/jcapi-go/v2" -) - -func flattenAttributes(attr *jcapiv2.UserGroupPostAttributes) map[string]interface{} { - return map[string]interface{}{ - "posix_groups": flattenPosixGroups(attr.PosixGroups), - // "enable_samba": fmt.Sprintf("%t", attr.SambaEnabled), - } -} - -func flattenPosixGroups(pg []jcapiv2.UserGroupPostAttributesPosixGroups) string { - out := []string{} - for _, v := range pg { - out = append(out, fmt.Sprintf("%d:%s", v.Id, v.Name)) - } - return strings.Join(out, ",") -} - -func expandAttributes(attr interface{}) (out *jcapiv2.UserGroupPostAttributes, ok bool) { - if attr == nil { - return - } - mapAttr, ok := attr.(map[string]interface{}) - if !ok { - return - } - - // var enableSamba bool - // sambaStr, ok := mapAttr["enable_samba"].(string) - // if ok { - // enableSamba, _ = strconv.ParseBool(sambaStr) - // } - - // TODO: empty string? nil? - posixStr, ok := mapAttr["posix_groups"].(string) - if !ok { - return - } - - groups := strings.Split(posixStr, ",") - posixGroups := []jcapiv2.UserGroupPostAttributesPosixGroups{} - for _, v := range groups { - g := strings.Split(v, ":") - if len(g) != 2 { - return - } - id, err := strconv.ParseInt(g[0], 10, 32) - if err != nil { - continue - } - posixGroups = append(posixGroups, - jcapiv2.UserGroupPostAttributesPosixGroups{ - Id: int32(id), Name: g[1], - }) - } - - if len(posixGroups) == 0 { - return - } - - return &jcapiv2.UserGroupPostAttributes{ - PosixGroups: posixGroups, - // SambaEnabled: enableSamba, - }, true -} diff --git a/jumpcloud/types.go b/jumpcloud/types.go deleted file mode 100644 index 8b53184..0000000 --- a/jumpcloud/types.go +++ /dev/null @@ -1,16 +0,0 @@ -package jumpcloud - -import jcapiv2 "github.com/TheJumpCloud/jcapi-go/v2" - -// UserGroup is like jcapiv2.UserGroup with Attributes -type UserGroup struct { - // ID uniquely identifies a User Group. - ID string `json:"id,omitempty"` - - // Type is the type of the group. - Type string `json:"type,omitempty"` - - // Display name of a User Group. - Name string `json:"name,omitempty"` - Attributes jcapiv2.UserGroupPostAttributes `json:"attributes,omitempty"` -} diff --git a/jumpcloud/utils.go b/jumpcloud/utils.go new file mode 100644 index 0000000..06ace18 --- /dev/null +++ b/jumpcloud/utils.go @@ -0,0 +1,17 @@ +package jumpcloud + +import ( + jcapiv1 "github.com/TheJumpCloud/jcapi-go/v1" + jcapiv2 "github.com/TheJumpCloud/jcapi-go/v2" +) + +// We receive a v2config from the TF base code but need a v1config to continue. So, we take the only +// preloaded element (the x-api-key) and populate the v1config with it. +func convertV2toV1Config(v2config *jcapiv2.Configuration) *jcapiv1.Configuration { + configv1 := jcapiv1.NewConfiguration() + configv1.AddDefaultHeader("x-api-key", v2config.DefaultHeader["x-api-key"]) + if v2config.DefaultHeader["x-org-id"] != "" { + configv1.AddDefaultHeader("x-org-id", v2config.DefaultHeader["x-org-id"]) + } + return configv1 +} diff --git a/main.go b/main.go index 3b277da..82f2d3a 100644 --- a/main.go +++ b/main.go @@ -1,14 +1,14 @@ package main import ( - "github.com/cognotektgmbh/terraform-provider-jumpcloud/jumpcloud" - "github.com/hashicorp/terraform-plugin-sdk/plugin" - "github.com/hashicorp/terraform-plugin-sdk/terraform" + "github.com/enthought/terraform-provider-jumpcloud/jumpcloud" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/plugin" ) func main() { plugin.Serve(&plugin.ServeOpts{ - ProviderFunc: func() terraform.ResourceProvider { + ProviderFunc: func() *schema.Provider { return jumpcloud.Provider() }, })