From 9cd6788b4868dd7a2455f48640c9ba8b8c7a661e Mon Sep 17 00:00:00 2001 From: Marais Kruger Date: Tue, 20 Aug 2024 13:36:02 +0200 Subject: [PATCH 1/7] mass commit --- .../examples/full-demo/main.tf | 6 +- pkg/config-api-provider/future_plan.tf | 86 +++++++++ pkg/config-api-provider/go.mod | 43 ++++- pkg/config-api-provider/go.sum | 164 +++++++++++++++++- pkg/config-api-provider/provider/provider.go | 3 +- .../provider/{ => resources}/group.go | 36 ++-- pkg/config-api-provider/test/group_test.go | 35 ++++ pkg/config-api-provider/test/provider_test.go | 21 +++ 8 files changed, 363 insertions(+), 31 deletions(-) create mode 100644 pkg/config-api-provider/future_plan.tf rename pkg/config-api-provider/provider/{ => resources}/group.go (85%) create mode 100644 pkg/config-api-provider/test/group_test.go create mode 100644 pkg/config-api-provider/test/provider_test.go diff --git a/pkg/config-api-provider/examples/full-demo/main.tf b/pkg/config-api-provider/examples/full-demo/main.tf index f5c23de6..ca664cf0 100644 --- a/pkg/config-api-provider/examples/full-demo/main.tf +++ b/pkg/config-api-provider/examples/full-demo/main.tf @@ -13,6 +13,6 @@ resource "uxi_group" "group" { parent_uid = "9999" } -output "group" { - value = uxi_group.group -} +# output "group" { +# value = uxi_group.group +# } diff --git a/pkg/config-api-provider/future_plan.tf b/pkg/config-api-provider/future_plan.tf new file mode 100644 index 00000000..433c23aa --- /dev/null +++ b/pkg/config-api-provider/future_plan.tf @@ -0,0 +1,86 @@ +// This file describes a potential layout for a manifest defined by the customer +// This file will be used as reference when building the terraform datasources and resources + +# Note: +# general data source | some sort of root_group_query +# investigate implementation of import block -> conflict of user defined fields +# assessment to see how difficult it would be for a user get the uid of various resources +# revisit the flow of a user onboarding existing resources -> moving from data source to resource + +data "uxi_group" "root_group" { + filter { + some_sort_of_filter = "" + } +} + +resource "uxi_group" "group" { + name = "group_name" # required, mutable + parent_uid = data.group.root_group.uid # required, immutable -> recreate on update +} + +# Sensor +resource "uxi_sensor" "sensor" { + name = "name" # mutable + address_note = "address_note" # mutable + notes = "note" # mutable + pcap_mode = "light" # mutable +} + +resource "uxi_sensor_group_assignment" "sensor_group_assignment" { + sensor_id = uxi_sensor.sensor.id # required, immutable -> recreate on update + group_id = uxi_group.group.id # required, immutable -> recreate on update +} + +# Agent +resource "uxi_agent" "agent_sensor" { + name = "name" # mutable + address_note = "address_note" # mutable + notes = "note" # mutable + pcap_mode = "light" # mutable +} + +resource "uxi_agent_group_assignment" "agent_group_assignment" { + agent_id = uxi_agent.agent_sensor.id # required, immutable -> recreate on update + group_id = uxi_group.group.id # required, immutable -> recreate on update +} + +# wireless networks +data "uxi_wireless_network" "wireless_network" { + uid = "" +} + +resource "uxi_network_group_assignment" "wireless_network_group_assignment" { + network_id = uxi_wireless_network.wireless_network.id # required, immutable -> recreate on update + group_id = uxi_group.group.id # required, immutable -> recreate on update +} + +# wired networks +data "uxi_wired_network" "wired_network" { + uid = "" +} + +resource "uxi_network_group_assignment" "wired_network_group_assignment" { + network_id = uxi_wired_network.wired_network.id # required, immutable -> recreate on update + group_id = uxi_group.group.id # required, immutable -> recreate on update +} + +# service-test +data "uxi_service_test" "service_test" { + uid = "" +} + +resource "uxi_service_test_group_assignment" "service_test_group_assignment" { + service_test_id = uxi_service_test.service_test.id # required, immutable -> recreate on update + group_id = uxi_group.group.id # required, immutable -> recreate on update +} + + +# ---------------------------------- +import { + to = "asfasdf" + id = uid +} + +resource "uxi_sensor_group_assignment" "" + +# terraform refresh-state diff --git a/pkg/config-api-provider/go.mod b/pkg/config-api-provider/go.mod index c2dd6d71..0f80674b 100644 --- a/pkg/config-api-provider/go.mod +++ b/pkg/config-api-provider/go.mod @@ -4,29 +4,62 @@ go 1.21 toolchain go1.22.5 -require github.com/hashicorp/terraform-plugin-framework v1.9.0 +require ( + github.com/golang/mock v1.6.0 + github.com/hashicorp/terraform-plugin-framework v1.9.0 + github.com/hashicorp/terraform-plugin-go v0.23.0 + github.com/hashicorp/terraform-plugin-testing v1.10.0 +) require ( + github.com/ProtonMail/go-crypto v1.1.0-alpha.2 // indirect + github.com/agext/levenshtein v1.2.2 // indirect + github.com/apparentlymart/go-textseg/v15 v15.0.0 // indirect + github.com/cloudflare/circl v1.3.7 // indirect github.com/fatih/color v1.16.0 // indirect github.com/golang/protobuf v1.5.4 // indirect + github.com/google/go-cmp v0.6.0 // 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.6.3 // indirect + github.com/hashicorp/go-multierror v1.1.1 // indirect github.com/hashicorp/go-plugin v1.6.0 // indirect + github.com/hashicorp/go-retryablehttp v0.7.7 // indirect github.com/hashicorp/go-uuid v1.0.3 // indirect - github.com/hashicorp/terraform-plugin-go v0.23.0 // indirect + github.com/hashicorp/go-version v1.7.0 // indirect + github.com/hashicorp/hc-install v0.8.0 // indirect + github.com/hashicorp/hcl/v2 v2.21.0 // indirect + github.com/hashicorp/logutils v1.0.0 // indirect + github.com/hashicorp/terraform-exec v0.21.0 // indirect + github.com/hashicorp/terraform-json v0.22.1 // indirect github.com/hashicorp/terraform-plugin-log v0.9.0 // indirect + github.com/hashicorp/terraform-plugin-sdk/v2 v2.34.0 // indirect github.com/hashicorp/terraform-registry-address v0.2.3 // indirect github.com/hashicorp/terraform-svchost v0.1.1 // indirect github.com/hashicorp/yamux v0.1.1 // indirect github.com/mattn/go-colorable v0.1.13 // indirect github.com/mattn/go-isatty v0.0.20 // 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/stretchr/testify v1.9.0 // indirect + github.com/vmihailenco/msgpack v4.0.4+incompatible // indirect github.com/vmihailenco/msgpack/v5 v5.4.1 // indirect github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect - golang.org/x/net v0.23.0 // indirect - golang.org/x/sys v0.20.0 // indirect - golang.org/x/text v0.15.0 // indirect + github.com/zclconf/go-cty v1.15.0 // indirect + golang.org/x/crypto v0.26.0 // indirect + golang.org/x/mod v0.19.0 // indirect + golang.org/x/net v0.25.0 // indirect + golang.org/x/sync v0.8.0 // indirect + golang.org/x/sys v0.23.0 // indirect + golang.org/x/text v0.17.0 // indirect + golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d // indirect + google.golang.org/appengine v1.6.8 // indirect google.golang.org/genproto/googleapis/rpc v0.0.0-20240227224415-6ceb2ff114de // indirect google.golang.org/grpc v1.63.2 // indirect google.golang.org/protobuf v1.34.0 // indirect diff --git a/pkg/config-api-provider/go.sum b/pkg/config-api-provider/go.sum index 9fc259be..a37925f8 100644 --- a/pkg/config-api-provider/go.sum +++ b/pkg/config-api-provider/go.sum @@ -1,35 +1,108 @@ +dario.cat/mergo v1.0.0 h1:AGCNq9Evsj31mOgNPcLyXc+4PNABt905YmuqPYYpBWk= +dario.cat/mergo v1.0.0/go.mod h1:uNxQE+84aUszobStD9th8a29P2fMDhsBdgRYvZOxGmk= +github.com/Microsoft/go-winio v0.6.1 h1:9/kr64B9VUZrLm5YYwbGtUJnMgqWVOdUAXu6Migciow= +github.com/Microsoft/go-winio v0.6.1/go.mod h1:LRdKpFKfdobln8UmuiYcKPot9D2v6svN5+sAH+4kjUM= +github.com/ProtonMail/go-crypto v1.1.0-alpha.2 h1:bkyFVUP+ROOARdgCiJzNQo2V2kiB97LyUpzH9P6Hrlg= +github.com/ProtonMail/go-crypto v1.1.0-alpha.2/go.mod h1:rA3QumHc/FZ8pAHreoekgiAbzpNsfQAosU5td4SnOrE= +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/v15 v15.0.0 h1:uYvfpb3DyLSCGWnctWKGj857c6ew1u1fNQOlOtuGxQY= +github.com/apparentlymart/go-textseg/v15 v15.0.0/go.mod h1:K8XmNZdhEBkdlyDdvbmmsvpAG721bKi0joRfFdHIWJ4= github.com/bufbuild/protocompile v0.4.0 h1:LbFKd2XowZvQ/kajzguUp2DC9UEIQhIq77fZZlaQsNA= github.com/bufbuild/protocompile v0.4.0/go.mod h1:3v93+mbWn/v3xzN+31nwkJfrEpAUwp+BagBSZWx+TP8= +github.com/cloudflare/circl v1.3.7 h1:qlCDlTPz2n9fu58M0Nh1J/JzcFpfgkFHHX3O35r5vcU= +github.com/cloudflare/circl v1.3.7/go.mod h1:sRTcRWXGLrKw6yIGJ+l7amYJFfAXbZG0kBSc8r4zxgA= +github.com/cyphar/filepath-securejoin v0.2.4 h1:Ugdm7cg7i6ZK6x3xDF1oEu1nfkyfH53EtKeQYTC3kyg= +github.com/cyphar/filepath-securejoin v0.2.4/go.mod h1:aPGpWjXOXUn2NCNjFvBE6aRxGGx79pTxQpKOJNYHHl4= 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/emirpasic/gods v1.18.1/go.mod h1:8tpGGwCnJ5H4r6BWwaV6OrWmMoPhUl5jm/FMNAnJvWQ= github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk= github.com/fatih/color v1.16.0 h1:zmkK9Ngbjj+K0yRhTVONQh1p/HknKYSlNT+vZCzyokM= github.com/fatih/color v1.16.0/go.mod h1:fL2Sau1YI5c0pdGEVCbKQbLXB6edEj1ZgiY4NijnWvE= +github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 h1:+zs/tPmkDkHx3U66DAb0lQFJrpS6731Oaa12ikc+DiI= +github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376/go.mod h1:an3vInlBmSxCcxctByoQdvwPiA7DTK7jaaFDBTtu0ic= +github.com/go-git/go-billy/v5 v5.5.0 h1:yEY4yhzCDuMGSv83oGxiBotRzhwhNr8VZyphhiu+mTU= +github.com/go-git/go-billy/v5 v5.5.0/go.mod h1:hmexnoNsr2SJU1Ju67OaNz5ASJY3+sHgFRpCtpDCKow= +github.com/go-git/go-git/v5 v5.12.0 h1:7Md+ndsjrzZxbddRDZjF14qK+NN56sy6wkqaVrjZtys= +github.com/go-git/go-git/v5 v5.12.0/go.mod h1:FTM9VKtnI2m65hNI/TenDDDnUf2Q9FHnXYjuz9i5OEY= +github.com/go-test/deep v1.0.3 h1:ZrJSEWsXzPOxaZnFteGEfooLba+ju3FYIbOrS+rQd68= +github.com/go-test/deep v1.0.3/go.mod h1:wGDj63lr65AM2AQyKZd/NYHGb0R+1RLqB8NKt3aSFNA= +github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da h1:oI5xCqsCo564l8iNU+DwB5epxmsaqB+rhGL0m5jtYqE= +github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= +github.com/golang/mock v1.6.0 h1:ErTB+efbowRARo13NNdxyJji2egdxLGQhRaY+DUumQc= +github.com/golang/mock v1.6.0/go.mod h1:p6yTPP+5HYm5mzsMV8JkE6ZKdX+/wYM6Hr+LicevLPs= +github.com/golang/protobuf v1.1.0/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.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek= github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps= +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.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= github.com/google/go-cmp v0.6.0/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.6.3 h1:Qr2kF+eVWjTiYmU7Y31tYlP1h0q/X3Nl3tPGdaB11/k= github.com/hashicorp/go-hclog v1.6.3/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.6.0 h1:wgd4KxHJTVGGqWBq4QPB1i5BZNEx9BR8+OFmHDmTk8A= github.com/hashicorp/go-plugin v1.6.0/go.mod h1:lBS5MtSSBZk0SHc66KACcjjlU6WzEVP/8pwz68aMkCI= +github.com/hashicorp/go-retryablehttp v0.7.7 h1:C8hUCYzor8PIfXHa4UrZkU4VvK8o9ISHxT2Q8+VepXU= +github.com/hashicorp/go-retryablehttp v0.7.7/go.mod h1:pkQpWZeYWskR+D1tR2O5OcBFOxfA7DoAO6xtkuQnHTk= +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.7.0 h1:5tqGy27NaOTB8yJKUZELlFAS/LTKJkrmONwQKeRZfjY= +github.com/hashicorp/go-version v1.7.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA= +github.com/hashicorp/hc-install v0.8.0 h1:LdpZeXkZYMQhoKPCecJHlKvUkQFixN/nvyR1CdfOLjI= +github.com/hashicorp/hc-install v0.8.0/go.mod h1:+MwJYjDfCruSD/udvBmRB22Nlkwwkwf5sAB6uTIhSaU= +github.com/hashicorp/hcl/v2 v2.21.0 h1:lve4q/o/2rqwYOgUg3y3V2YPyD1/zkCLGjIV74Jit14= +github.com/hashicorp/hcl/v2 v2.21.0/go.mod h1:62ZYHrXgPoX8xBnzl8QzbWq4dyDsDtfCRgIq1rbJEvA= +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.21.0 h1:uNkLAe95ey5Uux6KJdua6+cv8asgILFVWkd/RG0D2XQ= +github.com/hashicorp/terraform-exec v0.21.0/go.mod h1:1PPeMYou+KDUSSeRE9szMZ/oHf4fYUmB923Wzbq1ICg= +github.com/hashicorp/terraform-json v0.22.1 h1:xft84GZR0QzjPVWs4lRUwvTcPnegqlyS7orfb5Ltvec= +github.com/hashicorp/terraform-json v0.22.1/go.mod h1:JbWSQCLFSXFFhg42T7l9iJwdGXBYV8fmmD6o/ML4p3A= github.com/hashicorp/terraform-plugin-framework v1.9.0 h1:caLcDoxiRucNi2hk8+j3kJwkKfvHznubyFsJMWfZqKU= github.com/hashicorp/terraform-plugin-framework v1.9.0/go.mod h1:qBXLDn69kM97NNVi/MQ9qgd1uWWsVftGSnygYG1tImM= github.com/hashicorp/terraform-plugin-go v0.23.0 h1:AALVuU1gD1kPb48aPQUjug9Ir/125t+AAurhqphJ2Co= github.com/hashicorp/terraform-plugin-go v0.23.0/go.mod h1:1E3Cr9h2vMlahWMbsSEcNrOCxovCZhOOIXjFHbjc/lQ= 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.34.0 h1:kJiWGx2kiQVo97Y5IOGR4EMcZ8DtMswHhUuFibsCQQE= +github.com/hashicorp/terraform-plugin-sdk/v2 v2.34.0/go.mod h1:sl/UoabMc37HA6ICVMmGO+/0wofkVIRxf+BMb/dnoIg= +github.com/hashicorp/terraform-plugin-testing v1.10.0 h1:2+tmRNhvnfE4Bs8rB6v58S/VpqzGC6RCh9Y8ujdn+aw= +github.com/hashicorp/terraform-plugin-testing v1.10.0/go.mod h1:iWRW3+loP33WMch2P/TEyCxxct/ZEcCGMquSLSCVsrc= github.com/hashicorp/terraform-registry-address v0.2.3 h1:2TAiKJ1A3MAkZlH1YI/aTVcLZRu7JseiXNRHbOAyoTI= github.com/hashicorp/terraform-registry-address v0.2.3/go.mod h1:lFHA76T8jfQteVfT7caREqguFrW3c4MFSPhZB7HHgUM= 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.1.1 h1:yrQxtgseBDrq9Y652vSRDvsKCJKOUD+GzTS4Y0Y8pvE= github.com/hashicorp/yamux v0.1.1/go.mod h1:CtWFDAQgb7dxtzFs4tWbplKIe2jSi3+5vKbgIO0SLnQ= +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.15.1 h1:HUMERORf3I3ZdX05WaQ6MIpd/NJ434hTp5YiKgfCL6c= github.com/jhump/protoreflect v1.15.1/go.mod h1:jD/2GMKKE6OqX8qTjhADU1e6DShO+gavG9e0Q693nKo= +github.com/kevinburke/ssh_config v1.2.0 h1:x584FjTGwHzMwvHx18PXxbBVzfnxogHaAReU4gf13a4= +github.com/kevinburke/ssh_config v1.2.0/go.mod h1:CT57kijsi8u/K/BOFA39wgDQJ9CxiF4nAY/ojJ6r6mM= +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/mattn/go-colorable v0.1.9/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= github.com/mattn/go-colorable v0.1.12/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4= github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= @@ -39,39 +112,118 @@ github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27k github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= +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/pjbgf/sha1cd v0.3.0/go.mod h1:nZ1rrWOcGJ5uZgEEVL1VUM9iRQiZvWdbZjkKyFzPPsI= 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.3.2-0.20230802210424-5b0b94c5c0d3 h1:n661drycOFuPLCN3Uc8sB6B/s6Z4t2xvBgU1htSHuq8= +github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3/go.mod h1:A0bzQcvG0E7Rwjx0REVgAGH58e96+X0MeOfepqsbeW4= +github.com/skeema/knownhosts v1.2.2 h1:Iug2P4fLmDw9f41PB6thxUkNUkJzB5i+1/exaj40L3A= +github.com/skeema/knownhosts v1.2.2/go.mod h1:xYbVRSPxqBZFrdmDyMmsOs+uX1UZC3nTN3ThzgDxUwo= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.7.2/go.mod h1:R6va5+xMeoiuVRoj+gSkQ7d3FALtqAAGI1FQKckRals= github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +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.4.1 h1:cQriyiUvjTwOHg8QZaPihLWeRAAVoCpE00IUPn0Bjt8= github.com/vmihailenco/msgpack/v5 v5.4.1/go.mod h1:GaZTsDaehaPpQVyxrf5mtQlH+pc21PIudVV/E3rRQok= 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= -golang.org/x/net v0.23.0 h1:7EYJ93RZ9vYSZAIb2x3lnuvqO5zneoD6IvWjuhfxjTs= -golang.org/x/net v0.23.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg= +github.com/xanzy/ssh-agent v0.3.3 h1:+/15pJfg/RsTxqYcX6fHqOXZwwMP+2VyYWJeWM2qQFM= +github.com/xanzy/ssh-agent v0.3.3/go.mod h1:6dzNDKs0J9rVPHPhaGCukekBHKqfl+L3KghI1Bc68Uw= +github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= +github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= +github.com/zclconf/go-cty v1.15.0 h1:tTCRWxsexYUmtt/wVxgDClUe+uQusuI443uL6e+5sXQ= +github.com/zclconf/go-cty v1.15.0/go.mod h1:VvMs5i0vgZdhYawQNq5kePSpLAoz8u1xvZgrPIxfnZE= +github.com/zclconf/go-cty-debug v0.0.0-20240509010212-0d6042c53940 h1:4r45xpDWB6ZMSMNJFMOjqrGHynW3DIBuR2H9j0ug+Mo= +github.com/zclconf/go-cty-debug v0.0.0-20240509010212-0d6042c53940/go.mod h1:CmBdvvj3nqzfzJ6nTCIwDTPZ56aVGvDrmztiO5g3qrM= +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-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= +golang.org/x/crypto v0.26.0 h1:RrRspgV4mU+YwB4FYnuBoKsUapNIL5cohGAmSH3azsw= +golang.org/x/crypto v0.26.0/go.mod h1:GY7jblb9wI+FOo5y8/S2oY4zWP07AkOJ4+jxCqdqn54= +golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= +golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= +golang.org/x/mod v0.19.0 h1:fEdghXQSo20giMthA7cd28ZC+jts4amQ3YMXiP5oMQ8= +golang.org/x/mod v0.19.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= +golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= +golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM= +golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= +golang.org/x/net v0.25.0 h1:d/OCCoBEUq33pjydKrGQhw7IlUPI2Oylr+8qLx49kac= +golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM= +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-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ= +golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 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-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +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-20220503163025-988cb79eb6c6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.20.0 h1:Od9JTbYCk261bKm4M/mw7AklTlFYIa0bIp9BgSm1S8Y= -golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= -golang.org/x/text v0.15.0 h1:h1V/4gjBv8v9cjcR6+AR5+/cIYK5N/WAgiv4xlsEtAk= -golang.org/x/text v0.15.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= +golang.org/x/sys v0.23.0 h1:YfKFowiIMvtgl1UERQoTPPToxltDeZfbj4H7dVUCwmM= +golang.org/x/sys v0.23.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +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/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.17.0 h1:XtiM5bkSOt+ewxlOE/aE/AKEHibwj/6gvWMl9Rsh0Qc= +golang.org/x/text v0.17.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY= +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= +golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= +golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= +golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d h1:vU5i/LfpvrRCpgM/VPfJLg5KjxD3E+hfT1SH+d9zLwg= +golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d/go.mod h1:aiJjzUbINMkxbQROHiO6hDPo2LHcIPhhQsa9DLh0yGk= +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= +golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= +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/googleapis/rpc v0.0.0-20240227224415-6ceb2ff114de h1:cZGRis4/ot9uVm639a+rHCUaG0JJHEsdyzSQTMX+suY= google.golang.org/genproto/googleapis/rpc v0.0.0-20240227224415-6ceb2ff114de/go.mod h1:H4O17MA/PE9BsGx3w+a+W2VOLLD1Qf7oJneAoU6WktY= google.golang.org/grpc v1.63.2 h1:MUeiw1B2maTVZthpU5xvASfTh3LDbxHd6IJ6QQVU+xM= google.golang.org/grpc v1.63.2/go.mod h1:WAX/8DgncnokcFUldAxq7GeB5DXHDbMF+lLvDomNkRA= +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.34.0 h1:Qo/qEd2RZPCf2nKuorzksSknv0d3ERwp1vFG38gSmH4= google.golang.org/protobuf v1.34.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= 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/warnings.v0 v0.1.2/go.mod h1:jksf8JmL6Qr/oQM2OXTHunEvvTAsrWBLb6OOjuVWRNI= 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/pkg/config-api-provider/provider/provider.go b/pkg/config-api-provider/provider/provider.go index 3cdc0a06..9bac41ef 100644 --- a/pkg/config-api-provider/provider/provider.go +++ b/pkg/config-api-provider/provider/provider.go @@ -3,6 +3,7 @@ package provider import ( "context" + "github.com/aruba-uxi/configuration-api-terraform-provider/pkg/terraform-provider-configuration/provider/resources" "github.com/hashicorp/terraform-plugin-framework/datasource" "github.com/hashicorp/terraform-plugin-framework/provider" "github.com/hashicorp/terraform-plugin-framework/provider/schema" @@ -56,6 +57,6 @@ func (p *uxiConfigurationProvider) DataSources(_ context.Context) []func() datas // Resources defines the resources implemented in the provider. func (p *uxiConfigurationProvider) Resources(_ context.Context) []func() resource.Resource { return []func() resource.Resource{ - NewGroupResource, + resources.NewGroupResource, } } diff --git a/pkg/config-api-provider/provider/group.go b/pkg/config-api-provider/provider/resources/group.go similarity index 85% rename from pkg/config-api-provider/provider/group.go rename to pkg/config-api-provider/provider/resources/group.go index a4e46ac0..9fe45eed 100644 --- a/pkg/config-api-provider/provider/group.go +++ b/pkg/config-api-provider/provider/resources/group.go @@ -1,10 +1,11 @@ -package provider +package resources import ( "context" "time" + "github.com/hashicorp/terraform-plugin-framework/path" "github.com/hashicorp/terraform-plugin-framework/resource" "github.com/hashicorp/terraform-plugin-framework/resource/schema" "github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier" @@ -18,7 +19,6 @@ var ( _ resource.ResourceWithConfigure = &groupResource{} ) -// orderResourceModel maps the resource schema data. type groupResourceModel struct { ID types.String `tfsdk:"id"` Name types.String `tfsdk:"name"` @@ -26,27 +26,23 @@ type groupResourceModel struct { LastUpdated types.String `tfsdk:"last_updated"` } -type createGroupResonseModel struct { +type groupResonseModel struct { UID string Name string ParentUid string Path string } -// NewOrderResource is a helper function to simplify the provider implementation. func NewGroupResource() resource.Resource { return &groupResource{} } -// orderResource is the resource implementation. type groupResource struct{} -// Metadata returns the resource type name. func (r *groupResource) Metadata(ctx context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) { resp.TypeName = req.ProviderTypeName + "_group" } -// Schema defines the schema for the resource. func (r *groupResource) Schema(_ context.Context, _ resource.SchemaRequest, resp *resource.SchemaResponse) { resp.Schema = schema.Schema{ Attributes: map[string]schema.Attribute{ @@ -71,11 +67,9 @@ func (r *groupResource) Schema(_ context.Context, _ resource.SchemaRequest, resp } } -// Configure adds the provider configured client to the resource. func (r *groupResource) Configure(_ context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) { } -// Create creates the resource and sets the initial Terraform state. func (r *groupResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { // Retrieve values from plan var plan groupResourceModel @@ -101,7 +95,6 @@ func (r *groupResource) Create(ctx context.Context, req resource.CreateRequest, } } -// Read refreshes the Terraform state with the latest data. func (r *groupResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) { // Get current state var state groupResourceModel @@ -113,10 +106,7 @@ func (r *groupResource) Read(ctx context.Context, req resource.ReadRequest, resp // TODO: Call client create-group method // We are mocking the response of the client for this early stage of development - response := createGroupResonseModel{ - Name: "test_name_read", - ParentUid: "1234", - } + response := GetGroup() // Update state from client response state.Name = types.StringValue(response.Name) @@ -131,7 +121,6 @@ func (r *groupResource) Read(ctx context.Context, req resource.ReadRequest, resp } } -// Update updates the resource and sets the updated Terraform state on success. func (r *groupResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { // Retrieve values from plan var plan groupResourceModel @@ -154,7 +143,6 @@ func (r *groupResource) Update(ctx context.Context, req resource.UpdateRequest, } } -// Delete deletes the resource and removes the Terraform state on success. func (r *groupResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) { // Retrieve values from state var state groupResourceModel @@ -166,3 +154,19 @@ func (r *groupResource) Delete(ctx context.Context, req resource.DeleteRequest, // Delete existing group using the plan_id } + +func (r *groupResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { + resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp) +} + +// Get the group using the configuration-api client +func GetGroup() groupResonseModel { + // TODO: Query the group using the client + + return groupResonseModel{ + UID: "temporary_uid", + Name: "temporary_name", + ParentUid: "temporary_parent_uid", + Path: "temporary_path", + } +} diff --git a/pkg/config-api-provider/test/group_test.go b/pkg/config-api-provider/test/group_test.go new file mode 100644 index 00000000..4900f8cd --- /dev/null +++ b/pkg/config-api-provider/test/group_test.go @@ -0,0 +1,35 @@ +package test + +import ( + "testing" + + "github.com/hashicorp/terraform-plugin-testing/helper/resource" +) + +type Fetcher interface { + FetchData() ([]byte, error) +} + +func TestGroupResource(t *testing.T) { + createGroupConfig := ` + resource "uxi_group" "test_group" { + name = "test_name" + parent_uid = "9999" + }` + + resource.Test(t, resource.TestCase{ + ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, + Steps: []resource.TestStep{ + // Create and Read testing + { + Config: providerConfig + createGroupConfig, + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("uxi_group.test_group", "name", "test_name"), + resource.TestCheckResourceAttr("uxi_group.test_group", "parent_uid", "9999"), + resource.TestCheckResourceAttrSet("uxi_group.test_group", "id"), + resource.TestCheckResourceAttrSet("uxi_group.test_group", "last_updated"), + ), + }, + }, + }) +} diff --git a/pkg/config-api-provider/test/provider_test.go b/pkg/config-api-provider/test/provider_test.go new file mode 100644 index 00000000..a181751e --- /dev/null +++ b/pkg/config-api-provider/test/provider_test.go @@ -0,0 +1,21 @@ +package test + +import ( + "github.com/aruba-uxi/configuration-api-terraform-provider/pkg/terraform-provider-configuration/provider" + "github.com/hashicorp/terraform-plugin-framework/providerserver" + "github.com/hashicorp/terraform-plugin-go/tfprotov6" +) + +const ( + providerConfig = `provider "uxi" {}` +) + +var ( + // testAccProtoV6ProviderFactories are used to instantiate a provider during + // acceptance testing. The factory function will be invoked for every Terraform + // CLI command executed to create a provider server to which the CLI can + // reattach. + testAccProtoV6ProviderFactories = map[string]func() (tfprotov6.ProviderServer, error){ + "uxi": providerserver.NewProtocol6WithError(provider.New("test")()), + } +) From 5109d2adfa67b4ca5aa2085b7cabbebffb0cb00d Mon Sep 17 00:00:00 2001 From: 1riatsila1 Date: Wed, 21 Aug 2024 13:20:18 +0200 Subject: [PATCH 2/7] feat: sensor and agent resources --- .../examples/full-demo/main.tf | 23 ++- pkg/config-api-provider/future_plan.tf | 1 - pkg/config-api-provider/go.mod | 1 - pkg/config-api-provider/go.sum | 13 -- pkg/config-api-provider/provider/provider.go | 2 + .../provider/resources/agent.go | 161 ++++++++++++++++ .../provider/resources/sensor.go | 173 ++++++++++++++++++ 7 files changed, 356 insertions(+), 18 deletions(-) create mode 100644 pkg/config-api-provider/provider/resources/agent.go create mode 100644 pkg/config-api-provider/provider/resources/sensor.go diff --git a/pkg/config-api-provider/examples/full-demo/main.tf b/pkg/config-api-provider/examples/full-demo/main.tf index ca664cf0..44286e7d 100644 --- a/pkg/config-api-provider/examples/full-demo/main.tf +++ b/pkg/config-api-provider/examples/full-demo/main.tf @@ -8,9 +8,26 @@ terraform { provider "uxi" {} -resource "uxi_group" "group" { - name = "test_name" - parent_uid = "9999" +# resource "uxi_group" "group" { +# name = "test_name" +# parent_uid = "9999" +# } + +// to import: terraform import uxi_sensor.my_sensor my_sensor_uid +// to remove: terraform state rm uxi_sensor.my_sensor +resource "uxi_sensor" "my_sensor" { + name = "name" + address_note = "address_note" + notes = "notes" + pcap_mode = "pcap_mode" +} + +// to import: terraform import uxi_agent.my_agent my_agent_uid +// to remove: terraform state rm uxi_agent.my_agent +resource "uxi_agent" "my_agent" { + name = "name" + notes = "notes" + pcap_mode = "pcap_mode" } # output "group" { diff --git a/pkg/config-api-provider/future_plan.tf b/pkg/config-api-provider/future_plan.tf index 433c23aa..cec69628 100644 --- a/pkg/config-api-provider/future_plan.tf +++ b/pkg/config-api-provider/future_plan.tf @@ -34,7 +34,6 @@ resource "uxi_sensor_group_assignment" "sensor_group_assignment" { # Agent resource "uxi_agent" "agent_sensor" { name = "name" # mutable - address_note = "address_note" # mutable notes = "note" # mutable pcap_mode = "light" # mutable } diff --git a/pkg/config-api-provider/go.mod b/pkg/config-api-provider/go.mod index 0f80674b..d20b4ddf 100644 --- a/pkg/config-api-provider/go.mod +++ b/pkg/config-api-provider/go.mod @@ -5,7 +5,6 @@ go 1.21 toolchain go1.22.5 require ( - github.com/golang/mock v1.6.0 github.com/hashicorp/terraform-plugin-framework v1.9.0 github.com/hashicorp/terraform-plugin-go v0.23.0 github.com/hashicorp/terraform-plugin-testing v1.10.0 diff --git a/pkg/config-api-provider/go.sum b/pkg/config-api-provider/go.sum index a37925f8..8c5d97ab 100644 --- a/pkg/config-api-provider/go.sum +++ b/pkg/config-api-provider/go.sum @@ -33,8 +33,6 @@ github.com/go-test/deep v1.0.3 h1:ZrJSEWsXzPOxaZnFteGEfooLba+ju3FYIbOrS+rQd68= github.com/go-test/deep v1.0.3/go.mod h1:wGDj63lr65AM2AQyKZd/NYHGb0R+1RLqB8NKt3aSFNA= github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da h1:oI5xCqsCo564l8iNU+DwB5epxmsaqB+rhGL0m5jtYqE= github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= -github.com/golang/mock v1.6.0 h1:ErTB+efbowRARo13NNdxyJji2egdxLGQhRaY+DUumQc= -github.com/golang/mock v1.6.0/go.mod h1:p6yTPP+5HYm5mzsMV8JkE6ZKdX+/wYM6Hr+LicevLPs= github.com/golang/protobuf v1.1.0/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= @@ -145,41 +143,33 @@ github.com/vmihailenco/tagparser/v2 v2.0.0 h1:y09buUbR+b5aycVFQs/g70pqKVZNBmxwAh 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/xanzy/ssh-agent v0.3.3/go.mod h1:6dzNDKs0J9rVPHPhaGCukekBHKqfl+L3KghI1Bc68Uw= -github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= github.com/zclconf/go-cty v1.15.0 h1:tTCRWxsexYUmtt/wVxgDClUe+uQusuI443uL6e+5sXQ= github.com/zclconf/go-cty v1.15.0/go.mod h1:VvMs5i0vgZdhYawQNq5kePSpLAoz8u1xvZgrPIxfnZE= github.com/zclconf/go-cty-debug v0.0.0-20240509010212-0d6042c53940 h1:4r45xpDWB6ZMSMNJFMOjqrGHynW3DIBuR2H9j0ug+Mo= github.com/zclconf/go-cty-debug v0.0.0-20240509010212-0d6042c53940/go.mod h1:CmBdvvj3nqzfzJ6nTCIwDTPZ56aVGvDrmztiO5g3qrM= 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-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.26.0 h1:RrRspgV4mU+YwB4FYnuBoKsUapNIL5cohGAmSH3azsw= golang.org/x/crypto v0.26.0/go.mod h1:GY7jblb9wI+FOo5y8/S2oY4zWP07AkOJ4+jxCqdqn54= -golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= golang.org/x/mod v0.19.0 h1:fEdghXQSo20giMthA7cd28ZC+jts4amQ3YMXiP5oMQ8= golang.org/x/mod v0.19.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= -golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM= golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= golang.org/x/net v0.25.0 h1:d/OCCoBEUq33pjydKrGQhw7IlUPI2Oylr+8qLx49kac= golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM= 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-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ= golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 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-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 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= @@ -201,14 +191,11 @@ golang.org/x/text v0.17.0 h1:XtiM5bkSOt+ewxlOE/aE/AKEHibwj/6gvWMl9Rsh0Qc= golang.org/x/text v0.17.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY= 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= -golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d h1:vU5i/LfpvrRCpgM/VPfJLg5KjxD3E+hfT1SH+d9zLwg= golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d/go.mod h1:aiJjzUbINMkxbQROHiO6hDPo2LHcIPhhQsa9DLh0yGk= 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= -golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= google.golang.org/appengine v1.6.8 h1:IhEN5q69dyKagZPYMSdIjS2HqprW324FRQZJcGqPAsM= google.golang.org/appengine v1.6.8/go.mod h1:1jJ3jBArFh5pcgW8gCtRJnepW8FzD1V44FJffLiz/Ds= diff --git a/pkg/config-api-provider/provider/provider.go b/pkg/config-api-provider/provider/provider.go index 9bac41ef..1dc24978 100644 --- a/pkg/config-api-provider/provider/provider.go +++ b/pkg/config-api-provider/provider/provider.go @@ -57,6 +57,8 @@ func (p *uxiConfigurationProvider) DataSources(_ context.Context) []func() datas // Resources defines the resources implemented in the provider. func (p *uxiConfigurationProvider) Resources(_ context.Context) []func() resource.Resource { return []func() resource.Resource{ + resources.NewAgentResource, resources.NewGroupResource, + resources.NewSensorResource, } } diff --git a/pkg/config-api-provider/provider/resources/agent.go b/pkg/config-api-provider/provider/resources/agent.go new file mode 100644 index 00000000..e3533278 --- /dev/null +++ b/pkg/config-api-provider/provider/resources/agent.go @@ -0,0 +1,161 @@ +package resources + +import ( + "context" + + "time" + + "github.com/hashicorp/terraform-plugin-framework/path" + "github.com/hashicorp/terraform-plugin-framework/resource" + "github.com/hashicorp/terraform-plugin-framework/resource/schema" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier" + "github.com/hashicorp/terraform-plugin-framework/types" +) + +// Ensure the implementation satisfies the expected interfaces. +var ( + _ resource.Resource = &agentResource{} + _ resource.ResourceWithConfigure = &agentResource{} +) + +type agentResourceModel struct { + ID types.String `tfsdk:"id"` + Name types.String `tfsdk:"name"` + Notes types.String `tfsdk:"notes"` + PCapMode types.String `tfsdk:"pcap_mode"` + LastUpdated types.String `tfsdk:"last_updated"` +} + +type agentResponseModel struct { + Uid string + Serial string + Name string + ModelNumber string + WifiMacAddress string + EthernetMacAddress string + Notes string + PCapMode string +} + +func NewAgentResource() resource.Resource { + return &agentResource{} +} + +type agentResource struct{} + +func (r *agentResource) Metadata(ctx context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) { + resp.TypeName = req.ProviderTypeName + "_agent" +} + +func (r *agentResource) Schema(_ context.Context, _ resource.SchemaRequest, resp *resource.SchemaResponse) { + resp.Schema = schema.Schema{ + Attributes: map[string]schema.Attribute{ + "id": schema.StringAttribute{ + Computed: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.UseStateForUnknown(), + }, + }, + "last_updated": schema.StringAttribute{ + Computed: true, + }, + "name": schema.StringAttribute{ + Required: true, + }, + "notes": schema.StringAttribute{ + Optional: true, + }, + "pcap_mode": schema.StringAttribute{ + Optional: true, + }, + }, + } +} + +func (r *agentResource) Configure(_ context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) { +} + +func (r *agentResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { + // Retrieve values from plan + var plan agentResourceModel + diags := req.Plan.Get(ctx, &plan) + diags.AddError("operation not supported", "creating an agent resource is not supported; agents can only be imported") + resp.Diagnostics.Append(diags...) +} + +func (r *agentResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) { + // Get current state + var state agentResourceModel + diags := req.State.Get(ctx, &state) + resp.Diagnostics.Append(diags...) + if resp.Diagnostics.HasError() { + return + } + + // TODO: Call client create-agent method + // We are mocking the response of the client for this early stage of development + response := GetAgent() + + // Update state from client response + state.Name = types.StringValue(response.Name) + state.Notes = types.StringValue(response.Notes) + state.PCapMode = types.StringValue(response.PCapMode) + state.LastUpdated = types.StringValue(time.Now().Format(time.RFC850)) + + // Set refreshed state + diags = resp.State.Set(ctx, &state) + resp.Diagnostics.Append(diags...) + if resp.Diagnostics.HasError() { + return + } +} + +func (r *agentResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { + // Retrieve values from plan + var plan agentResourceModel + diags := req.Plan.Get(ctx, &plan) + resp.Diagnostics.Append(diags...) + if resp.Diagnostics.HasError() { + return + } + + // TODO: Call client update-agent method + + // Update the state to match the plan (replace with response from client) + plan.LastUpdated = types.StringValue(time.Now().Format(time.RFC850)) + + // Set state to fully populated data + diags = resp.State.Set(ctx, plan) + resp.Diagnostics.Append(diags...) + if resp.Diagnostics.HasError() { + return + } +} + +func (r *agentResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) { + // Retrieve values from state + var state agentResourceModel + diags := req.State.Get(ctx, &state) + diags.AddError("operation not supported", "deleting an agent resource is not supported; agents can only removed from state") + resp.Diagnostics.Append(diags...) +} + +func (r *agentResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { + resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp) +} + +// Get the agent using the configuration-api client +func GetAgent() agentResponseModel { + // TODO: Query the agent using the client + + return agentResponseModel{ + Serial: "temporary_serial", + Name: "temporary_name", + ModelNumber: "temporary_model_number", + WifiMacAddress: "temporary_wifi_mac_address", + EthernetMacAddress: "temporary_ethernet_mac_address", + Notes: "temporary_notes", + PCapMode: "temporary_pcap_mode", + } +} diff --git a/pkg/config-api-provider/provider/resources/sensor.go b/pkg/config-api-provider/provider/resources/sensor.go new file mode 100644 index 00000000..f095d9d1 --- /dev/null +++ b/pkg/config-api-provider/provider/resources/sensor.go @@ -0,0 +1,173 @@ +package resources + +import ( + "context" + + "time" + + "github.com/hashicorp/terraform-plugin-framework/path" + "github.com/hashicorp/terraform-plugin-framework/resource" + "github.com/hashicorp/terraform-plugin-framework/resource/schema" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier" + "github.com/hashicorp/terraform-plugin-framework/types" +) + +// Ensure the implementation satisfies the expected interfaces. +var ( + _ resource.Resource = &sensorResource{} + _ resource.ResourceWithConfigure = &sensorResource{} +) + +type sensorResourceModel struct { + ID types.String `tfsdk:"id"` + Name types.String `tfsdk:"name"` + AddressNote types.String `tfsdk:"address_note"` + Notes types.String `tfsdk:"notes"` + PCapMode types.String `tfsdk:"pcap_mode"` + LastUpdated types.String `tfsdk:"last_updated"` +} + +type sensorResponseModel struct { + UID string + Serial string + Name string + ModelNumber string + WifiMacAddress string + EthernetMacAddress string + AddressNote string + Longitude string + Latitude string + Notes string + PCapMode string +} + +func NewSensorResource() resource.Resource { + return &sensorResource{} +} + +type sensorResource struct{} + +func (r *sensorResource) Metadata(ctx context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) { + resp.TypeName = req.ProviderTypeName + "_sensor" +} + +func (r *sensorResource) Schema(_ context.Context, _ resource.SchemaRequest, resp *resource.SchemaResponse) { + resp.Schema = schema.Schema{ + Attributes: map[string]schema.Attribute{ + "id": schema.StringAttribute{ + Computed: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.UseStateForUnknown(), + }, + }, + "last_updated": schema.StringAttribute{ + Computed: true, + }, + "name": schema.StringAttribute{ + Required: true, + }, + "address_note": schema.StringAttribute{ + Optional: true, + }, + "notes": schema.StringAttribute{ + Optional: true, + }, + "pcap_mode": schema.StringAttribute{ + Optional: true, + }, + }, + } +} + +func (r *sensorResource) Configure(_ context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) { +} + +func (r *sensorResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { + // Retrieve values from plan + var plan sensorResourceModel + diags := req.Plan.Get(ctx, &plan) + diags.AddError("operation not supported", "creating a sensor resource is not supported; sensors can only be imported") + resp.Diagnostics.Append(diags...) +} + +func (r *sensorResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) { + // Get current state + var state sensorResourceModel + diags := req.State.Get(ctx, &state) + resp.Diagnostics.Append(diags...) + if resp.Diagnostics.HasError() { + return + } + + // TODO: Call client create-sensor method + // We are mocking the response of the client for this early stage of development + response := GetSensor() + + // Update state from client response + state.Name = types.StringValue(response.Name) + state.AddressNote = types.StringValue(response.AddressNote) + state.Notes = types.StringValue(response.Notes) + state.PCapMode = types.StringValue(response.PCapMode) + state.LastUpdated = types.StringValue(time.Now().Format(time.RFC850)) + + // Set refreshed state + diags = resp.State.Set(ctx, &state) + resp.Diagnostics.Append(diags...) + if resp.Diagnostics.HasError() { + return + } +} + +func (r *sensorResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { + // Retrieve values from plan + var plan sensorResourceModel + diags := req.Plan.Get(ctx, &plan) + resp.Diagnostics.Append(diags...) + if resp.Diagnostics.HasError() { + return + } + + // TODO: Call client update-sensor method + + // Update the state to match the plan (replace with response from client) + plan.LastUpdated = types.StringValue(time.Now().Format(time.RFC850)) + + // Set state to fully populated data + diags = resp.State.Set(ctx, plan) + resp.Diagnostics.Append(diags...) + if resp.Diagnostics.HasError() { + return + } +} + +func (r *sensorResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) { + // Retrieve values from state + var state sensorResourceModel + diags := req.State.Get(ctx, &state) + diags.AddError("operation not supported", "deleting a sensor resource is not supported; sensors can only removed from state") + resp.Diagnostics.Append(diags...) +} + +func (r *sensorResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { + resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp) +} + +// Get the sensor using the configuration-api client +func GetSensor() sensorResponseModel { + // TODO: Query the sensor using the client + + return sensorResponseModel{ + UID: "temporary_uid", + Serial: "temporary_serial", + Name: "temporary_name", + ModelNumber: "temporary_model_number", + WifiMacAddress: "temporary_wifi_mac_address", + EthernetMacAddress: "temporary_ethernet_mac_address", + AddressNote: "temporary_address_note", + Longitude: "temporary_longitude", + Latitude: "temporary_latitude", + Notes: "temporary_notes", + PCapMode: "temporary_pcap_mode", + } +} From abe0902bea0816f848e4e6ae757c0517cdc4ff4a Mon Sep 17 00:00:00 2001 From: 1riatsila1 Date: Thu, 22 Aug 2024 16:57:55 +0200 Subject: [PATCH 3/7] feat: sensor tests --- cmd/client_tester/main.go | 2 +- pkg/config-api-provider/go.mod | 10 +- pkg/config-api-provider/go.sum | 15 +- .../provider/resources/agent.go | 4 +- .../provider/resources/sensor.go | 86 ++++++++---- pkg/config-api-provider/test/sensor_test.go | 132 ++++++++++++++++++ 6 files changed, 203 insertions(+), 46 deletions(-) create mode 100644 pkg/config-api-provider/test/sensor_test.go diff --git a/cmd/client_tester/main.go b/cmd/client_tester/main.go index e12ff94d..18a31574 100644 --- a/cmd/client_tester/main.go +++ b/cmd/client_tester/main.go @@ -15,7 +15,7 @@ func main() { config.Scheme = "http" client := config_api_client.NewAPIClient(config) - resp, httpResp, err := client.HealthAPI.GetLivezHealthLivezGet(context.Background()).Execute() + resp, httpResp, err := client.ConfigurationAPI.GetLivezHealthLivezGet(context.Background()).Execute() fmt.Println(resp) fmt.Println(httpResp) diff --git a/pkg/config-api-provider/go.mod b/pkg/config-api-provider/go.mod index 0f80674b..d4d44603 100644 --- a/pkg/config-api-provider/go.mod +++ b/pkg/config-api-provider/go.mod @@ -5,10 +5,11 @@ go 1.21 toolchain go1.22.5 require ( - github.com/golang/mock v1.6.0 + github.com/aruba-uxi/configuration-api-terraform-provider/pkg/config-api-client v0.0.0-00010101000000-000000000000 github.com/hashicorp/terraform-plugin-framework v1.9.0 github.com/hashicorp/terraform-plugin-go v0.23.0 github.com/hashicorp/terraform-plugin-testing v1.10.0 + github.com/stretchr/testify v1.9.0 ) require ( @@ -16,6 +17,7 @@ require ( github.com/agext/levenshtein v1.2.2 // indirect github.com/apparentlymart/go-textseg/v15 v15.0.0 // indirect github.com/cloudflare/circl v1.3.7 // indirect + github.com/davecgh/go-spew v1.1.1 // indirect github.com/fatih/color v1.16.0 // indirect github.com/golang/protobuf v1.5.4 // indirect github.com/google/go-cmp v0.6.0 // indirect @@ -47,7 +49,8 @@ require ( 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/stretchr/testify v1.9.0 // indirect + github.com/pmezard/go-difflib v1.0.0 // indirect + github.com/stretchr/objx v0.5.2 // indirect github.com/vmihailenco/msgpack v4.0.4+incompatible // indirect github.com/vmihailenco/msgpack/v5 v5.4.1 // indirect github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect @@ -63,4 +66,7 @@ require ( google.golang.org/genproto/googleapis/rpc v0.0.0-20240227224415-6ceb2ff114de // indirect google.golang.org/grpc v1.63.2 // indirect google.golang.org/protobuf v1.34.0 // indirect + gopkg.in/yaml.v3 v3.0.1 // indirect ) + +replace github.com/aruba-uxi/configuration-api-terraform-provider/pkg/config-api-client => ../config-api-client diff --git a/pkg/config-api-provider/go.sum b/pkg/config-api-provider/go.sum index a37925f8..4a663b0a 100644 --- a/pkg/config-api-provider/go.sum +++ b/pkg/config-api-provider/go.sum @@ -33,8 +33,6 @@ github.com/go-test/deep v1.0.3 h1:ZrJSEWsXzPOxaZnFteGEfooLba+ju3FYIbOrS+rQd68= github.com/go-test/deep v1.0.3/go.mod h1:wGDj63lr65AM2AQyKZd/NYHGb0R+1RLqB8NKt3aSFNA= github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da h1:oI5xCqsCo564l8iNU+DwB5epxmsaqB+rhGL0m5jtYqE= github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= -github.com/golang/mock v1.6.0 h1:ErTB+efbowRARo13NNdxyJji2egdxLGQhRaY+DUumQc= -github.com/golang/mock v1.6.0/go.mod h1:p6yTPP+5HYm5mzsMV8JkE6ZKdX+/wYM6Hr+LicevLPs= github.com/golang/protobuf v1.1.0/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= @@ -133,6 +131,8 @@ github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3/go.mod h1:A0bzQcvG github.com/skeema/knownhosts v1.2.2 h1:Iug2P4fLmDw9f41PB6thxUkNUkJzB5i+1/exaj40L3A= github.com/skeema/knownhosts v1.2.2/go.mod h1:xYbVRSPxqBZFrdmDyMmsOs+uX1UZC3nTN3ThzgDxUwo= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/objx v0.5.2 h1:xuMeJ0Sdp5ZMRXx/aWO6RZxdr3beISkG5/G/aIRr3pY= +github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA= github.com/stretchr/testify v1.7.2/go.mod h1:R6va5+xMeoiuVRoj+gSkQ7d3FALtqAAGI1FQKckRals= github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= @@ -145,41 +145,33 @@ github.com/vmihailenco/tagparser/v2 v2.0.0 h1:y09buUbR+b5aycVFQs/g70pqKVZNBmxwAh 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/xanzy/ssh-agent v0.3.3/go.mod h1:6dzNDKs0J9rVPHPhaGCukekBHKqfl+L3KghI1Bc68Uw= -github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= github.com/zclconf/go-cty v1.15.0 h1:tTCRWxsexYUmtt/wVxgDClUe+uQusuI443uL6e+5sXQ= github.com/zclconf/go-cty v1.15.0/go.mod h1:VvMs5i0vgZdhYawQNq5kePSpLAoz8u1xvZgrPIxfnZE= github.com/zclconf/go-cty-debug v0.0.0-20240509010212-0d6042c53940 h1:4r45xpDWB6ZMSMNJFMOjqrGHynW3DIBuR2H9j0ug+Mo= github.com/zclconf/go-cty-debug v0.0.0-20240509010212-0d6042c53940/go.mod h1:CmBdvvj3nqzfzJ6nTCIwDTPZ56aVGvDrmztiO5g3qrM= 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-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.26.0 h1:RrRspgV4mU+YwB4FYnuBoKsUapNIL5cohGAmSH3azsw= golang.org/x/crypto v0.26.0/go.mod h1:GY7jblb9wI+FOo5y8/S2oY4zWP07AkOJ4+jxCqdqn54= -golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= golang.org/x/mod v0.19.0 h1:fEdghXQSo20giMthA7cd28ZC+jts4amQ3YMXiP5oMQ8= golang.org/x/mod v0.19.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= -golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM= golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= golang.org/x/net v0.25.0 h1:d/OCCoBEUq33pjydKrGQhw7IlUPI2Oylr+8qLx49kac= golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM= 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-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ= golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 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-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 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= @@ -201,14 +193,11 @@ golang.org/x/text v0.17.0 h1:XtiM5bkSOt+ewxlOE/aE/AKEHibwj/6gvWMl9Rsh0Qc= golang.org/x/text v0.17.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY= 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= -golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d h1:vU5i/LfpvrRCpgM/VPfJLg5KjxD3E+hfT1SH+d9zLwg= golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d/go.mod h1:aiJjzUbINMkxbQROHiO6hDPo2LHcIPhhQsa9DLh0yGk= 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= -golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= google.golang.org/appengine v1.6.8 h1:IhEN5q69dyKagZPYMSdIjS2HqprW324FRQZJcGqPAsM= google.golang.org/appengine v1.6.8/go.mod h1:1jJ3jBArFh5pcgW8gCtRJnepW8FzD1V44FJffLiz/Ds= diff --git a/pkg/config-api-provider/provider/resources/agent.go b/pkg/config-api-provider/provider/resources/agent.go index e3533278..a9538ab2 100644 --- a/pkg/config-api-provider/provider/resources/agent.go +++ b/pkg/config-api-provider/provider/resources/agent.go @@ -80,7 +80,7 @@ func (r *agentResource) Create(ctx context.Context, req resource.CreateRequest, // Retrieve values from plan var plan agentResourceModel diags := req.Plan.Get(ctx, &plan) - diags.AddError("operation not supported", "creating an agent resource is not supported; agents can only be imported") + diags.AddError("operation not supported", "creating an agent is not supported; agents can only be imported") resp.Diagnostics.Append(diags...) } @@ -137,7 +137,7 @@ func (r *agentResource) Delete(ctx context.Context, req resource.DeleteRequest, // Retrieve values from state var state agentResourceModel diags := req.State.Get(ctx, &state) - diags.AddError("operation not supported", "deleting an agent resource is not supported; agents can only removed from state") + diags.AddError("operation not supported", "deleting an agent is not supported; agents can only removed from state") resp.Diagnostics.Append(diags...) } diff --git a/pkg/config-api-provider/provider/resources/sensor.go b/pkg/config-api-provider/provider/resources/sensor.go index f095d9d1..bbc0a8fe 100644 --- a/pkg/config-api-provider/provider/resources/sensor.go +++ b/pkg/config-api-provider/provider/resources/sensor.go @@ -3,8 +3,7 @@ package resources import ( "context" - "time" - + // "github.com/aruba-uxi/configuration-api-terraform-provider/pkg/config-api-client" "github.com/hashicorp/terraform-plugin-framework/path" "github.com/hashicorp/terraform-plugin-framework/resource" "github.com/hashicorp/terraform-plugin-framework/resource/schema" @@ -25,10 +24,10 @@ type sensorResourceModel struct { AddressNote types.String `tfsdk:"address_note"` Notes types.String `tfsdk:"notes"` PCapMode types.String `tfsdk:"pcap_mode"` - LastUpdated types.String `tfsdk:"last_updated"` } -type sensorResponseModel struct { +// TODO: Switch this to use the Client Model when that becomes available +type SensorResponseModel struct { UID string Serial string Name string @@ -42,6 +41,14 @@ type sensorResponseModel struct { PCapMode string } +// TODO: Switch this to use the Client Model when that becomes available +type SensorUpdateRequestModel struct { + Name string + AddressNote string + Notes string + PCapMode string +} + func NewSensorResource() resource.Resource { return &sensorResource{} } @@ -61,9 +68,6 @@ func (r *sensorResource) Schema(_ context.Context, _ resource.SchemaRequest, res stringplanmodifier.UseStateForUnknown(), }, }, - "last_updated": schema.StringAttribute{ - Computed: true, - }, "name": schema.StringAttribute{ Required: true, }, @@ -81,13 +85,14 @@ func (r *sensorResource) Schema(_ context.Context, _ resource.SchemaRequest, res } func (r *sensorResource) Configure(_ context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) { + } func (r *sensorResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { // Retrieve values from plan var plan sensorResourceModel diags := req.Plan.Get(ctx, &plan) - diags.AddError("operation not supported", "creating a sensor resource is not supported; sensors can only be imported") + diags.AddError("operation not supported", "creating a sensor is not supported; sensors can only be imported") resp.Diagnostics.Append(diags...) } @@ -100,8 +105,6 @@ func (r *sensorResource) Read(ctx context.Context, req resource.ReadRequest, res return } - // TODO: Call client create-sensor method - // We are mocking the response of the client for this early stage of development response := GetSensor() // Update state from client response @@ -109,7 +112,6 @@ func (r *sensorResource) Read(ctx context.Context, req resource.ReadRequest, res state.AddressNote = types.StringValue(response.AddressNote) state.Notes = types.StringValue(response.Notes) state.PCapMode = types.StringValue(response.PCapMode) - state.LastUpdated = types.StringValue(time.Now().Format(time.RFC850)) // Set refreshed state diags = resp.State.Set(ctx, &state) @@ -128,10 +130,19 @@ func (r *sensorResource) Update(ctx context.Context, req resource.UpdateRequest, return } - // TODO: Call client update-sensor method + // Update existing order + response := UpdateSensor(SensorUpdateRequestModel{ + Name: plan.Name.ValueString(), + AddressNote: plan.AddressNote.ValueString(), + Notes: plan.Notes.ValueString(), + PCapMode: plan.PCapMode.ValueString(), + }) - // Update the state to match the plan (replace with response from client) - plan.LastUpdated = types.StringValue(time.Now().Format(time.RFC850)) + // Update resource state with updated items + plan.Name = types.StringValue(response.Name) + plan.AddressNote = types.StringValue(response.AddressNote) + plan.Notes = types.StringValue(response.Notes) + plan.PCapMode = types.StringValue(response.PCapMode) // Set state to fully populated data diags = resp.State.Set(ctx, plan) @@ -145,7 +156,7 @@ func (r *sensorResource) Delete(ctx context.Context, req resource.DeleteRequest, // Retrieve values from state var state sensorResourceModel diags := req.State.Get(ctx, &state) - diags.AddError("operation not supported", "deleting a sensor resource is not supported; sensors can only removed from state") + diags.AddError("operation not supported", "deleting a sensor is not supported; sensors can only removed from state") resp.Diagnostics.Append(diags...) } @@ -154,20 +165,39 @@ func (r *sensorResource) ImportState(ctx context.Context, req resource.ImportSta } // Get the sensor using the configuration-api client -func GetSensor() sensorResponseModel { +var GetSensor = func() SensorResponseModel { + // TODO: Query the sensor using the client + + return SensorResponseModel{ + UID: "mock_uid", + Serial: "mock_serial", + Name: "mock_name", + ModelNumber: "mock_model_number", + WifiMacAddress: "mock_wifi_mac_address", + EthernetMacAddress: "mock_ethernet_mac_address", + AddressNote: "mock_address_note", + Longitude: "mock_longitude", + Latitude: "mock_latitude", + Notes: "mock_notes", + PCapMode: "mock_pcap_mode", + } +} + +// Update the sensor using the configuration-api client +var UpdateSensor = func(request SensorUpdateRequestModel) SensorResponseModel { // TODO: Query the sensor using the client - return sensorResponseModel{ - UID: "temporary_uid", - Serial: "temporary_serial", - Name: "temporary_name", - ModelNumber: "temporary_model_number", - WifiMacAddress: "temporary_wifi_mac_address", - EthernetMacAddress: "temporary_ethernet_mac_address", - AddressNote: "temporary_address_note", - Longitude: "temporary_longitude", - Latitude: "temporary_latitude", - Notes: "temporary_notes", - PCapMode: "temporary_pcap_mode", + return SensorResponseModel{ + UID: "mock_uid", + Serial: "mock_serial", + Name: request.Name, + ModelNumber: "mock_model_number", + WifiMacAddress: "mock_wifi_mac_address", + EthernetMacAddress: "mock_ethernet_mac_address", + AddressNote: request.AddressNote, + Longitude: "mock_longitude", + Latitude: "mock_latitude", + Notes: request.Notes, + PCapMode: request.PCapMode, } } diff --git a/pkg/config-api-provider/test/sensor_test.go b/pkg/config-api-provider/test/sensor_test.go new file mode 100644 index 00000000..5eb90ab6 --- /dev/null +++ b/pkg/config-api-provider/test/sensor_test.go @@ -0,0 +1,132 @@ +package test + +import ( + "regexp" + "testing" + + "github.com/aruba-uxi/configuration-api-terraform-provider/pkg/terraform-provider-configuration/provider/resources" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/tfversion" +) + +func TestSensorResource(t *testing.T) { + + resource.Test(t, resource.TestCase{ + ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, + TerraformVersionChecks: []tfversion.TerraformVersionCheck{ + // we required terraform 1.7.0 and above for the `removed` block + tfversion.RequireAbove(tfversion.Version1_7_0), + }, + Steps: []resource.TestStep{ + // Creating a sensor is not allowed + { + Config: providerConfig + ` + resource "uxi_sensor" "my_sensor" { + name = "name" + address_note = "address_note" + notes = "note" + pcap_mode = "light" + }`, + + ExpectError: regexp.MustCompile(`creating a sensor is not supported; sensors can only be imported`), + }, + // Importing a sensor + { + PreConfig: func() { + resources.GetSensor = func() resources.SensorResponseModel { + return resources.SensorResponseModel{ + UID: "uid", + Serial: "serial", + Name: "imported_name", + ModelNumber: "model_number", + WifiMacAddress: "wifi_mac_address", + EthernetMacAddress: "ethernet_mac_address", + AddressNote: "imported_address_note", + Longitude: "imported_longitude", + Latitude: "imported_latitude", + Notes: "imported_notes", + PCapMode: "light", + } + } + }, + Config: providerConfig + ` + resource "uxi_sensor" "my_sensor" { + name = "imported_name" + address_note = "imported_address_note" + notes = "imported_notes" + pcap_mode = "light" + } + + import { + to = uxi_sensor.my_sensor + id = "test_uid" + }`, + + Check: resource.ComposeAggregateTestCheckFunc( + // Verify first order item updated + resource.TestCheckResourceAttr("uxi_sensor.my_sensor", "name", "imported_name"), + resource.TestCheckResourceAttr("uxi_sensor.my_sensor", "address_note", "imported_address_note"), + resource.TestCheckResourceAttr("uxi_sensor.my_sensor", "notes", "imported_notes"), + resource.TestCheckResourceAttr("uxi_sensor.my_sensor", "pcap_mode", "light"), + // Verify first coffee item has Computed attributes updated. + resource.TestCheckResourceAttr("uxi_sensor.my_sensor", "id", "test_uid"), + ), + }, + // ImportState testing + { + ResourceName: "uxi_sensor.my_sensor", + ImportState: true, + ImportStateVerify: true, + }, + // Update and Read testing + { + PreConfig: func() { + resources.GetSensor = func() resources.SensorResponseModel { + return resources.SensorResponseModel{ + UID: "uid", + Serial: "serial", + Name: "updated_name", + ModelNumber: "model_number", + WifiMacAddress: "wifi_mac_address", + EthernetMacAddress: "ethernet_mac_address", + AddressNote: "updated_address_note", + Longitude: "updated_longitude", + Latitude: "updated_latitude", + Notes: "updated_notes", + PCapMode: "not_light", + } + } + }, + Config: providerConfig + ` + resource "uxi_sensor" "my_sensor" { + name = "updated_name" + address_note = "updated_address_note" + notes = "updated_notes" + pcap_mode = "not_light" + }`, + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("uxi_sensor.my_sensor", "name", "updated_name"), + resource.TestCheckResourceAttr("uxi_sensor.my_sensor", "address_note", "updated_address_note"), + resource.TestCheckResourceAttr("uxi_sensor.my_sensor", "notes", "updated_notes"), + resource.TestCheckResourceAttr("uxi_sensor.my_sensor", "pcap_mode", "not_light"), + ), + }, + // Deleting a sensor is not allowed + { + Config: providerConfig + ``, + ExpectError: regexp.MustCompile(`deleting a sensor is not supported; sensors can only removed from state`), + }, + // Remove sensor from state + { + Config: providerConfig + ` + removed { + from = uxi_sensor.my_sensor + + lifecycle { + destroy = false + } + }`, + }, + }, + }) +} From 02676fd2fbbcaadbf48f34a1de47893b813f63f4 Mon Sep 17 00:00:00 2001 From: 1riatsila1 Date: Thu, 22 Aug 2024 17:07:13 +0200 Subject: [PATCH 4/7] add the agent code too --- .../provider/resources/agent.go | 79 ++++++++---- pkg/config-api-provider/test/agent_test.go | 121 ++++++++++++++++++ 2 files changed, 173 insertions(+), 27 deletions(-) create mode 100644 pkg/config-api-provider/test/agent_test.go diff --git a/pkg/config-api-provider/provider/resources/agent.go b/pkg/config-api-provider/provider/resources/agent.go index a9538ab2..be4e2e13 100644 --- a/pkg/config-api-provider/provider/resources/agent.go +++ b/pkg/config-api-provider/provider/resources/agent.go @@ -3,8 +3,7 @@ package resources import ( "context" - "time" - + // "github.com/aruba-uxi/configuration-api-terraform-provider/pkg/config-api-client" "github.com/hashicorp/terraform-plugin-framework/path" "github.com/hashicorp/terraform-plugin-framework/resource" "github.com/hashicorp/terraform-plugin-framework/resource/schema" @@ -20,15 +19,15 @@ var ( ) type agentResourceModel struct { - ID types.String `tfsdk:"id"` - Name types.String `tfsdk:"name"` - Notes types.String `tfsdk:"notes"` - PCapMode types.String `tfsdk:"pcap_mode"` - LastUpdated types.String `tfsdk:"last_updated"` + ID types.String `tfsdk:"id"` + Name types.String `tfsdk:"name"` + Notes types.String `tfsdk:"notes"` + PCapMode types.String `tfsdk:"pcap_mode"` } -type agentResponseModel struct { - Uid string +// TODO: Switch this to use the Client Model when that becomes available +type AgentResponseModel struct { + UID string Serial string Name string ModelNumber string @@ -38,6 +37,13 @@ type agentResponseModel struct { PCapMode string } +// TODO: Switch this to use the Client Model when that becomes available +type AgentUpdateRequestModel struct { + Name string + Notes string + PCapMode string +} + func NewAgentResource() resource.Resource { return &agentResource{} } @@ -57,9 +63,6 @@ func (r *agentResource) Schema(_ context.Context, _ resource.SchemaRequest, resp stringplanmodifier.UseStateForUnknown(), }, }, - "last_updated": schema.StringAttribute{ - Computed: true, - }, "name": schema.StringAttribute{ Required: true, }, @@ -74,6 +77,7 @@ func (r *agentResource) Schema(_ context.Context, _ resource.SchemaRequest, resp } func (r *agentResource) Configure(_ context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) { + } func (r *agentResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { @@ -93,15 +97,12 @@ func (r *agentResource) Read(ctx context.Context, req resource.ReadRequest, resp return } - // TODO: Call client create-agent method - // We are mocking the response of the client for this early stage of development response := GetAgent() // Update state from client response state.Name = types.StringValue(response.Name) state.Notes = types.StringValue(response.Notes) state.PCapMode = types.StringValue(response.PCapMode) - state.LastUpdated = types.StringValue(time.Now().Format(time.RFC850)) // Set refreshed state diags = resp.State.Set(ctx, &state) @@ -120,10 +121,17 @@ func (r *agentResource) Update(ctx context.Context, req resource.UpdateRequest, return } - // TODO: Call client update-agent method + // Update existing order + response := UpdateAgent(AgentUpdateRequestModel{ + Name: plan.Name.ValueString(), + Notes: plan.Notes.ValueString(), + PCapMode: plan.PCapMode.ValueString(), + }) - // Update the state to match the plan (replace with response from client) - plan.LastUpdated = types.StringValue(time.Now().Format(time.RFC850)) + // Update resource state with updated items + plan.Name = types.StringValue(response.Name) + plan.Notes = types.StringValue(response.Notes) + plan.PCapMode = types.StringValue(response.PCapMode) // Set state to fully populated data diags = resp.State.Set(ctx, plan) @@ -146,16 +154,33 @@ func (r *agentResource) ImportState(ctx context.Context, req resource.ImportStat } // Get the agent using the configuration-api client -func GetAgent() agentResponseModel { +var GetAgent = func() AgentResponseModel { + // TODO: Query the agent using the client + + return AgentResponseModel{ + UID: "mock_uid", + Serial: "mock_serial", + Name: "mock_name", + ModelNumber: "mock_model_number", + WifiMacAddress: "mock_wifi_mac_address", + EthernetMacAddress: "mock_ethernet_mac_address", + Notes: "mock_notes", + PCapMode: "mock_pcap_mode", + } +} + +// Update the agent using the configuration-api client +var UpdateAgent = func(request AgentUpdateRequestModel) AgentResponseModel { // TODO: Query the agent using the client - return agentResponseModel{ - Serial: "temporary_serial", - Name: "temporary_name", - ModelNumber: "temporary_model_number", - WifiMacAddress: "temporary_wifi_mac_address", - EthernetMacAddress: "temporary_ethernet_mac_address", - Notes: "temporary_notes", - PCapMode: "temporary_pcap_mode", + return AgentResponseModel{ + UID: "mock_uid", + Serial: "mock_serial", + Name: request.Name, + ModelNumber: "mock_model_number", + WifiMacAddress: "mock_wifi_mac_address", + EthernetMacAddress: "mock_ethernet_mac_address", + Notes: request.Notes, + PCapMode: request.PCapMode, } } diff --git a/pkg/config-api-provider/test/agent_test.go b/pkg/config-api-provider/test/agent_test.go new file mode 100644 index 00000000..7a9fdcd9 --- /dev/null +++ b/pkg/config-api-provider/test/agent_test.go @@ -0,0 +1,121 @@ +package test + +import ( + "regexp" + "testing" + + "github.com/aruba-uxi/configuration-api-terraform-provider/pkg/terraform-provider-configuration/provider/resources" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/tfversion" +) + +func TestAgentResource(t *testing.T) { + + resource.Test(t, resource.TestCase{ + ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, + TerraformVersionChecks: []tfversion.TerraformVersionCheck{ + // we required terraform 1.7.0 and above for the `removed` block + tfversion.RequireAbove(tfversion.Version1_7_0), + }, + Steps: []resource.TestStep{ + // Creating an agent is not allowed + { + Config: providerConfig + ` + resource "uxi_agent" "my_agent" { + name = "name" + notes = "note" + pcap_mode = "light" + }`, + + ExpectError: regexp.MustCompile(`creating an agent is not supported; agents can only be imported`), + }, + // Importing an agent + { + PreConfig: func() { + resources.GetAgent = func() resources.AgentResponseModel { + return resources.AgentResponseModel{ + UID: "uid", + Serial: "serial", + Name: "imported_name", + ModelNumber: "model_number", + WifiMacAddress: "wifi_mac_address", + EthernetMacAddress: "ethernet_mac_address", + Notes: "imported_notes", + PCapMode: "light", + } + } + }, + Config: providerConfig + ` + resource "uxi_agent" "my_agent" { + name = "imported_name" + notes = "imported_notes" + pcap_mode = "light" + } + + import { + to = uxi_agent.my_agent + id = "test_uid" + }`, + + Check: resource.ComposeAggregateTestCheckFunc( + // Verify first order item updated + resource.TestCheckResourceAttr("uxi_agent.my_agent", "name", "imported_name"), + resource.TestCheckResourceAttr("uxi_agent.my_agent", "notes", "imported_notes"), + resource.TestCheckResourceAttr("uxi_agent.my_agent", "pcap_mode", "light"), + // Verify first coffee item has Computed attributes updated. + resource.TestCheckResourceAttr("uxi_agent.my_agent", "id", "test_uid"), + ), + }, + // ImportState testing + { + ResourceName: "uxi_agent.my_agent", + ImportState: true, + ImportStateVerify: true, + }, + // Update and Read testing + { + PreConfig: func() { + resources.GetAgent = func() resources.AgentResponseModel { + return resources.AgentResponseModel{ + UID: "uid", + Serial: "serial", + Name: "updated_name", + ModelNumber: "model_number", + WifiMacAddress: "wifi_mac_address", + EthernetMacAddress: "ethernet_mac_address", + Notes: "updated_notes", + PCapMode: "not_light", + } + } + }, + Config: providerConfig + ` + resource "uxi_agent" "my_agent" { + name = "updated_name" + notes = "updated_notes" + pcap_mode = "not_light" + }`, + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("uxi_agent.my_agent", "name", "updated_name"), + resource.TestCheckResourceAttr("uxi_agent.my_agent", "notes", "updated_notes"), + resource.TestCheckResourceAttr("uxi_agent.my_agent", "pcap_mode", "not_light"), + ), + }, + // Deleting an agent is not allowed + { + Config: providerConfig + ``, + ExpectError: regexp.MustCompile(`deleting an agent is not supported; agents can only removed from state`), + }, + // Remove agent from state + { + Config: providerConfig + ` + removed { + from = uxi_agent.my_agent + + lifecycle { + destroy = false + } + }`, + }, + }, + }) +} From 06a22139e862c664b07da9b04cad10cc7101c8f3 Mon Sep 17 00:00:00 2001 From: 1riatsila1 Date: Thu, 22 Aug 2024 17:12:49 +0200 Subject: [PATCH 5/7] Align test cases with mock data --- Justfile | 12 ++++++++++++ pkg/config-api-provider/test/group_test.go | 8 ++++---- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/Justfile b/Justfile index 4e1e74e7..46f3f3aa 100644 --- a/Justfile +++ b/Justfile @@ -59,11 +59,22 @@ lint-provider: golangci-lint run +fmt-provider: + gofmt -w pkg/config-api-provider + +test-provider: + cd {{ CONFIG_API_PROVIDER_DIR }} && TF_ACC=1 go test -v ./test/... -race -covermode=atomic -coverprofile=.coverage + +coverage-provider: + cd {{ CONFIG_API_PROVIDER_DIR }} && go tool cover -html=.coverage -o=.coverage.html + test: just test-client + just test-provider coverage: just coverage-client + coverage-provider lint: just lint-client @@ -71,6 +82,7 @@ lint: fmt: just fmt-client + just fmt-provider clean: find . -name ".coverage*" -type f -delete diff --git a/pkg/config-api-provider/test/group_test.go b/pkg/config-api-provider/test/group_test.go index 4900f8cd..d192e7f6 100644 --- a/pkg/config-api-provider/test/group_test.go +++ b/pkg/config-api-provider/test/group_test.go @@ -13,8 +13,8 @@ type Fetcher interface { func TestGroupResource(t *testing.T) { createGroupConfig := ` resource "uxi_group" "test_group" { - name = "test_name" - parent_uid = "9999" + name = "temporary_name" + parent_uid = "temporary_parent_uid" }` resource.Test(t, resource.TestCase{ @@ -24,8 +24,8 @@ func TestGroupResource(t *testing.T) { { Config: providerConfig + createGroupConfig, Check: resource.ComposeAggregateTestCheckFunc( - resource.TestCheckResourceAttr("uxi_group.test_group", "name", "test_name"), - resource.TestCheckResourceAttr("uxi_group.test_group", "parent_uid", "9999"), + resource.TestCheckResourceAttr("uxi_group.test_group", "name", "temporary_name"), + resource.TestCheckResourceAttr("uxi_group.test_group", "parent_uid", "temporary_parent_uid"), resource.TestCheckResourceAttrSet("uxi_group.test_group", "id"), resource.TestCheckResourceAttrSet("uxi_group.test_group", "last_updated"), ), From 98506236419b8f08170ecf00fde0db466578d8b3 Mon Sep 17 00:00:00 2001 From: 1riatsila1 Date: Thu, 22 Aug 2024 17:18:47 +0200 Subject: [PATCH 6/7] Fix Justfile --- Justfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Justfile b/Justfile index 46f3f3aa..a80c8035 100644 --- a/Justfile +++ b/Justfile @@ -63,7 +63,7 @@ fmt-provider: gofmt -w pkg/config-api-provider test-provider: - cd {{ CONFIG_API_PROVIDER_DIR }} && TF_ACC=1 go test -v ./test/... -race -covermode=atomic -coverprofile=.coverage + cd {{ CONFIG_API_PROVIDER_DIR }} && TF_ACC=1 go test -v ./... -race -covermode=atomic -coverprofile=.coverage coverage-provider: cd {{ CONFIG_API_PROVIDER_DIR }} && go tool cover -html=.coverage -o=.coverage.html @@ -74,7 +74,7 @@ test: coverage: just coverage-client - coverage-provider + just coverage-provider lint: just lint-client From 51ade02ed7dde4bd8c70b49e318f297241a6f0c5 Mon Sep 17 00:00:00 2001 From: 1riatsila1 Date: Fri, 23 Aug 2024 10:58:58 +0200 Subject: [PATCH 7/7] Deleting agents is allowed --- .../provider/resources/agent.go | 7 ++++++- pkg/config-api-provider/test/agent_test.go | 17 +---------------- 2 files changed, 7 insertions(+), 17 deletions(-) diff --git a/pkg/config-api-provider/provider/resources/agent.go b/pkg/config-api-provider/provider/resources/agent.go index be4e2e13..9565ecb2 100644 --- a/pkg/config-api-provider/provider/resources/agent.go +++ b/pkg/config-api-provider/provider/resources/agent.go @@ -145,8 +145,13 @@ func (r *agentResource) Delete(ctx context.Context, req resource.DeleteRequest, // Retrieve values from state var state agentResourceModel diags := req.State.Get(ctx, &state) - diags.AddError("operation not supported", "deleting an agent is not supported; agents can only removed from state") resp.Diagnostics.Append(diags...) + if resp.Diagnostics.HasError() { + return + } + + // Delete existing agent using client here + // err := r.client.DeleteOrder(state.ID.ValueString()) } func (r *agentResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { diff --git a/pkg/config-api-provider/test/agent_test.go b/pkg/config-api-provider/test/agent_test.go index 7a9fdcd9..290f67af 100644 --- a/pkg/config-api-provider/test/agent_test.go +++ b/pkg/config-api-provider/test/agent_test.go @@ -100,22 +100,7 @@ func TestAgentResource(t *testing.T) { resource.TestCheckResourceAttr("uxi_agent.my_agent", "pcap_mode", "not_light"), ), }, - // Deleting an agent is not allowed - { - Config: providerConfig + ``, - ExpectError: regexp.MustCompile(`deleting an agent is not supported; agents can only removed from state`), - }, - // Remove agent from state - { - Config: providerConfig + ` - removed { - from = uxi_agent.my_agent - - lifecycle { - destroy = false - } - }`, - }, + // Delete testing automatically occurs in TestCase }, }) }