Yohan460 / terraform-provider-jamf

Other
14 stars 10 forks source link

Assign computers to jamf_staticComputerGroups with serial_number or id + half a fix for jamf_computerExtensionAttribute tests #21

Open w0de opened 4 months ago

w0de commented 4 months ago

Changes:

The example in docs seems to imply that serial number may be used to assign a computer:

resource "jamf_staticComputerGroup" "test_static_1" {
  computer {
    id = 1
  }
  computer {
    serial_number = "C06X4489JFD3"
  }
  name = "Test Static 1"
}

However, it's presently a computed value. Only the Jamf computer object's ID may be used. This change allows the use of serial number.

I rolled custom validation in this func b/c: https://github.com/hashicorp/terraform-plugin-sdk/issues/644

There are two other bugs in jamf/resource_jamf_computer_extension_attribute_test.go, though I may just be holding it wrong. On the first run, this occurs:

panic: script: '': source data must be an array or slice, got map

goroutine 188 [running]:
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*ResourceData).Set(0x140005a5000, {0x100dd0abb, 0x6}, {0x10105afc0, 0x140000a86c0})
    /Users/w0de/go/pkg/mod/github.com/hashicorp/terraform-plugin-sdk/v2@v2.4.3/helper/schema/resource_data.go:230 +0x24c
github.com/yohan460/terraform-provider-jamf/jamf.deconstructJamfComputerExtensionAttributeStruct(0x100e10ba9?, 0x1400054db80)
    /Users/w0de/src/terraform-provider-jamf/jamf/data_source_jamf_computer_extension_attribute.go:154 +0x4c4
github.com/yohan460/terraform-provider-jamf/jamf.resourceJamfComputerExtensionAttributeRead({0x140005a5000?, 0x100e10ba9?}, 0x140005a5000, {0x10117a720?, 0x14000304480})
    /Users/w0de/src/terraform-provider-jamf/jamf/resource_jamf_computer_extension_attribute.go:240 +0x19c
github.com/yohan460/terraform-provider-jamf/jamf.resourceJamfComputerExtensionAttributeCreate({0x10118f998, 0x140006fab60}, 0x0?, {0x10117a720?, 0x14000304480?})
    /Users/w0de/src/terraform-provider-jamf/jamf/resource_jamf_computer_extension_attribute.go:223 +0x158
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).create(0x140000fd5c0, {0x10118f928, 0x14000543630}, 0x2?, {0x10117a720, 0x14000304480})
    /Users/w0de/go/pkg/mod/github.com/hashicorp/terraform-plugin-sdk/v2@v2.4.3/helper/schema/resource.go:285 +0x154
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).Apply(0x140000fd5c0, {0x10118f928, 0x14000543630}, 0x140006fa4d0, 0x14000780500, {0x10117a720, 0x14000304480})
    /Users/w0de/go/pkg/mod/github.com/hashicorp/terraform-plugin-sdk/v2@v2.4.3/helper/schema/resource.go:396 +0x674
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*GRPCProviderServer).ApplyResourceChange(0x1400053c318, {0x10118f928, 0x14000543630}, 0x14000543680)
    /Users/w0de/go/pkg/mod/github.com/hashicorp/terraform-plugin-sdk/v2@v2.4.3/helper/schema/grpc_provider.go:955 +0x82c
github.com/hashicorp/terraform-plugin-go/tfprotov5/server.(*server).ApplyResourceChange(0x14000568b80, {0x10118f8f0?, 0x1400059eb70?}, 0x0?)
    /Users/w0de/go/pkg/mod/github.com/hashicorp/terraform-plugin-go@v0.2.1/tfprotov5/server/server.go:332 +0x64
github.com/hashicorp/terraform-plugin-go/tfprotov5/internal/tfplugin5._Provider_ApplyResourceChange_Handler({0x101140bc0?, 0x14000568b80}, {0x10118f8f0, 0x1400059eb70}, 0x140004d4660, 0x0)
    /Users/w0de/go/pkg/mod/github.com/hashicorp/terraform-plugin-go@v0.2.1/tfprotov5/internal/tfplugin5/tfplugin5_grpc.pb.go:380 +0x164
google.golang.org/grpc.(*Server).processUnaryRPC(0x14000478000, {0x101193f90, 0x140001fc780}, 0x1400040a300, 0x1400055f260, 0x101745a60, 0x0)
    /Users/w0de/go/pkg/mod/google.golang.org/grpc@v1.35.0/server.go:1217 +0xa58
google.golang.org/grpc.(*Server).handleStream(0x14000478000, {0x101193f90, 0x140001fc780}, 0x1400040a300, 0x0)
    /Users/w0de/go/pkg/mod/google.golang.org/grpc@v1.35.0/server.go:1540 +0x7c4
google.golang.org/grpc.(*Server).serveStreams.func1.2()
    /Users/w0de/go/pkg/mod/google.golang.org/grpc@v1.35.0/server.go:878 +0x84
created by google.golang.org/grpc.(*Server).serveStreams.func1 in goroutine 184
    /Users/w0de/go/pkg/mod/google.golang.org/grpc@v1.35.0/server.go:876 +0x24c
FAIL    github.com/yohan460/terraform-provider-jamf/jamf    1.882s
FAIL
make: *** [testacc] Error 1

I'm not sure how to fix this yet. If its not just my mistake, lmk, I'll open an issue.

On a subsequent run, the test fails because the prior test did succeed in creating an extension attribute - but didn't destroy it. Jamf API returns a duplicate name error:

==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./jamf -v -count 1 -parallel 20 -run TestAccJamfComputerExtensionAttribute_basic -timeout 120m
=== RUN   TestAccJamfComputerExtensionAttribute_basic
=== PAUSE TestAccJamfComputerExtensionAttribute_basic
=== CONT  TestAccJamfComputerExtensionAttribute_basic
    resource_jamf_computer_extension_attribute_test.go:12: Step 1/3 error: Error running apply: exit status 1

        Error: API Error: 409 URI: /JSSResource/computerextensionattributes/id/0 Body: <html> <head>    <title>Status page</title> </head> <body style="font-family: sans-serif;"> <p style="font-size: 1.2em;font-weight: bold;margin: 1em 0px;">Conflict</p> <p>Error: Duplicate name</p> <p>You can get technical details <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.4.10">here</a>.<br> Please continue your visit at our <a href="/">home page</a>. </p> </body> </html>

--- FAIL: TestAccJamfComputerExtensionAttribute_basic (1.34s)
FAIL
FAIL    github.com/yohan460/terraform-provider-jamf/jamf    1.619s
FAIL
make: *** [testacc] Error 1