hashicorp / terraform-plugin-sdk

Terraform Plugin SDK enables building plugins (providers) to manage any service providers or custom in-house solutions
https://developer.hashicorp.com/terraform/plugin
Mozilla Public License 2.0
433 stars 230 forks source link

Setting Optional w/ Default is reporting an warning #159

Closed kevinkirkup closed 4 years ago

kevinkirkup commented 5 years ago

Terraform Version

% terraform -v
Terraform v0.12.1

Terraform Configuration Files

N/A

Debug Output

In the schema, the arguments are set as Optional with a Default:

        "billing_term": {
            Type:     schema.TypeString,
            Optional: true,
            Default:  "HOURLY",
        },
        "peering_type": {
            Type:         schema.TypeString,
            Description:  "The peering type to use for this connection: [PUBLIC, PRIVATE]",
            Default:      "PRIVATE",
            Optional:     true,
            ForceNew:     true,
            ValidateFunc: validation.StringInSlice([]string{"private", "public"}, true),
        },

Terraform reports a warning:

      - .peering_type: planned value cty.StringVal("PRIVATE") does not match config value cty.NullVal(cty.String)
      - .billing_term: planned value cty.StringVal("HOURLY") does not match config value cty.NullVal(cty.String)
pureport_aws_connection.main - *terraform.NodePlannableResourceInstance
------
2019/06/05 12:27:14 [TRACE] Executing graph transform *terraform.OrphanResourceCountTransformer
2019/06/05 12:27:14 [TRACE] Completed graph transform *terraform.OrphanResourceCountTransformer (no changes)
2019/06/05 12:27:14 [TRACE] Executing graph transform *terraform.AttachStateTransformer
2019/06/05 12:27:14 [DEBUG] Resource instance state not found for node "pureport_aws_connection.main", instance pureport_aws_connection.main
2019/06/05 12:27:14 [TRACE] Completed graph transform *terraform.AttachStateTransformer (no changes)
2019/06/05 12:27:14 [TRACE] Executing graph transform *terraform.TargetsTransformer
2019/06/05 12:27:14 [TRACE] Completed graph transform *terraform.TargetsTransformer (no changes)
2019/06/05 12:27:14 [TRACE] Executing graph transform *terraform.ReferenceTransformer
2019/06/05 12:27:14 [DEBUG] ReferenceTransformer: "pureport_aws_connection.main" references: []
2019/06/05 12:27:14 [TRACE] Completed graph transform *terraform.ReferenceTransformer (no changes)
2019/06/05 12:27:14 [TRACE] Executing graph transform *terraform.RootTransformer
2019/06/05 12:27:14 [TRACE] Completed graph transform *terraform.RootTransformer (no changes)
2019/06/05 12:27:14 [TRACE] vertex "pureport_aws_connection.main": entering dynamic subgraph
2019/06/05 12:27:14 [TRACE] dag/walk: updating graph
2019/06/05 12:27:14 [TRACE] dag/walk: added new vertex: "pureport_aws_connection.main"
2019/06/05 12:27:14 [TRACE] dag/walk: visiting "pureport_aws_connection.main"
2019/06/05 12:27:14 [TRACE] vertex "pureport_aws_connection.main": starting visit (*terraform.NodePlannableResourceInstance)
2019/06/05 12:27:14 [TRACE] vertex "pureport_aws_connection.main": evaluating
2019/06/05 12:27:14 [TRACE] [walkPlan] Entering eval tree: pureport_aws_connection.main
2019/06/05 12:27:14 [TRACE] <root>: eval: *terraform.EvalSequence
2019/06/05 12:27:14 [TRACE] <root>: eval: *terraform.EvalGetProvider
2019/06/05 12:27:14 [TRACE] <root>: eval: *terraform.EvalReadState
2019/06/05 12:27:14 [TRACE] EvalReadState: reading state for pureport_aws_connection.main
2019/06/05 12:27:14 [TRACE] EvalReadState: no state present for pureport_aws_connection.main
2019/06/05 12:27:14 [TRACE] <root>: eval: *terraform.EvalValidateSelfRef
2019/06/05 12:27:14 [TRACE] <root>: eval: *terraform.EvalDiff
2019/06/05 12:27:14 [TRACE] GetResourceInstance: data.pureport_cloud_regions.main is a single instance
2019/06/05 12:27:14 [TRACE] GetResourceInstance: data.pureport_locations.main is a single instance
2019/06/05 12:27:14 [TRACE] GetResourceInstance: data.pureport_networks.main is a single instance
2019/06/05 12:27:14 [TRACE] GRPCProvider: PlanResourceChange
2019/06/05 12:27:14 [WARN] Provider "pureport" produced an invalid plan for pureport_aws_connection.main, but we are tolerating it because it is using the legacy plugin SDK.
    The following problems may be the cause of any confusing errors from downstream operations:
      - .peering_type: planned value cty.StringVal("PRIVATE") does not match config value cty.NullVal(cty.String)
      - .billing_term: planned value cty.StringVal("HOURLY") does not match config value cty.NullVal(cty.String)
      - .nat_config: attribute representing nested block must not be unknown itself; set nested attribute values to unknown instead
2019/06/05 12:27:14 [TRACE] <root>: eval: *terraform.EvalCheckPreventDestroy
2019/06/05 12:27:14 [TRACE] <root>: eval: *terraform.EvalWriteState
2019/06/05 12:27:14 [TRACE] EvalWriteState: writing current state object for pureport_aws_connection.main
2019/06/05 12:27:14 [TRACE] <root>: eval: *terraform.EvalWriteDiff
2019/06/05 12:27:14 [TRACE] EvalWriteDiff: recorded Create change for pureport_aws_connection.main
2019/06/05 12:27:14 [TRACE] [walkPlan] Exiting eval tree: pureport_aws_connection.main
2019/06/05 12:27:14 [TRACE] vertex "pureport_aws_connection.main": visit complete
2019/06/05 12:27:14 [TRACE] vertex "pureport_aws_connection.main": dynamic subgraph completed successfully
2019/06/05 12:27:14 [TRACE] vertex "pureport_aws_connection.main": visit complete
2019/06/05 12:27:14 [TRACE] dag/walk: visiting "meta.count-boundary (EachMode fixup)"
2019/06/05 12:27:14 [TRACE] vertex "meta.count-boundary (EachMode fixup)": starting visit (*terraform.NodeCountBoundary)
2019/06/05 12:27:14 [TRACE] vertex "meta.count-boundary (EachMode fixup)": evaluating
2019/06/05 12:27:14 [TRACE] [walkPlan] Entering eval tree: meta.count-boundary (EachMode fixup)
2019/06/05 12:27:14 [TRACE] <root>: eval: *terraform.EvalCountFixZeroOneBoundaryGlobal
2019/06/05 12:27:14 [TRACE] dag/walk: visiting "provider.pureport (close)"
2019/06/05 12:27:14 [TRACE] vertex "provider.pureport (close)": starting visit (*terraform.graphNodeCloseProvider)
2019/06/05 12:27:14 [TRACE] vertex "provider.pureport (close)": evaluating
2019/06/05 12:27:14 [TRACE] [walkPlan] Entering eval tree: provider.pureport (close)
2019/06/05 12:27:14 [TRACE] <root>: eval: *terraform.EvalCloseProvider
2019/06/05 12:27:14 [TRACE] GRPCProvider: Close
2019/06/05 12:27:14 [TRACE] [walkPlan] Exiting eval tree: meta.count-boundary (EachMode fixup)
2019/06/05 12:27:14 [TRACE] vertex "meta.count-boundary (EachMode fixup)": visit complete
2019/06/05 12:27:14 [DEBUG] provider has no plugin.Client
2019/06/05 12:27:14 [TRACE] [walkPlan] Exiting eval tree: provider.pureport (close)
2019/06/05 12:27:14 [TRACE] vertex "provider.pureport (close)": visit complete
2019/06/05 12:27:14 [TRACE] dag/walk: visiting "root"
2019/06/05 12:27:14 [TRACE] vertex "root": starting visit (terraform.graphNodeRoot)
2019/06/05 12:27:14 [TRACE] vertex "root": visit complete
2019/06/05 12:27:14 [WARN] Test: Step plan: DIFF:

CREATE: pureport_aws_connection.main
  aws_account_id:      "" => "123456789012"
  aws_region:          "" => "us-west-2"
  billing_term:        "" => "HOURLY"
  customer_networks.#: "" => "0"
  gateways:            "" => "<computed>"
  high_availability:   "" => "true"
  id:                  "" => "<computed>"
  location_href:       "" => "/locations/us-sea"
  name:                "" => "AwsDirectConnectTest"
  nat_config:          "" => "<computed>"
  network_href:        "" => "/networks/network-EhlpJLhAcHMOmY75J91H3g"
  peering_type:        "" => "PRIVATE"
  speed:               "" => "100"

Crash Output

Expected Behavior

This should have been fine.

Actual Behavior

Terraform reports a warning

Steps to Reproduce

Run the Acceptance Tests for Pureport Provider.

Additional Context

References

None that I could find.

jbardin commented 5 years ago

Hi @kevinkirkup,

Thanks for bringing this up.

This is the expected behavior when using the old SDK with the new provider protocol. In the future there will be a new SDK that can make full use of the new plugin protocol.

What is happening is that when a provider gets the proposed new state to plan, the only fields it can technically replace must be marked as Computed (defaults are essentially a computed field that is filled in during plan). However that doesn't align with how the old SDK worked, and we need to make allowances for that in core by only logging a warning.

These warnings have still proven extremely useful in diagnosing provider issues, since they often highlight where providers are returning the incorrect values which cause problems later on. Unfortunately in the case of Default settings, Terraform has no visibility into that and can't distinguish them from any other unexpected value.

I'll leave this open for now to make it easier for others to try and locate information about the warnings.

paultyng commented 4 years ago

Going to close this issue as there isn't anything actionable left and folks should still get search hits for closed issues anyway.

ghost commented 4 years ago

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.