Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect quoting and format for custom_attributes #158

Open
AndyDLP opened this issue Sep 14, 2022 · 2 comments
Open

Incorrect quoting and format for custom_attributes #158

AndyDLP opened this issue Sep 14, 2022 · 2 comments
Labels
bug Something isn't working

Comments

@AndyDLP
Copy link

AndyDLP commented Sep 14, 2022

Terraform Version and Provider Version

Terraform v1.2.7 on windows_amd64

provider registry.terraform.io/hashicorp/ad v0.4.4

Windows Version

Running TF: Windows 10 (v10.0.19044)
winrm_hostname: Server 2019 (v10.0.17763)
domain controller: Server 2019 (v10.0.17763)

Affected Resource(s)

ad_user

Terraform Configuration Files

EXAMPLE 1

Defining a simple user

resource "ad_user" "user" {
    principal_name   = "[email protected]"
    sam_account_name = "test_account"
    display_name     = "test_account"
}

then adding a custom_attributes property after applying, then reapply (so modify operation, not new)

    custom_attributes = jsonencode({ msDS-SupportedEncryptionTypes = 28 })

EXAMPLE 2

Define a new user with custom_attributes "msDS-SupportedEncryptionTypes" as NUMBER

resource "ad_user" "user" {
    principal_name   = "[email protected]"
    sam_account_name = "test_account"
    display_name     = "test_account"
    custom_attributes = jsonencode({ msDS-SupportedEncryptionTypes = 28 })
}

EXAMPLE 3

Define a new user with custom_attributes "msDS-SupportedEncryptionTypes" as STRING

resource "ad_user" "user" {
    principal_name   = "[email protected]"
    sam_account_name = "test_account"
    display_name     = "test_account"
    custom_attributes = jsonencode({ msDS-SupportedEncryptionTypes = "28"})
}

Debug Output

EXAMPLE 1: doesn't panic, but fails with error "Missing '=' operator after key in hash literal"

cause = Invalid key name (PS hashtables can't have a hyphen - without quoting it), and invalid format, should just be integer.

[DEBUG] Constructing powerrshell command ... -Add @{msDS-SupportedEncryptionTypes="2.8E+01"}

EXAMPLE 2: panic, see below

EXAMPLE 3: Key is correctly quoted and creates successfully, but is automatically converted to number on the user, resulting in a change on next apply.

[DEBUG] Constructing powerrshell command ... -OtherAttributes @{'msDS-SupportedEncryptionTypes'="28"}

Next apply fails due to unquoted key name (cant have - in name without quotes), and double quoted string for value isn't valid

[DEBUG] Constructing powerrshell command ... -Replace @{msDS-SupportedEncryptionTypes=""28""}

Panic Output

EXAMPLE 2:

Stack trace from the terraform-provider-ad_v0.4.4_x5.exe plugin:

panic: interface conversion: interface {} is float64, not string

goroutine 28 [running]:
github.com/hashicorp/terraform-provider-ad/ad/internal/winrmhelper.(*User).getOtherAttributes(0xa88c70?)
        /opt/teamcity-agent/work/5d79fe75d4460a2f/src/github.com/hashicorp/terraform-provider-ad/ad/internal/winrmhelper/winrm_user.go:494 +0x3d5
github.com/hashicorp/terraform-provider-ad/ad/internal/winrmhelper.(*User).NewUser(0xc000504c80, 0xc00048ed00)
        /opt/teamcity-agent/work/5d79fe75d4460a2f/src/github.com/hashicorp/terraform-provider-ad/ad/internal/winrmhelper/winrm_user.go:210 +0x28e5
github.com/hashicorp/terraform-provider-ad/ad.resourceADUserCreate(0x0?, {0xa10ae0?, 0xc00048ed00})
        /opt/teamcity-agent/work/5d79fe75d4460a2f/src/github.com/hashicorp/terraform-provider-ad/ad/resource_ad_user.go:266 +0xbb
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).create(0xbcd570?, {0xbcd570?, 0xc0000b93b0?}, 0xd?, {0xa10ae0?, 0xc00048ed00?})
        /opt/teamcity-agent/work/5d79fe75d4460a2f/src/github.com/hashicorp/terraform-provider-ad/vendor/github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema/resource.go:330 +0x178
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).Apply(0xc00029d6c0, {0xbcd570, 0xc0000b93b0}, 0xc000214d00, 0xc0004c7880, {0xa10ae0, 0xc00048ed00})
        /opt/teamcity-agent/work/5d79fe75d4460a2f/src/github.com/hashicorp/terraform-provider-ad/vendor/github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema/resource.go:472 +0x83a
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*GRPCProviderServer).ApplyResourceChange(0xc000293a40, {0xbcd4c8?, 0xc00021a9c0?}, 0xc00049ea50)
        /opt/teamcity-agent/work/5d79fe75d4460a2f/src/github.com/hashicorp/terraform-provider-ad/vendor/github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema/grpc_provider.go:1021 +0xdaa
github.com/hashicorp/terraform-plugin-go/tfprotov5/tf5server.(*server).ApplyResourceChange(0xc000323360, {0xbcd570?, 0xc0000b8b10?}, 0xc0001aa930)
        /opt/teamcity-agent/work/5d79fe75d4460a2f/src/github.com/hashicorp/terraform-provider-ad/vendor/github.com/hashicorp/terraform-plugin-go/tfprotov5/tf5server/server.go:812 +0x515
github.com/hashicorp/terraform-plugin-go/tfprotov5/internal/tfplugin5._Provider_ApplyResourceChange_Handler({0xa501e0?, 0xc000323360}, {0xbcd570, 0xc0000b8b10}, 0xc00008e4e0, 0x0)
        /opt/teamcity-agent/work/5d79fe75d4460a2f/src/github.com/hashicorp/terraform-provider-ad/vendor/github.com/hashicorp/terraform-plugin-go/tfprotov5/internal/tfplugin5/tfplugin5_grpc.pb.go:385 +0x170
google.golang.org/grpc.(*Server).processUnaryRPC(0xc0002ae700, {0xbd03a0, 0xc00019b1e0}, 0xc000336000, 0xc0003f1ce0, 0x11615e0, 0x0)
        /opt/teamcity-agent/work/5d79fe75d4460a2f/src/github.com/hashicorp/terraform-provider-ad/vendor/google.golang.org/grpc/server.go:1282 +0xccf
google.golang.org/grpc.(*Server).handleStream(0xc0002ae700, {0xbd03a0, 0xc00019b1e0}, 0xc000336000, 0x0)
        /opt/teamcity-agent/work/5d79fe75d4460a2f/src/github.com/hashicorp/terraform-provider-ad/vendor/google.golang.org/grpc/server.go:1619 +0xa1b
google.golang.org/grpc.(*Server).serveStreams.func1.2()
        /opt/teamcity-agent/work/5d79fe75d4460a2f/src/github.com/hashicorp/terraform-provider-ad/vendor/google.golang.org/grpc/server.go:921 +0x98
created by google.golang.org/grpc.(*Server).serveStreams.func1
        /opt/teamcity-agent/work/5d79fe75d4460a2f/src/github.com/hashicorp/terraform-provider-ad/vendor/google.golang.org/grpc/server.go:919 +0x28a

Error: The terraform-provider-ad_v0.4.4_x5.exe plugin crashed!

Expected Behavior

Set msDS-SupportedEncryptionTypes attribute on user to expected integer value (/or hex, it's a bitmask)

Actual Behavior

Errors as shown above

Steps to Reproduce

Terraform apply as above

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment
@AndyDLP AndyDLP added the bug Something isn't working label Sep 14, 2022
@wehrleSchuler
Copy link

@AndyDLP Dou you find an workaround for this?

@ben-ruset
Copy link

This is failing in the same exact way for me when trying to set uidNumber and gidNumber attributes for a user.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants