hashicorp / terraform-provider-ad

Active Directory provider for HashiCorp Terraform (experimental)
https://registry.terraform.io/providers/hashicorp/ad/latest
Mozilla Public License 2.0
140 stars 72 forks source link

[Resource ad_computer] Provider produced inconsistent result after appl #125

Open hshmilov opened 3 years ago

hshmilov commented 3 years ago

Terraform version: 1.0.3 / terraform-provider-ad_v0.4.3_x5 apply new AD Host(s) ( using double hop authN ) result with :

Error: Provider produced inconsistent result after apply When applying changes to ad_computer.AxonHost[1], provider "provider[\"registry.terraform.io/hashicorp/ad\"]" produced an unexpected new value: Root resource was present, but now absent.

This is a bug in the provider, which should be reported in the provider's own issue tracker.

do note all host created successfully on AD . it looks as someting related to post verification with state

creating a single ad host will succeed most of the time.

Terraform Configuration Files

variable "generate" { default = 2 }

resource "ad_computer" "AxonHost" { count = var.generate name = "AXON-${count.index}" description = "AXON HOST ${count.index}" container = "OU=Computers,OU=hanan-domain-2,DC=hanan-domain-2,DC=axonius,DC=test" pre2kname = "AXON${count.index}$" }



### Debug Output

2021-08-16T18:52:05.253+0300 [DEBUG] Adding temp file log sink: /var/folders/8z/03m43xln1p93n9fydl9k94f80000gn/T/terraform-log098716626
2021-08-16T18:52:05.253+0300 [INFO]  Terraform version: 1.0.3
2021-08-16T18:52:05.253+0300 [INFO]  Go runtime version: go1.16.4
2021-08-16T18:52:05.253+0300 [INFO]  CLI args: []string{"/usr/local/bin/terraform", "apply", "-auto-approve"}
2021-08-16T18:52:05.254+0300 [DEBUG] Attempting to open CLI config file: /Users/hanan/.terraformrc
2021-08-16T18:52:05.254+0300 [DEBUG] File doesn't exist, but doesn't need to. Ignoring.
2021-08-16T18:52:05.256+0300 [DEBUG] ignoring non-existing provider search directory terraform.d/plugins
2021-08-16T18:52:05.256+0300 [DEBUG] ignoring non-existing provider search directory /Users/hanan/.terraform.d/plugins
2021-08-16T18:52:05.256+0300 [DEBUG] ignoring non-existing provider search directory /Users/hanan/Library/Application Support/io.terraform/plugins
2021-08-16T18:52:05.256+0300 [DEBUG] ignoring non-existing provider search directory /Library/Application Support/io.terraform/plugins
2021-08-16T18:52:05.258+0300 [INFO]  CLI command args: []string{"apply", "-auto-approve"}
2021-08-16T18:52:05.267+0300 [DEBUG] New state was assigned lineage "76854580-7cb7-2274-a93c-7bb09f763fc4"
2021-08-16T18:52:05.322+0300 [DEBUG] checking for provisioner in "."
2021-08-16T18:52:05.325+0300 [DEBUG] checking for provisioner in "/usr/local/bin"
2021-08-16T18:52:05.326+0300 [INFO]  Failed to read plugin lock file .terraform/plugins/darwin_amd64/lock.json: open .terraform/plugins/darwin_amd64/lock.json: no such file or directory
2021-08-16T18:52:05.330+0300 [INFO]  backend/local: starting Apply operation
2021-08-16T18:52:05.338+0300 [DEBUG] created provider logger: level=debug
2021-08-16T18:52:05.339+0300 [INFO]  provider: configuring client automatic mTLS
2021-08-16T18:52:05.383+0300 [DEBUG] provider: starting plugin: path=.terraform/providers/registry.terraform.io/hashicorp/ad/0.4.3/darwin_amd64/terraform-provider-ad_v0.4.3_x5 args=[.terraform/providers/registry.terraform.io/hashicorp/ad/0.4.3/darwin_amd64/terraform-provider-ad_v0.4.3_x5]
2021-08-16T18:52:05.387+0300 [DEBUG] provider: plugin started: path=.terraform/providers/registry.terraform.io/hashicorp/ad/0.4.3/darwin_amd64/terraform-provider-ad_v0.4.3_x5 pid=50633
2021-08-16T18:52:05.387+0300 [DEBUG] provider: waiting for RPC address: path=.terraform/providers/registry.terraform.io/hashicorp/ad/0.4.3/darwin_amd64/terraform-provider-ad_v0.4.3_x5
2021-08-16T18:52:05.400+0300 [INFO]  provider.terraform-provider-ad_v0.4.3_x5: configuring server automatic mTLS: timestamp=2021-08-16T18:52:05.399+0300
2021-08-16T18:52:05.434+0300 [DEBUG] provider.terraform-provider-ad_v0.4.3_x5: plugin address: address=/var/folders/8z/03m43xln1p93n9fydl9k94f80000gn/T/plugin167944316 network=unix timestamp=2021-08-16T18:52:05.434+0300
2021-08-16T18:52:05.434+0300 [DEBUG] provider: using plugin: version=5
2021-08-16T18:52:05.493+0300 [DEBUG] provider.stdio: received EOF, stopping recv loop: err="rpc error: code = Unavailable desc = transport is closing"
2021-08-16T18:52:05.495+0300 [DEBUG] provider: plugin process exited: path=.terraform/providers/registry.terraform.io/hashicorp/ad/0.4.3/darwin_amd64/terraform-provider-ad_v0.4.3_x5 pid=50633
2021-08-16T18:52:05.495+0300 [DEBUG] provider: plugin exited
2021-08-16T18:52:05.496+0300 [INFO]  terraform: building graph: GraphTypeValidate
2021-08-16T18:52:05.500+0300 [DEBUG] ProviderTransformer: "ad_computer.AxonHost" (*terraform.NodeValidatableResource) needs provider["registry.terraform.io/hashicorp/ad"]
2021-08-16T18:52:05.500+0300 [DEBUG] ReferenceTransformer: "var.password" references: []
2021-08-16T18:52:05.500+0300 [DEBUG] ReferenceTransformer: "var.generate" references: []
2021-08-16T18:52:05.500+0300 [DEBUG] ReferenceTransformer: "provider[\"registry.terraform.io/hashicorp/ad\"]" references: []
2021-08-16T18:52:05.500+0300 [INFO]  ReferenceTransformer: reference not found: "count.index"
2021-08-16T18:52:05.500+0300 [INFO]  ReferenceTransformer: reference not found: "count.index"
2021-08-16T18:52:05.500+0300 [INFO]  ReferenceTransformer: reference not found: "count.index"
2021-08-16T18:52:05.500+0300 [DEBUG] ReferenceTransformer: "ad_computer.AxonHost" references: [var.generate]
2021-08-16T18:52:05.500+0300 [DEBUG] ReferenceTransformer: "var.hostname" references: []
2021-08-16T18:52:05.500+0300 [DEBUG] ReferenceTransformer: "var.dc" references: []
2021-08-16T18:52:05.501+0300 [DEBUG] ReferenceTransformer: "var.username" references: []
2021-08-16T18:52:05.501+0300 [DEBUG] Starting graph walk: walkValidate
2021-08-16T18:52:05.503+0300 [DEBUG] created provider logger: level=debug
2021-08-16T18:52:05.503+0300 [INFO]  provider: configuring client automatic mTLS
2021-08-16T18:52:05.535+0300 [DEBUG] provider: starting plugin: path=.terraform/providers/registry.terraform.io/hashicorp/ad/0.4.3/darwin_amd64/terraform-provider-ad_v0.4.3_x5 args=[.terraform/providers/registry.terraform.io/hashicorp/ad/0.4.3/darwin_amd64/terraform-provider-ad_v0.4.3_x5]
2021-08-16T18:52:05.539+0300 [DEBUG] provider: plugin started: path=.terraform/providers/registry.terraform.io/hashicorp/ad/0.4.3/darwin_amd64/terraform-provider-ad_v0.4.3_x5 pid=50634
2021-08-16T18:52:05.539+0300 [DEBUG] provider: waiting for RPC address: path=.terraform/providers/registry.terraform.io/hashicorp/ad/0.4.3/darwin_amd64/terraform-provider-ad_v0.4.3_x5
2021-08-16T18:52:05.551+0300 [INFO]  provider.terraform-provider-ad_v0.4.3_x5: configuring server automatic mTLS: timestamp=2021-08-16T18:52:05.551+0300
2021-08-16T18:52:05.586+0300 [DEBUG] provider: using plugin: version=5
2021-08-16T18:52:05.586+0300 [DEBUG] provider.terraform-provider-ad_v0.4.3_x5: plugin address: address=/var/folders/8z/03m43xln1p93n9fydl9k94f80000gn/T/plugin159415913 network=unix timestamp=2021-08-16T18:52:05.586+0300
2021-08-16T18:52:05.637+0300 [DEBUG] provider.stdio: received EOF, stopping recv loop: err="rpc error: code = Unavailable desc = transport is closing"
2021-08-16T18:52:05.639+0300 [DEBUG] provider: plugin process exited: path=.terraform/providers/registry.terraform.io/hashicorp/ad/0.4.3/darwin_amd64/terraform-provider-ad_v0.4.3_x5 pid=50634
2021-08-16T18:52:05.639+0300 [DEBUG] provider: plugin exited
2021-08-16T18:52:05.639+0300 [INFO]  backend/local: apply calling Plan
2021-08-16T18:52:05.639+0300 [INFO]  terraform: building graph: GraphTypePlan
2021-08-16T18:52:05.640+0300 [DEBUG] ProviderTransformer: "ad_computer.AxonHost (expand)" (*terraform.nodeExpandPlannableResource) needs provider["registry.terraform.io/hashicorp/ad"]
2021-08-16T18:52:05.640+0300 [DEBUG] ReferenceTransformer: "var.generate" references: []
2021-08-16T18:52:05.640+0300 [DEBUG] ReferenceTransformer: "var.hostname" references: []
2021-08-16T18:52:05.640+0300 [DEBUG] ReferenceTransformer: "var.dc" references: []
2021-08-16T18:52:05.640+0300 [DEBUG] ReferenceTransformer: "provider[\"registry.terraform.io/hashicorp/ad\"]" references: []
2021-08-16T18:52:05.640+0300 [INFO]  ReferenceTransformer: reference not found: "count.index"
2021-08-16T18:52:05.640+0300 [INFO]  ReferenceTransformer: reference not found: "count.index"
2021-08-16T18:52:05.640+0300 [INFO]  ReferenceTransformer: reference not found: "count.index"
2021-08-16T18:52:05.640+0300 [DEBUG] ReferenceTransformer: "ad_computer.AxonHost (expand)" references: [var.generate]
2021-08-16T18:52:05.640+0300 [DEBUG] ReferenceTransformer: "var.username" references: []
2021-08-16T18:52:05.640+0300 [DEBUG] ReferenceTransformer: "var.password" references: []
2021-08-16T18:52:05.641+0300 [DEBUG] Starting graph walk: walkPlan
2021-08-16T18:52:05.642+0300 [DEBUG] created provider logger: level=debug
2021-08-16T18:52:05.642+0300 [INFO]  provider: configuring client automatic mTLS
2021-08-16T18:52:05.674+0300 [DEBUG] provider: starting plugin: path=.terraform/providers/registry.terraform.io/hashicorp/ad/0.4.3/darwin_amd64/terraform-provider-ad_v0.4.3_x5 args=[.terraform/providers/registry.terraform.io/hashicorp/ad/0.4.3/darwin_amd64/terraform-provider-ad_v0.4.3_x5]
2021-08-16T18:52:05.678+0300 [DEBUG] provider: plugin started: path=.terraform/providers/registry.terraform.io/hashicorp/ad/0.4.3/darwin_amd64/terraform-provider-ad_v0.4.3_x5 pid=50635
2021-08-16T18:52:05.678+0300 [DEBUG] provider: waiting for RPC address: path=.terraform/providers/registry.terraform.io/hashicorp/ad/0.4.3/darwin_amd64/terraform-provider-ad_v0.4.3_x5
2021-08-16T18:52:05.694+0300 [INFO]  provider.terraform-provider-ad_v0.4.3_x5: configuring server automatic mTLS: timestamp=2021-08-16T18:52:05.694+0300
2021-08-16T18:52:05.728+0300 [DEBUG] provider.terraform-provider-ad_v0.4.3_x5: plugin address: address=/var/folders/8z/03m43xln1p93n9fydl9k94f80000gn/T/plugin185354910 network=unix timestamp=2021-08-16T18:52:05.728+0300
2021-08-16T18:52:05.729+0300 [DEBUG] provider: using plugin: version=5
2021-08-16T18:52:05.775+0300 [WARN]  ValidateProviderConfig from "provider[\"registry.terraform.io/hashicorp/ad\"]" changed the config value, but that value is unused
2021-08-16T18:52:05.777+0300 [DEBUG] Resource instance state not found for node "ad_computer.AxonHost[0]", instance ad_computer.AxonHost[0]
2021-08-16T18:52:05.777+0300 [DEBUG] Resource instance state not found for node "ad_computer.AxonHost[1]", instance ad_computer.AxonHost[1]
2021-08-16T18:52:05.777+0300 [INFO]  ReferenceTransformer: reference not found: "var.generate"
2021-08-16T18:52:05.777+0300 [INFO]  ReferenceTransformer: reference not found: "count.index"
2021-08-16T18:52:05.777+0300 [INFO]  ReferenceTransformer: reference not found: "count.index"
2021-08-16T18:52:05.777+0300 [INFO]  ReferenceTransformer: reference not found: "count.index"
2021-08-16T18:52:05.777+0300 [DEBUG] ReferenceTransformer: "ad_computer.AxonHost[1]" references: []
2021-08-16T18:52:05.777+0300 [INFO]  ReferenceTransformer: reference not found: "var.generate"
2021-08-16T18:52:05.777+0300 [INFO]  ReferenceTransformer: reference not found: "count.index"
2021-08-16T18:52:05.777+0300 [INFO]  ReferenceTransformer: reference not found: "count.index"
2021-08-16T18:52:05.777+0300 [INFO]  ReferenceTransformer: reference not found: "count.index"
2021-08-16T18:52:05.777+0300 [DEBUG] ReferenceTransformer: "ad_computer.AxonHost[0]" references: []
2021-08-16T18:52:05.778+0300 [DEBUG] refresh: ad_computer.AxonHost[0]: no state, so not refreshing
2021-08-16T18:52:05.778+0300 [DEBUG] refresh: ad_computer.AxonHost[1]: no state, so not refreshing
2021-08-16T18:52:05.781+0300 [DEBUG] provider.stdio: received EOF, stopping recv loop: err="rpc error: code = Unavailable desc = transport is closing"
2021-08-16T18:52:05.783+0300 [DEBUG] provider: plugin process exited: path=.terraform/providers/registry.terraform.io/hashicorp/ad/0.4.3/darwin_amd64/terraform-provider-ad_v0.4.3_x5 pid=50635
2021-08-16T18:52:05.783+0300 [DEBUG] provider: plugin exited

Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
  + create

Terraform will perform the following actions:

  # ad_computer.AxonHost[0] will be created
  + resource "ad_computer" "AxonHost" {
      + container   = "OU=Computers,OU=hanan-domain-2,DC=hanan-domain-2,DC=axonius,DC=test"
      + description = "AXON HOST 0"
      + dn          = (known after apply)
      + guid        = (known after apply)
      + id          = (known after apply)
      + name        = "AXON-0"
      + pre2kname   = "AXON0$"
      + sid         = (known after apply)
    }

  # ad_computer.AxonHost[1] will be created
  + resource "ad_computer" "AxonHost" {
      + container   = "OU=Computers,OU=hanan-domain-2,DC=hanan-domain-2,DC=axonius,DC=test"
      + description = "AXON HOST 1"
      + dn          = (known after apply)
      + guid        = (known after apply)
      + id          = (known after apply)
      + name        = "AXON-1"
      + pre2kname   = "AXON1$"
      + sid         = (known after apply)
    }

Plan: 2 to add, 0 to change, 0 to destroy.
2021-08-16T18:52:05.784+0300 [INFO]  backend/local: apply calling Apply
2021-08-16T18:52:05.784+0300 [INFO]  terraform: building graph: GraphTypeApply
2021-08-16T18:52:05.785+0300 [DEBUG] Resource state not found for node "ad_computer.AxonHost[1]", instance ad_computer.AxonHost[1]
2021-08-16T18:52:05.785+0300 [DEBUG] Resource state not found for node "ad_computer.AxonHost[0]", instance ad_computer.AxonHost[0]
2021-08-16T18:52:05.785+0300 [DEBUG] ProviderTransformer: "ad_computer.AxonHost (expand)" (*terraform.nodeExpandApplyableResource) needs provider["registry.terraform.io/hashicorp/ad"]
2021-08-16T18:52:05.785+0300 [DEBUG] ProviderTransformer: "ad_computer.AxonHost[1]" (*terraform.NodeApplyableResourceInstance) needs provider["registry.terraform.io/hashicorp/ad"]
2021-08-16T18:52:05.785+0300 [DEBUG] ProviderTransformer: "ad_computer.AxonHost[0]" (*terraform.NodeApplyableResourceInstance) needs provider["registry.terraform.io/hashicorp/ad"]
2021-08-16T18:52:05.785+0300 [DEBUG] ReferenceTransformer: "ad_computer.AxonHost (expand)" references: [var.generate]
2021-08-16T18:52:05.785+0300 [DEBUG] ReferenceTransformer: "var.hostname" references: []
2021-08-16T18:52:05.785+0300 [DEBUG] ReferenceTransformer: "var.dc" references: []
2021-08-16T18:52:05.785+0300 [DEBUG] ReferenceTransformer: "var.username" references: []
2021-08-16T18:52:05.785+0300 [DEBUG] ReferenceTransformer: "var.generate" references: []
2021-08-16T18:52:05.785+0300 [DEBUG] ReferenceTransformer: "var.password" references: []
2021-08-16T18:52:05.785+0300 [INFO]  ReferenceTransformer: reference not found: "count.index"
2021-08-16T18:52:05.785+0300 [INFO]  ReferenceTransformer: reference not found: "count.index"
2021-08-16T18:52:05.785+0300 [INFO]  ReferenceTransformer: reference not found: "count.index"
2021-08-16T18:52:05.785+0300 [DEBUG] ReferenceTransformer: "ad_computer.AxonHost[1]" references: [var.generate]
2021-08-16T18:52:05.785+0300 [INFO]  ReferenceTransformer: reference not found: "count.index"
2021-08-16T18:52:05.785+0300 [INFO]  ReferenceTransformer: reference not found: "count.index"
2021-08-16T18:52:05.786+0300 [INFO]  ReferenceTransformer: reference not found: "count.index"
2021-08-16T18:52:05.786+0300 [DEBUG] ReferenceTransformer: "ad_computer.AxonHost[0]" references: [var.generate]
2021-08-16T18:52:05.786+0300 [DEBUG] ReferenceTransformer: "provider[\"registry.terraform.io/hashicorp/ad\"]" references: []
2021-08-16T18:52:05.786+0300 [DEBUG] Starting graph walk: walkApply
2021-08-16T18:52:05.787+0300 [DEBUG] created provider logger: level=debug
2021-08-16T18:52:05.787+0300 [INFO]  provider: configuring client automatic mTLS
2021-08-16T18:52:05.818+0300 [DEBUG] provider: starting plugin: path=.terraform/providers/registry.terraform.io/hashicorp/ad/0.4.3/darwin_amd64/terraform-provider-ad_v0.4.3_x5 args=[.terraform/providers/registry.terraform.io/hashicorp/ad/0.4.3/darwin_amd64/terraform-provider-ad_v0.4.3_x5]
2021-08-16T18:52:05.821+0300 [DEBUG] provider: plugin started: path=.terraform/providers/registry.terraform.io/hashicorp/ad/0.4.3/darwin_amd64/terraform-provider-ad_v0.4.3_x5 pid=50636
2021-08-16T18:52:05.821+0300 [DEBUG] provider: waiting for RPC address: path=.terraform/providers/registry.terraform.io/hashicorp/ad/0.4.3/darwin_amd64/terraform-provider-ad_v0.4.3_x5
2021-08-16T18:52:05.834+0300 [INFO]  provider.terraform-provider-ad_v0.4.3_x5: configuring server automatic mTLS: timestamp=2021-08-16T18:52:05.833+0300
2021-08-16T18:52:05.867+0300 [DEBUG] provider.terraform-provider-ad_v0.4.3_x5: plugin address: address=/var/folders/8z/03m43xln1p93n9fydl9k94f80000gn/T/plugin177169659 network=unix timestamp=2021-08-16T18:52:05.867+0300
2021-08-16T18:52:05.867+0300 [DEBUG] provider: using plugin: version=5
2021-08-16T18:52:05.911+0300 [WARN]  ValidateProviderConfig from "provider[\"registry.terraform.io/hashicorp/ad\"]" changed the config value, but that value is unused
ad_computer.AxonHost[0]: Creating...
ad_computer.AxonHost[1]: Creating...
2021-08-16T18:52:05.914+0300 [INFO]  Starting apply for ad_computer.AxonHost[0]
2021-08-16T18:52:05.914+0300 [INFO]  Starting apply for ad_computer.AxonHost[1]
2021-08-16T18:52:05.914+0300 [DEBUG] ad_computer.AxonHost[0]: applying the planned Create change
2021-08-16T18:52:05.914+0300 [DEBUG] ad_computer.AxonHost[1]: applying the planned Create change
2021-08-16T18:52:05.915+0300 [INFO]  provider.terraform-provider-ad_v0.4.3_x5: 2021/08/16 18:52:05 [DEBUG] sanitising key "AXON-1" to: AXON-1: timestamp=2021-08-16T18:52:05.915+0300
2021-08-16T18:52:05.915+0300 [INFO]  provider.terraform-provider-ad_v0.4.3_x5: 2021/08/16 18:52:05 [DEBUG] sanitising key "AXON-0" to: AXON-0: timestamp=2021-08-16T18:52:05.915+0300
2021-08-16T18:52:05.915+0300 [INFO]  provider.terraform-provider-ad_v0.4.3_x5: 2021/08/16 18:52:05 [DEBUG] sanitising key "" to:: timestamp=2021-08-16T18:52:05.915+0300
2021-08-16T18:52:05.915+0300 [INFO]  provider.terraform-provider-ad_v0.4.3_x5: 2021/08/16 18:52:05 [DEBUG] sanitising key "" to:: timestamp=2021-08-16T18:52:05.915+0300
2021-08-16T18:52:05.915+0300 [INFO]  provider.terraform-provider-ad_v0.4.3_x5: 2021/08/16 18:52:05 [DEBUG] sanitising key "AXON HOST 1" to: AXON HOST 1: timestamp=2021-08-16T18:52:05.915+0300
2021-08-16T18:52:05.915+0300 [INFO]  provider.terraform-provider-ad_v0.4.3_x5: 2021/08/16 18:52:05 [DEBUG] sanitising key "AXON HOST 0" to: AXON HOST 0: timestamp=2021-08-16T18:52:05.915+0300
2021-08-16T18:52:05.915+0300 [INFO]  provider.terraform-provider-ad_v0.4.3_x5: 2021/08/16 18:52:05 [DEBUG] sanitising key "" to:: timestamp=2021-08-16T18:52:05.915+0300
2021-08-16T18:52:05.915+0300 [INFO]  provider.terraform-provider-ad_v0.4.3_x5: 2021/08/16 18:52:05 [DEBUG] sanitising key "" to:: timestamp=2021-08-16T18:52:05.915+0300
2021-08-16T18:52:05.915+0300 [INFO]  provider.terraform-provider-ad_v0.4.3_x5: 2021/08/16 18:52:05 [DEBUG] sanitising key "AXON1$" to: AXON1`$: timestamp=2021-08-16T18:52:05.915+0300
2021-08-16T18:52:05.915+0300 [INFO]  provider.terraform-provider-ad_v0.4.3_x5: 2021/08/16 18:52:05 [DEBUG] sanitising key "AXON0$" to: AXON0`$: timestamp=2021-08-16T18:52:05.915+0300
2021-08-16T18:52:05.915+0300 [INFO]  provider.terraform-provider-ad_v0.4.3_x5: 2021/08/16 18:52:05 [DEBUG] sanitising key "OU=Computers,OU=hanan-domain-2,DC=hanan-domain-2,DC=axonius,DC=test" to: OU=Computers,OU=hanan-domain-2,DC=hanan-domain-2,DC=axonius,DC=test: timestamp=2021-08-16T18:52:05.915+0300
2021-08-16T18:52:05.915+0300 [INFO]  provider.terraform-provider-ad_v0.4.3_x5: 2021/08/16 18:52:05 [DEBUG] Checking if connection should be local: timestamp=2021-08-16T18:52:05.915+0300
2021-08-16T18:52:05.915+0300 [INFO]  provider.terraform-provider-ad_v0.4.3_x5: 2021/08/16 18:52:05 [DEBUG] Local connection ? false: timestamp=2021-08-16T18:52:05.915+0300
2021-08-16T18:52:05.915+0300 [INFO]  provider.terraform-provider-ad_v0.4.3_x5: 2021/08/16 18:52:05 [DEBUG] sanitising key "OU=Computers,OU=hanan-domain-2,DC=hanan-domain-2,DC=axonius,DC=test" to: OU=Computers,OU=hanan-domain-2,DC=hanan-domain-2,DC=axonius,DC=test: timestamp=2021-08-16T18:52:05.915+0300
2021-08-16T18:52:05.915+0300 [INFO]  provider.terraform-provider-ad_v0.4.3_x5: 2021/08/16 18:52:05 [DEBUG] Checking if connection should be local: timestamp=2021-08-16T18:52:05.915+0300
2021-08-16T18:52:05.915+0300 [INFO]  provider.terraform-provider-ad_v0.4.3_x5: 2021/08/16 18:52:05 [DEBUG] Local connection ? false: timestamp=2021-08-16T18:52:05.915+0300
2021-08-16T18:52:05.915+0300 [INFO]  provider.terraform-provider-ad_v0.4.3_x5: 2021/08/16 18:52:05 [DEBUG] Checking to see if credentials should be passed: timestamp=2021-08-16T18:52:05.915+0300
2021-08-16T18:52:05.915+0300 [INFO]  provider.terraform-provider-ad_v0.4.3_x5: 2021/08/16 18:52:05 [DEBUG] Checking to see if credentials should be passed: timestamp=2021-08-16T18:52:05.915+0300
2021-08-16T18:52:05.915+0300 [INFO]  provider.terraform-provider-ad_v0.4.3_x5: 2021/08/16 18:52:05 [DEBUG] Matching criteria for passing credenitals: timestamp=2021-08-16T18:52:05.915+0300
2021-08-16T18:52:05.915+0300 [INFO]  provider.terraform-provider-ad_v0.4.3_x5: 2021/08/16 18:52:05 [DEBUG] Pass Credentials ? true: timestamp=2021-08-16T18:52:05.915+0300
2021-08-16T18:52:05.915+0300 [INFO]  provider.terraform-provider-ad_v0.4.3_x5: 2021/08/16 18:52:05 [DEBUG] Matching criteria for passing credenitals: timestamp=2021-08-16T18:52:05.915+0300
2021-08-16T18:52:05.915+0300 [INFO]  provider.terraform-provider-ad_v0.4.3_x5: 2021/08/16 18:52:05 [DEBUG] Constructing powerrshell command: $Password = ConvertTo-SecureString -String "<REDACTED>" -AsPlainText -Force
 $User = "Admin"
 $Credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $User, $Password
 New-ADComputer -Passthru -Name "AXON-1" -SamAccountName "AXON1`$" -Path "OU=Computers,OU=hanan-domain-2,DC=hanan-domain-2,DC=axonius,DC=test" -Description "AXON HOST 1" -Credential $Credential -Server HANAN-DOMAIN-2.AXONIUS.TEST | ConvertTo-Json: timestamp=2021-08-16T18:52:05.915+0300
2021-08-16T18:52:05.915+0300 [INFO]  provider.terraform-provider-ad_v0.4.3_x5: 2021/08/16 18:52:05 [DEBUG] Pass Credentials ? true: timestamp=2021-08-16T18:52:05.915+0300
2021-08-16T18:52:05.915+0300 [INFO]  provider.terraform-provider-ad_v0.4.3_x5: 2021/08/16 18:52:05 [DEBUG] Constructing powerrshell command: $Password = ConvertTo-SecureString -String "<REDACTED>" -AsPlainText -Force
 $User = "Admin"
 $Credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $User, $Password
 New-ADComputer -Passthru -Name "AXON-0" -SamAccountName "AXON0`$" -Path "OU=Computers,OU=hanan-domain-2,DC=hanan-domain-2,DC=axonius,DC=test" -Description "AXON HOST 0" -Credential $Credential -Server HANAN-DOMAIN-2.AXONIUS.TEST | ConvertTo-Json: timestamp=2021-08-16T18:52:05.915+0300
2021-08-16T18:52:05.915+0300 [INFO]  provider.terraform-provider-ad_v0.4.3_x5: 2021/08/16 18:52:05 [DEBUG] Executing command on remote host: timestamp=2021-08-16T18:52:05.915+0300
2021-08-16T18:52:05.915+0300 [INFO]  provider.terraform-provider-ad_v0.4.3_x5: 2021/08/16 18:52:05 [DEBUG] Executing command on remote host: timestamp=2021-08-16T18:52:05.915+0300
2021-08-16T18:52:09.654+0300 [INFO]  provider.terraform-provider-ad_v0.4.3_x5: 2021/08/16 18:52:09 [DEBUG] Powershell command exited with code 0: timestamp=2021-08-16T18:52:09.654+0300
2021-08-16T18:52:09.655+0300 [INFO]  provider.terraform-provider-ad_v0.4.3_x5: 2021/08/16 18:52:09 [DEBUG] Powershell command exited with code 0: timestamp=2021-08-16T18:52:09.654+0300
2021-08-16T18:52:09.655+0300 [INFO]  provider.terraform-provider-ad_v0.4.3_x5: 2021/08/16 18:52:09 [DEBUG] Checking if connection should be local: timestamp=2021-08-16T18:52:09.655+0300
2021-08-16T18:52:09.655+0300 [INFO]  provider.terraform-provider-ad_v0.4.3_x5: 2021/08/16 18:52:09 [DEBUG] Local connection ? false: timestamp=2021-08-16T18:52:09.655+0300
2021-08-16T18:52:09.655+0300 [INFO]  provider.terraform-provider-ad_v0.4.3_x5: 2021/08/16 18:52:09 [DEBUG] Checking to see if credentials should be passed: timestamp=2021-08-16T18:52:09.655+0300
2021-08-16T18:52:09.655+0300 [INFO]  provider.terraform-provider-ad_v0.4.3_x5: 2021/08/16 18:52:09 [DEBUG] Matching criteria for passing credenitals: timestamp=2021-08-16T18:52:09.655+0300
2021-08-16T18:52:09.655+0300 [INFO]  provider.terraform-provider-ad_v0.4.3_x5: 2021/08/16 18:52:09 [DEBUG] Pass Credentials ? true: timestamp=2021-08-16T18:52:09.655+0300
2021-08-16T18:52:09.655+0300 [INFO]  provider.terraform-provider-ad_v0.4.3_x5: 2021/08/16 18:52:09 [DEBUG] Constructing powerrshell command: $Password = ConvertTo-SecureString -String "<REDACTED>" -AsPlainText -Force
 $User = "Admin"
 $Credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $User, $Password
 Get-ADComputer -Identity "68e226d7-81fe-4cf8-af01-616b0c14c24b" -Properties * -Credential $Credential -Server HANAN-DOMAIN-2.AXONIUS.TEST | ConvertTo-Json: timestamp=2021-08-16T18:52:09.655+0300
2021-08-16T18:52:09.655+0300 [INFO]  provider.terraform-provider-ad_v0.4.3_x5: 2021/08/16 18:52:09 [DEBUG] Executing command on remote host: timestamp=2021-08-16T18:52:09.655+0300
2021-08-16T18:52:09.748+0300 [INFO]  provider.terraform-provider-ad_v0.4.3_x5: 2021/08/16 18:52:09 [DEBUG] Powershell command exited with code 0: timestamp=2021-08-16T18:52:09.748+0300
2021-08-16T18:52:09.748+0300 [INFO]  provider.terraform-provider-ad_v0.4.3_x5: 2021/08/16 18:52:09 [DEBUG] Powershell command exited with code 0: timestamp=2021-08-16T18:52:09.748+0300
2021-08-16T18:52:09.748+0300 [INFO]  provider.terraform-provider-ad_v0.4.3_x5: 2021/08/16 18:52:09 [DEBUG] Checking if connection should be local: timestamp=2021-08-16T18:52:09.748+0300
2021-08-16T18:52:09.748+0300 [INFO]  provider.terraform-provider-ad_v0.4.3_x5: 2021/08/16 18:52:09 [DEBUG] Local connection ? false: timestamp=2021-08-16T18:52:09.748+0300
2021-08-16T18:52:09.748+0300 [INFO]  provider.terraform-provider-ad_v0.4.3_x5: 2021/08/16 18:52:09 [DEBUG] Checking to see if credentials should be passed: timestamp=2021-08-16T18:52:09.748+0300
2021-08-16T18:52:09.748+0300 [INFO]  provider.terraform-provider-ad_v0.4.3_x5: 2021/08/16 18:52:09 [DEBUG] Matching criteria for passing credenitals: timestamp=2021-08-16T18:52:09.748+0300
2021-08-16T18:52:09.748+0300 [INFO]  provider.terraform-provider-ad_v0.4.3_x5: 2021/08/16 18:52:09 [DEBUG] Pass Credentials ? true: timestamp=2021-08-16T18:52:09.748+0300
2021-08-16T18:52:09.748+0300 [INFO]  provider.terraform-provider-ad_v0.4.3_x5: 2021/08/16 18:52:09 [DEBUG] Constructing powerrshell command: $Password = ConvertTo-SecureString -String "<REDACTED>" -AsPlainText -Force
 $User = "Admin"
 $Credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $User, $Password
 Get-ADComputer -Identity "10d691a9-6dde-47d2-98c6-eb8cd792e7c8" -Properties * -Credential $Credential -Server HANAN-DOMAIN-2.AXONIUS.TEST | ConvertTo-Json: timestamp=2021-08-16T18:52:09.748+0300
2021-08-16T18:52:09.748+0300 [INFO]  provider.terraform-provider-ad_v0.4.3_x5: 2021/08/16 18:52:09 [DEBUG] Executing command on remote host: timestamp=2021-08-16T18:52:09.748+0300
2021-08-16T18:52:13.198+0300 [INFO]  provider.terraform-provider-ad_v0.4.3_x5: 2021/08/16 18:52:13 [DEBUG] Powershell command exited with code 1: timestamp=2021-08-16T18:52:13.198+0300
2021-08-16T18:52:13.198+0300 [INFO]  provider.terraform-provider-ad_v0.4.3_x5: 2021/08/16 18:52:13 [DEBUG] Powershell command exited with code 1: timestamp=2021-08-16T18:52:13.198+0300
2021-08-16T18:52:13.198+0300 [INFO]  provider.terraform-provider-ad_v0.4.3_x5: 2021/08/16 18:52:13 [DEBUG] Stdout: , Stderr: #< CLIXML
<Objs Version="1.1.0.1" xmlns="http://schemas.microsoft.com/powershell/2004/04"><Obj S="progress" RefId="0"><TN RefId="0"><T>System.Management.Automation.PSCustomObject</T><T>System.Object</T></TN><MS><I64 N="SourceId">1</I64><PR N="Record"><AV>Preparing modules for first use.</AV><AI>0</AI><Nil /><PI>-1</PI><PC>-1</PC><T>Completed</T><SR>-1</SR><SD> </SD></PR></MS></Obj><Obj S="progress" RefId="1"><TNRef RefId="0" /><MS><I64 N="SourceId">1</I64><PR N="Record"><AV>Preparing modules for first use.</AV><AI>0</AI><Nil /><PI>-1</PI><PC>-1</PC><T>Completed</T><SR>-1</SR><SD> </SD></PR></MS></Obj><Obj S="progress" RefId="2"><TNRef RefId="0" /><MS><I64 N="SourceId">1</I64><PR N="Record"><AV>Preparing modules for first use.</AV><AI>0</AI><Nil /><PI>-1</PI><PC>-1</PC><T>Completed</T><SR>-1</SR><SD> </SD></PR></MS></Obj><S S="Error">Get-ADComputer : Directory object not found_x000D__x000A_</S><S S="Error">At line:4 char:2_x000D__x000A_</S><S S="Error">+  Get-ADComputer -Identity "68e226d7-81fe-4cf8-af01-616b0c14c24b" -Pro ..._x000D__x000A_</S><S S="Error">+  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~_x000D__x000A_</S><S S="Error">    + CategoryInfo          : ObjectNotFound: (68e226d7-81fe-4cf8-af01-616b0c14c24b:ADComputer) [Get-ADComputer], ADId _x000D__x000A_</S><S S="Error">   entityNotFoundException_x000D__x000A_</S><S S="Error">    + FullyQualifiedErrorId : ActiveDirectoryCmdlet:Microsoft.ActiveDirectory.Management.ADIdentityNotFoundException,M _x000D__x000A_</S><S S="Error">   icrosoft.ActiveDirectory.Management.Commands.GetADComputer_x000D__x000A_</S><S S="Error"> _x000D__x000A_</S></Objs>: timestamp=2021-08-16T18:52:13.198+0300
2021-08-16T18:52:13.682+0300 [INFO]  provider.terraform-provider-ad_v0.4.3_x5: 2021/08/16 18:52:13 [DEBUG] Powershell command exited with code 0: timestamp=2021-08-16T18:52:13.682+0300
2021-08-16T18:52:13.682+0300 [INFO]  provider.terraform-provider-ad_v0.4.3_x5: 2021/08/16 18:52:13 [DEBUG] Powershell command exited with code 0: timestamp=2021-08-16T18:52:13.682+0300
ad_computer.AxonHost[0]: Creation complete after 8s [id=10d691a9-6dde-47d2-98c6-eb8cd792e7c8]
╷
│ Error: Provider produced inconsistent result after apply
│
│ When applying changes to ad_computer.AxonHost[1], provider "provider[\"registry.terraform.io/hashicorp/ad\"]" produced an unexpected new value: Root resource was present, but now absent.
│
│ This is a bug in the provider, which should be reported in the provider's own issue tracker.
╵
2021-08-16T18:52:13.725+0300 [DEBUG] provider.stdio: received EOF, stopping recv loop: err="rpc error: code = Unavailable desc = transport is closing"
2021-08-16T18:52:13.729+0300 [DEBUG] provider: plugin process exited: path=.terraform/providers/registry.terraform.io/hashicorp/ad/0.4.3/darwin_amd64/terraform-provider-ad_v0.4.3_x5 pid=50636
2021-08-16T18:52:13.729+0300 [DEBUG] provider: plugin exited
exit status 1
techBeck03 commented 3 years ago

I had this exact issue when I set the winrm_hostname to my domain name example.com. My theory (and I'm no AD expert) is that the create is happening on one of my domain controllers and the read is getting DNS load balanced to the other domain controller which isn't yet in sync. When I changed my winrm_hostname to a specific domain controller I no longer got this error.

ryantho6 commented 3 years ago

I got this error too while using second hop. I suspect, as @techBeck03 said, it's due to reading from multiple DCs. I believe the get-adobject command (and probably other) uses a -server DOMAIN.COM rather than -server SPECIFICDC

juanjojulian commented 2 years ago

Hi, we are getting this same problem here when creating ad_computer resources, we have a pretty big multisite and multi region domain with several domain controllers. ad provider is configured with Double hop Authentication. I assume that this is due to the way the provider works, once the creation of the Computer Object is done the function calls resourceADComputerRead() in order to verify the creation:

func resourceADComputerCreate(d *schema.ResourceData, meta interface{}) error {
    computer := winrmhelper.NewComputerFromResource(d)
    guid, err := computer.Create(meta.(*config.ProviderConf))
    if err != nil {
        return fmt.Errorf("error while creating new computer object: %s", err)
    }
    d.SetId(guid)
    return resourceADComputerRead(d, meta)
}

In my case the Computer Object is successfully created:

2022-02-24T15:48:56.399Z [INFO]  provider.terraform-provider-ad_v0.4.3_x5: 2022/02/24 15:48:56 [DEBUG] Constructing powerrshell command: $Password = ConvertTo-SecureString -String "<REDACTED>" -AsPlainText -Force
 $User = "ADTest"
 $Credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $User, $Password
 New-ADComputer -Passthru -Name "terraform-test3" -Path "OU=Servers_TEST,OU=Servers,DC=XXX,DC=XX,DC=com" -Description "terraform-test3 - Private Cloud" -Credential $Credential -Server XXX.XX.COM | ConvertTo-Json: timestamp=2022-02-24T15:48:56.399Z
2022-02-24T15:48:56.400Z [INFO]  provider.terraform-provider-ad_v0.4.3_x5: 2022/02/24 15:48:56 [DEBUG] Executing command on remote host: timestamp=2022-02-24T15:48:56.400Z

But Get-ADComputer command is failing (directory object not found):

2022-02-24T15:48:59.677Z [INFO]  provider.terraform-provider-ad_v0.4.3_x5: 2022/02/24 15:48:59 [DEBUG] Constructing powerrshell command: $Password = ConvertTo-SecureString -String "<REDACTED>" -AsPlainText -Force
 $User = "ADTest"
 $Credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $User, $Password
 Get-ADComputer -Identity "1abe1178-f263-418c-8e80-aaa2b066ceb2" -Properties * -Credential $Credential -Server XXX.XX.COM | ConvertTo-Json: timestamp=2022-02-24T15:48:59.677Z
2022-02-24T15:48:59.677Z [INFO]  provider.terraform-provider-ad_v0.4.3_x5: 2022/02/24 15:48:59 [DEBUG] Executing command on remote host: timestamp=2022-02-24T15:48:59.677Z
CleanShot 2022-02-27 at 15 09 06@2x

Only 3 seconds between the New-ADComputer command and the Get-ADComputer command but if I'm not mistaken and due to the way winrm works both commands are completely separated and independent winrm sessions which means that the first "New-ADComputer" could be issued against one domain controller and the "Get-ADComputer" against a different one and only 3 seconds could not be enough for AD replication in big multi-region domains.

Could it be possible to delay the verification a little bit? Maybe by adding a time.Sleep(30 * time.Second) to both "resourceADComputerCreate" and "resourceADComputerUpdate"?

func resourceADComputerCreate(d *schema.ResourceData, meta interface{}) error {
    computer := winrmhelper.NewComputerFromResource(d)
    guid, err := computer.Create(meta.(*config.ProviderConf))
    if err != nil {
        return fmt.Errorf("error while creating new computer object: %s", err)
    }
    d.SetId(guid)
        time.Sleep(30 * time.Second)
    return resourceADComputerRead(d, meta)
}
Sdougal commented 1 year ago

Just want to add I've just hit this as well...

Double hop Kerberos auth in azure using a self hosted terraform cloud agent using a mgmt VM to create OUs in Azure Active Directory Domain Services.

The OUs were created but Terraform Cloud reported a failure and therefore the resources don't appear in the state file.

"Error: Provider produced inconsistent result after apply When applying changes to ad_ou., provider "provider[\"registry.terraform.io/hashicorp/ad\"]" produced an unexpected new value: Root resource was present, but now absent.

This is a bug in the provider, which should be reported in the provider's own issue tracker."

jwhite-ac commented 1 year ago

Only 3 seconds between the New-ADComputer command and the Get-ADComputer command but if I'm not mistaken and due to the way winrm works both commands are completely separated and independent winrm sessions which means that the first "New-ADComputer" could be issued against one domain controller and the "Get-ADComputer" against a different one and only 3 seconds could not be enough for AD replication in big multi-region domains.

Could it be possible to delay the verification a little bit? Maybe by adding a time.Sleep(30 * time.Second) to both "resourceADComputerCreate" and "resourceADComputerUpdate"?

Hitting this exact issue today, you are dead right, one session is creating the object, another is verifying, and they're both hitting different DCs - the change has not had a chance to propagate against all of them.

We've worked around this by targeting a specific DC, and it appears the solution for the provider is simple (wait and/or retry). Incredible that this has been open for 2 years and not fixed...