hashicorp / terraform

Terraform enables you to safely and predictably create, change, and improve infrastructure. It is a source-available tool that codifies APIs into declarative configuration files that can be shared amongst team members, treated as code, edited, reviewed, and versioned.
https://www.terraform.io/
Other
42.47k stars 9.51k forks source link

Multi-line comments have regressed with hcl2 in Terraform v12.0-alpha2 #19372

Closed ravitandonrt closed 5 years ago

ravitandonrt commented 5 years ago

Terraform Version

2018/11/14 17:26:35 [INFO] Terraform version: 0.12.0 alpha2
2018/11/14 17:26:35 [INFO] Go runtime version: go1.11.1

Terraform Configuration Files

/*
 * This example file shows how to create a group and add a user to it.
 */

resource "oci_identity_group" "group1" {
  name        = "tf-example-group"
  description = "group created by terraform"
}

resource "oci_identity_user_group_membership" "user-group-mem1" {
  compartment_id = "${var.tenancy_ocid}"
  user_id        = "${oci_identity_user.user1.id}"
  group_id       = "${oci_identity_group.group1.id}"
}

data "oci_identity_groups" "groups1" {
  compartment_id = "${oci_identity_group.group1.compartment_id}"

  filter {
    name   = "name"
    values = ["tf-example-group"]
  }
}

output "groups" {
  value = "${data.oci_identity_groups.groups1.groups}"
}

/*
 * Some more directives to show dynamic groups and policy for it
 */
resource "oci_identity_dynamic_group" "dynamic-group-1" {
  compartment_id = "${var.tenancy_ocid}"
  name           = "tf-example-dynamic-group"
  description    = "dynamic group created by terraform"
  matching_rule  = "instance.compartment.id = ${oci_identity_compartment.compartment1.id}"
}

data "oci_identity_dynamic_groups" "dynamic-groups-1" {
  compartment_id = "${oci_identity_dynamic_group.dynamic-group-1.compartment_id}"

  filter {
    name   = "id"
    values = ["${oci_identity_dynamic_group.dynamic-group-1.id}"]
  }
}

output "dynamicGroups" {
  value = "${data.oci_identity_dynamic_groups.dynamic-groups-1.dynamic_groups}"
}

Full TF Config: https://github.com/terraform-providers/terraform-provider-oci/tree/master/docs/examples/identity/identity_providers

Debug Output

Error: Reference to undeclared resource

on /Users/ratandon/projects/go/src/github.com/terraform-providers/terraform-provider-oci/docs/examples/identity/identity_providers/idp_group_mapping.tf line 3, in resource "oci_identity_idp_group_mapping" "test_idp_group_mapping": 3: group_id = "${oci_identity_group.group1.id}"

A resource "oci_identity_group" "group1" has not been declared in the root module

The resources in that file group.tf got completely skipped due to the two multi-line comments in there, here is the walkthrough: vtity_api_key.api-key1 - terraform.NodeValidatableResource oci_identity_auth_token.auth-token1 - terraform.NodeValidatableResource oci_identity_compartment.compartment1 - terraform.NodeValidatableResource oci_identity_customer_secret_key.customer-secret-key1 - terraform.NodeValidatableResource oci_identity_dynamic_group.dynamic-group-1 - terraform.NodeValidatableResource oci_identity_identity_provider.test_identity_provider - terraform.NodeValidatableResource oci_identity_idp_group_mapping.test_idp_group_mapping - terraform.NodeValidatableResource oci_identity_ui_password.password1 - terraform.NodeValidatableResource oci_identity_user.user1 - terraform.NodeValidatableResource output.auth-token - terraform.NodeApplyableOutput output.compartments - terraform.NodeApplyableOutput output.customer-secret-key - terraform.NodeApplyableOutput output.dynamicGroups - terraform.NodeApplyableOutput output.identity_providers - terraform.NodeApplyableOutput output.idp_group_mappings - terraform.NodeApplyableOutput output.user-api-key - terraform.NodeApplyableOutput output.user-password - terraform.NodeApplyableOutput output.users1 - terraform.NodeApplyableOutput provider.oci - terraform.NodeApplyableProvider var.fingerprint - terraform.NodeRootVariable var.identity_provider_defined_tags_value - terraform.NodeRootVariable var.identity_provider_description - terraform.NodeRootVariable var.identity_provider_freeform_tags - terraform.NodeRootVariable var.identity_provider_metadata - terraform.NodeRootVariable var.identity_provider_metadata_file - terraform.NodeRootVariable var.identity_provider_metadata_url - terraform.NodeRootVariable var.identity_provider_name - terraform.NodeRootVariable var.identity_provider_product_type - terraform.NodeRootVariable var.identity_provider_protocol - terraform.NodeRootVariable var.idp_group_mapping_idp_group_name - terraform.NodeRootVariable var.private_key_path - terraform.NodeRootVariable var.region - terraform.NodeRootVariable var.tenancy_ocid - terraform.NodeRootVariable var.user_ocid - terraform.NodeRootVariable

Crash Output

Expected Behavior

Multi-line comments should continue to work as in hcl v1. I noticed that there are tests for different types of comments in there. It would be good to run those tests against hcl v2.

https://github.com/hashicorp/hcl/blob/ef8a98b0bbce4a65b5aa4c368430a80ddc533168/hcl/printer/testdata/comment.golden

Actual Behavior

Most likely the hcl2 parser greedily consumed the rest of the TF config file as part of the multi-line comment, haven't had a change to look at the parser.

On removing the comments, the TF config worked. However, this can break any existing TF configs with multi-line comments in them using / and /

Steps to Reproduce

  1. terraform init
  2. terraform plan or terraform validate

Additional Context

Our OCI provider does not ship with the terraform v12 alpha and is built locally. It is compiled against go version go1.9.6 darwin/amd64

2018-11-14T17:29:36.874-0800 [DEBUG] plugin: waiting for RPC address: path=/Users/ratandon/.terraform.d/plugins/darwin_amd64/terraform-provider-oci 2018-11-14T17:29:36.892-0800 [DEBUG] plugin.terraform-provider-oci: 2018/11/14 17:29:36 [INFO] terraform-provider-oci 3.6.0

I will also try updating the Go version but that should not have any impact on parsing of TF config from a plugin perspective.

References

apparentlymart commented 5 years ago

Hi @ravitandonrt! Thanks for reporting this.

This seems to be the same root problem as #19224, so I'm going to close this one just to consolidate over there.

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.