Repository: GoogleCloudPlatform/terraform-validator
Pull request #458 (2022-01-07 18:28:39)

fix hand written iam files
<!-- Put a description of what this PR is for here, along with any references to issues that this resolves or contributes to -->
fix hand written iam files to adapt to multiple parameters in asset name



<!--
Replace each [ ] with [X] to check it. Switch to the preview view to make it easier to click on links.
These steps will speed up the review process, and we appreciate you spending time on them before sending
your code to be reviewed.
-->
If this PR is for Terraform, I acknowledge that I have:

- [X] Searched through the [issue tracker](https://github.com/hashicorp/terraform-provider-google/issues) for an open issue that this either resolves or contributes to, commented on it to claim it, and written "fixes {url}" or "part of {url}" in this PR description. If there were no relevant open issues, I opened one and commented that I would like to work on it (not necessary for very small changes).
- [ ] [Generated Terraform](https://github.com/GoogleCloudPlatform/magic-modules#generating-downstream-tools), and ran `make test` and `make lint` to ensure it passes unit and linter tests.
- [ ] Ensured that all new fields I added that can be set by a user appear in at least one [example](https://github.com/GoogleCloudPlatform/magic-modules/tree/master/templates/terraform/examples) (for generated resources) or [third_party test](https://github.com/GoogleCloudPlatform/magic-modules/tree/master/third_party/terraform/tests) (for handwritten resources or update tests).
- [ ] [Ran](https://github.com/hashicorp/terraform-provider-google/blob/master/.github/CONTRIBUTING.md#tests) relevant acceptance tests (If the acceptance tests do not yet pass or you are unable to run them, please let your reviewer know).
- [X] Read the [Release Notes Guide](https://github.com/GoogleCloudPlatform/magic-modules/blob/master/.ci/RELEASE_NOTES_GUIDE.md) before writing my release note below.

<!-- AUTOCHANGELOG for Downstream PRs.

Please select one of the following "release-note:" headings:
    - release-note:enhancement
    - release-note:bug
    - release-note:note
    - release-note:new-resource
    - release-note:new-datasource
    - release-note:deprecation
    - release-note:breaking-change
    - release-note:none
    
Unless you choose release-note:none, please add a release note.

See .ci/RELEASE_NOTES_GUIDE.md for writing good release notes.

You can add more release note blocks if you want more than one CHANGELOG
entry for this PR.
-->
**Release Note Template for Downstream PRs (will be copied)**

```release-note:none

```

Derived from https://github.com/GoogleCloudPlatform/magic-modules/pull/5598


Patch:
diff --git a/converters/google/resources/bigquery_dataset_iam.go b/converters/google/resources/bigquery_dataset_iam.go
index a1152665..0de2b9ca 100644
--- a/converters/google/resources/bigquery_dataset_iam.go
+++ b/converters/google/resources/bigquery_dataset_iam.go
@@ -73,7 +73,7 @@ func newBigqueryDatasetIamAsset(
 		return []Asset{}, fmt.Errorf("expanding bindings: %v", err)
 	}
 
-	name, err := assetName(d, config, "//bigquery.googleapis.com/{{dataset_id}}")
+	name, err := assetName(d, config, "//bigquery.googleapis.com/projects/{{project}}/datasets/{{dataset_id}}")
 	if err != nil {
 		return []Asset{}, err
 	}
@@ -97,7 +97,7 @@ func FetchBigqueryDatasetIamPolicy(d TerraformResourceData, config *Config) (Ass
 		NewBigqueryDatasetIamUpdater,
 		d,
 		config,
-		"//bigquery.googleapis.com/{{dataset_id}}",
+		"//bigquery.googleapis.com/projects/{{project}}/datasets/{{dataset_id}}",
 		"bigquery.googleapis.com/Dataset",
 	)
 }
diff --git a/converters/google/resources/pubsub_subscription_iam.go b/converters/google/resources/pubsub_subscription_iam.go
index 59ce310a..678e495f 100644
--- a/converters/google/resources/pubsub_subscription_iam.go
+++ b/converters/google/resources/pubsub_subscription_iam.go
@@ -73,7 +73,7 @@ func newPubsubSubscriptionIamAsset(
 		return []Asset{}, fmt.Errorf("expanding bindings: %v", err)
 	}
 
-	name, err := assetName(d, config, "//pubsub.googleapis.com/{{pubsubSubscriptionId}}")
+	name, err := assetName(d, config, "//pubsub.googleapis.com/projects/{{project}}/subscriptions/{{subscription}}")
 	if err != nil {
 		return []Asset{}, err
 	}
@@ -89,7 +89,7 @@ func newPubsubSubscriptionIamAsset(
 
 func FetchPubsubSubscriptionIamPolicy(d TerraformResourceData, config *Config) (Asset, error) {
 	// Check if the identity field returns a value
-	if _, ok := d.GetOk("{{pubsubSubscriptionId}}"); !ok {
+	if _, ok := d.GetOk("{{subscription}}"); !ok {
 		return Asset{}, ErrEmptyIdentityField
 	}
 
@@ -97,7 +97,7 @@ func FetchPubsubSubscriptionIamPolicy(d TerraformResourceData, config *Config) (
 		NewPubsubSubscriptionIamUpdater,
 		d,
 		config,
-		"//pubsub.googleapis.com/{{pubsubSubscriptionId}}",
+		"//pubsub.googleapis.com/projects/{{project}}/subscriptions/{{subscription}}",
 		"pubsub.googleapis.com/Subscription",
 	)
 }
diff --git a/converters/google/resources/spanner_database_iam.go b/converters/google/resources/spanner_database_iam.go
index 1e98f398..ba81b92b 100644
--- a/converters/google/resources/spanner_database_iam.go
+++ b/converters/google/resources/spanner_database_iam.go
@@ -73,7 +73,7 @@ func newSpannerDatabaseIamAsset(
 		return []Asset{}, fmt.Errorf("expanding bindings: %v", err)
 	}
 
-	name, err := assetName(d, config, "//spanner.googleapis.com/{{spannerDatabaseId}}")
+	name, err := assetName(d, config, "//spanner.googleapis.com/projects/{{project}}/instances/{{instance}}/databases/{{database}}")
 	if err != nil {
 		return []Asset{}, err
 	}
@@ -89,7 +89,11 @@ func newSpannerDatabaseIamAsset(
 
 func FetchSpannerDatabaseIamPolicy(d TerraformResourceData, config *Config) (Asset, error) {
 	// Check if the identity field returns a value
-	if _, ok := d.GetOk("{{spannerDatabaseId}}"); !ok {
+	if _, ok := d.GetOk("{{instance}}"); !ok {
+		return Asset{}, ErrEmptyIdentityField
+	}
+
+	if _, ok := d.GetOk("{{database}}"); !ok {
 		return Asset{}, ErrEmptyIdentityField
 	}
 
@@ -97,7 +101,7 @@ func FetchSpannerDatabaseIamPolicy(d TerraformResourceData, config *Config) (Ass
 		NewSpannerDatabaseIamUpdater,
 		d,
 		config,
-		"//spanner.googleapis.com/{{spannerDatabaseId}}",
+		"//spanner.googleapis.com/projects/{{project}}/instances/{{instance}}/databases/{{database}}",
 		"spanner.googleapis.com/Database",
 	)
 }
diff --git a/converters/google/resources/spanner_instance_iam.go b/converters/google/resources/spanner_instance_iam.go
index 86dfe134..9e2120fe 100644
--- a/converters/google/resources/spanner_instance_iam.go
+++ b/converters/google/resources/spanner_instance_iam.go
@@ -73,7 +73,7 @@ func newSpannerInstanceIamAsset(
 		return []Asset{}, fmt.Errorf("expanding bindings: %v", err)
 	}
 
-	name, err := assetName(d, config, "//spanner.googleapis.com/{{instance_id}}")
+	name, err := assetName(d, config, "//spanner.googleapis.com/projects/{{project}}/instances/{{instance}}")
 	if err != nil {
 		return []Asset{}, err
 	}
@@ -89,7 +89,7 @@ func newSpannerInstanceIamAsset(
 
 func FetchSpannerInstanceIamPolicy(d TerraformResourceData, config *Config) (Asset, error) {
 	// Check if the identity field returns a value
-	if _, ok := d.GetOk("{{instance_id}}"); !ok {
+	if _, ok := d.GetOk("{{instance}}"); !ok {
 		return Asset{}, ErrEmptyIdentityField
 	}
 
@@ -97,7 +97,7 @@ func FetchSpannerInstanceIamPolicy(d TerraformResourceData, config *Config) (Ass
 		NewSpannerInstanceIamUpdater,
 		d,
 		config,
-		"//spanner.googleapis.com/{{instance_id}}",
+		"//spanner.googleapis.com/projects/{{project}}/instances/{{instance}}",
 		"spanner.googleapis.com/Instance",
 	)
 }


Test patch:
diff --git a/testdata/templates/example_bigquery_dataset_iam_binding.json b/testdata/templates/example_bigquery_dataset_iam_binding.json
index e779657d..a3f5bacc 100644
--- a/testdata/templates/example_bigquery_dataset_iam_binding.json
+++ b/testdata/templates/example_bigquery_dataset_iam_binding.json
@@ -1,31 +1,34 @@
-[{
-	"name": "//bigquery.googleapis.com/projects/{{.Provider.project}}/datasets/test-dataset",
-	"asset_type": "bigquery.googleapis.com/Dataset",
-	"ancestry_path": "{{.Ancestry}}/project/{{.Provider.project}}",
-	"resource": {
-		"version": "v2",
-		"discovery_document_uri": "https://www.googleapis.com/discovery/v1/apis/bigquery/v2/rest",
-		"discovery_name": "Dataset",
-		"parent": "//cloudresourcemanager.googleapis.com/projects/{{.Provider.project}}",
-		"data": {
-			"datasetReference": {
-				"datasetId": "test-dataset"
-			},
-			"defaultTableExpirationMs": 3600000,
-			"labels": {
-				"env": "dev"
-			},
-			"location": "EU"
-		}
-	}
-}, {
-	"name": "//bigquery.googleapis.com/test-dataset",
-	"asset_type": "bigquery.googleapis.com/Dataset",
-	"ancestry_path": "{{.Ancestry}}/project/{{.Provider.project}}",
-	"iam_policy": {
-		"bindings": [{
-			"role": "roles/bigquery.dataViewer",
-			"members": ["allUsers", "allAuthenticatedUsers"]
-		}]
-	}
-}]
\ No newline at end of file
+[
+  {
+    "name": "//bigquery.googleapis.com/projects/{{.Provider.project}}/datasets/test-dataset",
+    "asset_type": "bigquery.googleapis.com/Dataset",
+    "ancestry_path": "{{.Ancestry}}/project/{{.Provider.project}}",
+    "resource": {
+      "version": "v2",
+      "discovery_document_uri": "https://www.googleapis.com/discovery/v1/apis/bigquery/v2/rest",
+      "discovery_name": "Dataset",
+      "parent": "//cloudresourcemanager.googleapis.com/projects/{{.Provider.project}}",
+      "data": {
+        "datasetReference": {
+          "datasetId": "test-dataset"
+        },
+        "defaultTableExpirationMs": 3600000,
+        "labels": {
+          "env": "dev"
+        },
+        "location": "EU"
+      }
+    },
+    "iam_policy": {
+      "bindings": [
+        {
+          "role": "roles/bigquery.dataViewer",
+          "members": [
+            "allUsers",
+            "allAuthenticatedUsers"
+          ]
+        }
+      ]
+    }
+  }
+]
diff --git a/testdata/templates/example_bigquery_dataset_iam_member.json b/testdata/templates/example_bigquery_dataset_iam_member.json
index 5dce14fe..dbda7165 100644
--- a/testdata/templates/example_bigquery_dataset_iam_member.json
+++ b/testdata/templates/example_bigquery_dataset_iam_member.json
@@ -1,31 +1,33 @@
-[{
-	"name": "//bigquery.googleapis.com/projects/{{.Provider.project}}/datasets/test-dataset",
-	"asset_type": "bigquery.googleapis.com/Dataset",
-	"ancestry_path": "{{.Ancestry}}/project/{{.Provider.project}}",
-	"resource": {
-		"version": "v2",
-		"discovery_document_uri": "https://www.googleapis.com/discovery/v1/apis/bigquery/v2/rest",
-		"discovery_name": "Dataset",
-		"parent": "//cloudresourcemanager.googleapis.com/projects/{{.Provider.project}}",
-		"data": {
-			"datasetReference": {
-				"datasetId": "test-dataset"
-			},
-			"defaultTableExpirationMs": 3600000,
-			"labels": {
-				"env": "dev"
-			},
-			"location": "EU"
-		}
-	}
-}, {
-	"name": "//bigquery.googleapis.com/test-dataset",
-	"asset_type": "bigquery.googleapis.com/Dataset",
-	"ancestry_path": "{{.Ancestry}}/project/{{.Provider.project}}",
-	"iam_policy": {
-		"bindings": [{
-			"role": "roles/bigquery.dataEditor",
-			"members": ["allAuthenticatedUsers"]
-		}]
-	}
-}]
\ No newline at end of file
+[
+  {
+    "name": "//bigquery.googleapis.com/projects/{{.Provider.project}}/datasets/test-dataset",
+    "asset_type": "bigquery.googleapis.com/Dataset",
+    "ancestry_path": "{{.Ancestry}}/project/{{.Provider.project}}",
+    "resource": {
+      "version": "v2",
+      "discovery_document_uri": "https://www.googleapis.com/discovery/v1/apis/bigquery/v2/rest",
+      "discovery_name": "Dataset",
+      "parent": "//cloudresourcemanager.googleapis.com/projects/{{.Provider.project}}",
+      "data": {
+        "datasetReference": {
+          "datasetId": "test-dataset"
+        },
+        "defaultTableExpirationMs": 3600000,
+        "labels": {
+          "env": "dev"
+        },
+        "location": "EU"
+      }
+    },
+    "iam_policy": {
+      "bindings": [
+        {
+          "role": "roles/bigquery.dataEditor",
+          "members": [
+            "allAuthenticatedUsers"
+          ]
+        }
+      ]
+    }
+  }
+]
diff --git a/testdata/templates/example_bigquery_dataset_iam_policy.json b/testdata/templates/example_bigquery_dataset_iam_policy.json
index 0f4f658a..adbde0c0 100644
--- a/testdata/templates/example_bigquery_dataset_iam_policy.json
+++ b/testdata/templates/example_bigquery_dataset_iam_policy.json
@@ -1,31 +1,34 @@
-[{
-	"name": "//bigquery.googleapis.com/projects/{{.Provider.project}}/datasets/test-dataset",
-	"asset_type": "bigquery.googleapis.com/Dataset",
-	"ancestry_path": "{{.Ancestry}}/project/{{.Provider.project}}",
-	"resource": {
-		"version": "v2",
-		"discovery_document_uri": "https://www.googleapis.com/discovery/v1/apis/bigquery/v2/rest",
-		"discovery_name": "Dataset",
-		"parent": "//cloudresourcemanager.googleapis.com/projects/{{.Provider.project}}",
-		"data": {
-			"datasetReference": {
-				"datasetId": "test-dataset"
-			},
-			"defaultTableExpirationMs": 3600000,
-			"labels": {
-				"env": "dev"
-			},
-			"location": "EU"
-		}
-	}
-}, {
-	"name": "//bigquery.googleapis.com/test-dataset",
-	"asset_type": "bigquery.googleapis.com/Dataset",
-	"ancestry_path": "{{.Ancestry}}/project/{{.Provider.project}}",
-	"iam_policy": {
-		"bindings": [{
-			"role": "roles/editor",
-			"members": ["serviceAccount:998476993360@cloudservices.gserviceaccount.com", "allAuthenticatedUsers"]
-		}]
-	}
-}]
\ No newline at end of file
+[
+  {
+    "name": "//bigquery.googleapis.com/projects/{{.Provider.project}}/datasets/test-dataset",
+    "asset_type": "bigquery.googleapis.com/Dataset",
+    "ancestry_path": "{{.Ancestry}}/project/{{.Provider.project}}",
+    "resource": {
+      "version": "v2",
+      "discovery_document_uri": "https://www.googleapis.com/discovery/v1/apis/bigquery/v2/rest",
+      "discovery_name": "Dataset",
+      "parent": "//cloudresourcemanager.googleapis.com/projects/{{.Provider.project}}",
+      "data": {
+        "datasetReference": {
+          "datasetId": "test-dataset"
+        },
+        "defaultTableExpirationMs": 3600000,
+        "labels": {
+          "env": "dev"
+        },
+        "location": "EU"
+      }
+    },
+    "iam_policy": {
+      "bindings": [
+        {
+          "role": "roles/editor",
+          "members": [
+            "serviceAccount:998476993360@cloudservices.gserviceaccount.com",
+            "allAuthenticatedUsers"
+          ]
+        }
+      ]
+    }
+  }
+]
diff --git a/testdata/templates/example_pubsub_subscription_iam_binding.json b/testdata/templates/example_pubsub_subscription_iam_binding.json
index f970350f..de0fda73 100644
--- a/testdata/templates/example_pubsub_subscription_iam_binding.json
+++ b/testdata/templates/example_pubsub_subscription_iam_binding.json
@@ -1,8 +1,27 @@
 [
   {
-    "name": "//pubsub.googleapis.com/placeholder-BpLnfgDs",
+    "name": "//pubsub.googleapis.com/projects/{{.Provider.project}}/subscriptions/example-subscription",
     "asset_type": "pubsub.googleapis.com/Subscription",
     "ancestry_path": "{{.Ancestry}}/project/{{.Provider.project}}",
+    "resource": {
+      "version": "v1",
+      "discovery_document_uri": "https://www.googleapis.com/discovery/v1/apis/pubsub/v1/rest",
+      "discovery_name": "Subscription",
+      "parent": "//cloudresourcemanager.googleapis.com/projects/{{.Provider.project}}",
+      "data": {
+        "ackDeadlineSeconds": 20,
+        "deadLetterPolicy": null,
+        "expirationPolicy": null,
+        "labels": {
+          "test-label1": "test-value1"
+        },
+        "messageRetentionDuration": "604800s",
+        "pushConfig": {
+          "pushEndpoint": "https://example.com/push"
+        },
+        "topic": "projects/{{.Provider.project}}/topics/example-pubsub-topic"
+      }
+    },
     "iam_policy": {
       "bindings": [
         {
diff --git a/testdata/templates/example_pubsub_subscription_iam_binding.tf b/testdata/templates/example_pubsub_subscription_iam_binding.tf
index 03e8dff4..8cd71802 100644
--- a/testdata/templates/example_pubsub_subscription_iam_binding.tf
+++ b/testdata/templates/example_pubsub_subscription_iam_binding.tf
@@ -27,8 +27,27 @@ provider "google" {
   {{if .Provider.credentials }}credentials = "{{.Provider.credentials}}"{{end}}
 }
 
+resource "google_pubsub_subscription" "example" {
+  name  = "example-subscription"
+  topic = "example-pubsub-topic"
+
+  ack_deadline_seconds = 20
+
+  labels = {
+    test-label1 = "test-value1"
+  }
+
+  push_config {
+    push_endpoint = "https://example.com/push"
+
+    attributes = {
+      x-goog-version = "v1"
+    }
+  }
+}
+
 resource "google_pubsub_subscription_iam_binding" "editor" {
-  subscription = "your-subscription-name"
+  subscription = google_pubsub_subscription.example.name
   role         = "roles/editor"
   members = [
     "user:jane@example.com",
diff --git a/testdata/templates/example_pubsub_subscription_iam_binding.tfplan.json b/testdata/templates/example_pubsub_subscription_iam_binding.tfplan.json
index 2f9ca9c1..0a730e6b 100644
--- a/testdata/templates/example_pubsub_subscription_iam_binding.tfplan.json
+++ b/testdata/templates/example_pubsub_subscription_iam_binding.tfplan.json
@@ -4,6 +4,47 @@
   "planned_values": {
     "root_module": {
       "resources": [
+        {
+          "address": "google_pubsub_subscription.example",
+          "mode": "managed",
+          "type": "google_pubsub_subscription",
+          "name": "example",
+          "provider_name": "registry.terraform.io/hashicorp/google",
+          "schema_version": 0,
+          "values": {
+            "ack_deadline_seconds": 20,
+            "dead_letter_policy": [],
+            "enable_message_ordering": null,
+            "filter": null,
+            "labels": {
+              "test-label1": "test-value1"
+            },
+            "message_retention_duration": "604800s",
+            "name": "example-subscription",
+            "push_config": [
+              {
+                "attributes": null,
+                "oidc_token": [],
+                "push_endpoint": "https://example.com/push"
+              }
+            ],
+            "retain_acked_messages": null,
+            "retry_policy": [],
+            "timeouts": null,
+            "topic": "example-pubsub-topic"
+          },
+          "sensitive_values": {
+            "dead_letter_policy": [],
+            "expiration_policy": [],
+            "labels": {},
+            "push_config": [
+              {
+                "oidc_token": []
+              }
+            ],
+            "retry_policy": []
+          }
+        },
         {
           "address": "google_pubsub_subscription_iam_binding.editor",
           "mode": "managed",
@@ -17,7 +58,7 @@
               "user:jane@example.com"
             ],
             "role": "roles/editor",
-            "subscription": "your-subscription-name"
+            "subscription": "example-subscription"
           },
           "sensitive_values": {
             "condition": [],
@@ -30,6 +71,66 @@
     }
   },
   "resource_changes": [
+    {
+      "address": "google_pubsub_subscription.example",
+      "mode": "managed",
+      "type": "google_pubsub_subscription",
+      "name": "example",
+      "provider_name": "registry.terraform.io/hashicorp/google",
+      "change": {
+        "actions": [
+          "create"
+        ],
+        "before": null,
+        "after": {
+          "ack_deadline_seconds": 20,
+          "dead_letter_policy": [],
+          "enable_message_ordering": null,
+          "filter": null,
+          "labels": {
+            "test-label1": "test-value1"
+          },
+          "message_retention_duration": "604800s",
+          "name": "example-subscription",
+          "push_config": [
+            {
+              "attributes": null,
+              "oidc_token": [],
+              "push_endpoint": "https://example.com/push"
+            }
+          ],
+          "retain_acked_messages": null,
+          "retry_policy": [],
+          "timeouts": null,
+          "topic": "example-pubsub-topic"
+        },
+        "after_unknown": {
+          "dead_letter_policy": [],
+          "expiration_policy": true,
+          "id": true,
+          "labels": {},
+          "project": true,
+          "push_config": [
+            {
+              "oidc_token": []
+            }
+          ],
+          "retry_policy": []
+        },
+        "before_sensitive": false,
+        "after_sensitive": {
+          "dead_letter_policy": [],
+          "expiration_policy": [],
+          "labels": {},
+          "push_config": [
+            {
+              "oidc_token": []
+            }
+          ],
+          "retry_policy": []
+        }
+      }
+    },
     {
       "address": "google_pubsub_subscription_iam_binding.editor",
       "mode": "managed",
@@ -47,7 +148,7 @@
             "user:jane@example.com"
           ],
           "role": "roles/editor",
-          "subscription": "your-subscription-name"
+          "subscription": "example-subscription"
         },
         "after_unknown": {
           "condition": [],
@@ -71,6 +172,42 @@
   "configuration": {
     "root_module": {
       "resources": [
+        {
+          "address": "google_pubsub_subscription.example",
+          "mode": "managed",
+          "type": "google_pubsub_subscription",
+          "name": "example",
+          "provider_config_key": "google",
+          "expressions": {
+            "ack_deadline_seconds": {
+              "constant_value": 20
+            },
+            "labels": {
+              "constant_value": {
+                "test-label1": "test-value1"
+              }
+            },
+            "name": {
+              "constant_value": "example-subscription"
+            },
+            "push_config": [
+              {
+                "attributes": {
+                  "constant_value": {
+                    "x-goog-version": "v1"
+                  }
+                },
+                "push_endpoint": {
+                  "constant_value": "https://example.com/push"
+                }
+              }
+            ],
+            "topic": {
+              "constant_value": "example-pubsub-topic"
+            }
+          },
+          "schema_version": 0
+        },
         {
           "address": "google_pubsub_subscription_iam_binding.editor",
           "mode": "managed",
@@ -87,7 +224,10 @@
               "constant_value": "roles/editor"
             },
             "subscription": {
-              "constant_value": "your-subscription-name"
+              "references": [
+                "google_pubsub_subscription.example.name",
+                "google_pubsub_subscription.example"
+              ]
             }
           },
           "schema_version": 0
diff --git a/testdata/templates/example_pubsub_subscription_iam_member.json b/testdata/templates/example_pubsub_subscription_iam_member.json
index f970350f..de0fda73 100644
--- a/testdata/templates/example_pubsub_subscription_iam_member.json
+++ b/testdata/templates/example_pubsub_subscription_iam_member.json
@@ -1,8 +1,27 @@
 [
   {
-    "name": "//pubsub.googleapis.com/placeholder-BpLnfgDs",
+    "name": "//pubsub.googleapis.com/projects/{{.Provider.project}}/subscriptions/example-subscription",
     "asset_type": "pubsub.googleapis.com/Subscription",
     "ancestry_path": "{{.Ancestry}}/project/{{.Provider.project}}",
+    "resource": {
+      "version": "v1",
+      "discovery_document_uri": "https://www.googleapis.com/discovery/v1/apis/pubsub/v1/rest",
+      "discovery_name": "Subscription",
+      "parent": "//cloudresourcemanager.googleapis.com/projects/{{.Provider.project}}",
+      "data": {
+        "ackDeadlineSeconds": 20,
+        "deadLetterPolicy": null,
+        "expirationPolicy": null,
+        "labels": {
+          "test-label1": "test-value1"
+        },
+        "messageRetentionDuration": "604800s",
+        "pushConfig": {
+          "pushEndpoint": "https://example.com/push"
+        },
+        "topic": "projects/{{.Provider.project}}/topics/example-pubsub-topic"
+      }
+    },
     "iam_policy": {
       "bindings": [
         {
diff --git a/testdata/templates/example_pubsub_subscription_iam_member.tf b/testdata/templates/example_pubsub_subscription_iam_member.tf
index f4a9774a..51e9e7d6 100644
--- a/testdata/templates/example_pubsub_subscription_iam_member.tf
+++ b/testdata/templates/example_pubsub_subscription_iam_member.tf
@@ -27,8 +27,27 @@ provider "google" {
   {{if .Provider.credentials }}credentials = "{{.Provider.credentials}}"{{end}}
 }
 
+resource "google_pubsub_subscription" "example" {
+  name  = "example-subscription"
+  topic = "example-pubsub-topic"
+
+  ack_deadline_seconds = 20
+
+  labels = {
+    test-label1 = "test-value1"
+  }
+
+  push_config {
+    push_endpoint = "https://example.com/push"
+
+    attributes = {
+      x-goog-version = "v1"
+    }
+  }
+}
+
 resource "google_pubsub_subscription_iam_member" "editor" {
-  subscription = "your-subscription-name"
+  subscription = google_pubsub_subscription.example.name
   role         = "roles/editor"
   member       = "user:jane@example.com"
 }
diff --git a/testdata/templates/example_pubsub_subscription_iam_member.tfplan.json b/testdata/templates/example_pubsub_subscription_iam_member.tfplan.json
index 5d78eb28..691e23ba 100644
--- a/testdata/templates/example_pubsub_subscription_iam_member.tfplan.json
+++ b/testdata/templates/example_pubsub_subscription_iam_member.tfplan.json
@@ -4,6 +4,47 @@
   "planned_values": {
     "root_module": {
       "resources": [
+        {
+          "address": "google_pubsub_subscription.example",
+          "mode": "managed",
+          "type": "google_pubsub_subscription",
+          "name": "example",
+          "provider_name": "registry.terraform.io/hashicorp/google",
+          "schema_version": 0,
+          "values": {
+            "ack_deadline_seconds": 20,
+            "dead_letter_policy": [],
+            "enable_message_ordering": null,
+            "filter": null,
+            "labels": {
+              "test-label1": "test-value1"
+            },
+            "message_retention_duration": "604800s",
+            "name": "example-subscription",
+            "push_config": [
+              {
+                "attributes": null,
+                "oidc_token": [],
+                "push_endpoint": "https://example.com/push"
+              }
+            ],
+            "retain_acked_messages": null,
+            "retry_policy": [],
+            "timeouts": null,
+            "topic": "example-pubsub-topic"
+          },
+          "sensitive_values": {
+            "dead_letter_policy": [],
+            "expiration_policy": [],
+            "labels": {},
+            "push_config": [
+              {
+                "oidc_token": []
+              }
+            ],
+            "retry_policy": []
+          }
+        },
         {
           "address": "google_pubsub_subscription_iam_member.editor",
           "mode": "managed",
@@ -15,7 +56,7 @@
             "condition": [],
             "member": "user:jane@example.com",
             "role": "roles/editor",
-            "subscription": "your-subscription-name"
+            "subscription": "example-subscription"
           },
           "sensitive_values": {
             "condition": []
@@ -25,6 +66,66 @@
     }
   },
   "resource_changes": [
+    {
+      "address": "google_pubsub_subscription.example",
+      "mode": "managed",
+      "type": "google_pubsub_subscription",
+      "name": "example",
+      "provider_name": "registry.terraform.io/hashicorp/google",
+      "change": {
+        "actions": [
+          "create"
+        ],
+        "before": null,
+        "after": {
+          "ack_deadline_seconds": 20,
+          "dead_letter_policy": [],
+          "enable_message_ordering": null,
+          "filter": null,
+          "labels": {
+            "test-label1": "test-value1"
+          },
+          "message_retention_duration": "604800s",
+          "name": "example-subscription",
+          "push_config": [
+            {
+              "attributes": null,
+              "oidc_token": [],
+              "push_endpoint": "https://example.com/push"
+            }
+          ],
+          "retain_acked_messages": null,
+          "retry_policy": [],
+          "timeouts": null,
+          "topic": "example-pubsub-topic"
+        },
+        "after_unknown": {
+          "dead_letter_policy": [],
+          "expiration_policy": true,
+          "id": true,
+          "labels": {},
+          "project": true,
+          "push_config": [
+            {
+              "oidc_token": []
+            }
+          ],
+          "retry_policy": []
+        },
+        "before_sensitive": false,
+        "after_sensitive": {
+          "dead_letter_policy": [],
+          "expiration_policy": [],
+          "labels": {},
+          "push_config": [
+            {
+              "oidc_token": []
+            }
+          ],
+          "retry_policy": []
+        }
+      }
+    },
     {
       "address": "google_pubsub_subscription_iam_member.editor",
       "mode": "managed",
@@ -40,7 +141,7 @@
           "condition": [],
           "member": "user:jane@example.com",
           "role": "roles/editor",
-          "subscription": "your-subscription-name"
+          "subscription": "example-subscription"
         },
         "after_unknown": {
           "condition": [],
@@ -58,6 +159,42 @@
   "configuration": {
     "root_module": {
       "resources": [
+        {
+          "address": "google_pubsub_subscription.example",
+          "mode": "managed",
+          "type": "google_pubsub_subscription",
+          "name": "example",
+          "provider_config_key": "google",
+          "expressions": {
+            "ack_deadline_seconds": {
+              "constant_value": 20
+            },
+            "labels": {
+              "constant_value": {
+                "test-label1": "test-value1"
+              }
+            },
+            "name": {
+              "constant_value": "example-subscription"
+            },
+            "push_config": [
+              {
+                "attributes": {
+                  "constant_value": {
+                    "x-goog-version": "v1"
+                  }
+                },
+                "push_endpoint": {
+                  "constant_value": "https://example.com/push"
+                }
+              }
+            ],
+            "topic": {
+              "constant_value": "example-pubsub-topic"
+            }
+          },
+          "schema_version": 0
+        },
         {
           "address": "google_pubsub_subscription_iam_member.editor",
           "mode": "managed",
@@ -72,7 +209,10 @@
               "constant_value": "roles/editor"
             },
             "subscription": {
-              "constant_value": "your-subscription-name"
+              "references": [
+                "google_pubsub_subscription.example.name",
+                "google_pubsub_subscription.example"
+              ]
             }
           },
           "schema_version": 0
diff --git a/testdata/templates/example_pubsub_subscription_iam_policy.json b/testdata/templates/example_pubsub_subscription_iam_policy.json
index f970350f..de0fda73 100644
--- a/testdata/templates/example_pubsub_subscription_iam_policy.json
+++ b/testdata/templates/example_pubsub_subscription_iam_policy.json
@@ -1,8 +1,27 @@
 [
   {
-    "name": "//pubsub.googleapis.com/placeholder-BpLnfgDs",
+    "name": "//pubsub.googleapis.com/projects/{{.Provider.project}}/subscriptions/example-subscription",
     "asset_type": "pubsub.googleapis.com/Subscription",
     "ancestry_path": "{{.Ancestry}}/project/{{.Provider.project}}",
+    "resource": {
+      "version": "v1",
+      "discovery_document_uri": "https://www.googleapis.com/discovery/v1/apis/pubsub/v1/rest",
+      "discovery_name": "Subscription",
+      "parent": "//cloudresourcemanager.googleapis.com/projects/{{.Provider.project}}",
+      "data": {
+        "ackDeadlineSeconds": 20,
+        "deadLetterPolicy": null,
+        "expirationPolicy": null,
+        "labels": {
+          "test-label1": "test-value1"
+        },
+        "messageRetentionDuration": "604800s",
+        "pushConfig": {
+          "pushEndpoint": "https://example.com/push"
+        },
+        "topic": "projects/{{.Provider.project}}/topics/example-pubsub-topic"
+      }
+    },
     "iam_policy": {
       "bindings": [
         {
diff --git a/testdata/templates/example_pubsub_subscription_iam_policy.tf b/testdata/templates/example_pubsub_subscription_iam_policy.tf
index dd23f787..1d50f556 100644
--- a/testdata/templates/example_pubsub_subscription_iam_policy.tf
+++ b/testdata/templates/example_pubsub_subscription_iam_policy.tf
@@ -27,7 +27,38 @@ provider "google" {
   {{if .Provider.credentials }}credentials = "{{.Provider.credentials}}"{{end}}
 }
 
+resource "google_pubsub_subscription" "example" {
+  name  = "example-subscription"
+  topic = "example-pubsub-topic"
+
+  ack_deadline_seconds = 20
+
+  labels = {
+    test-label1 = "test-value1"
+  }
+
+  push_config {
+    push_endpoint = "https://example.com/push"
+
+    attributes = {
+      x-goog-version = "v1"
+    }
+  }
+}
+
 resource "google_pubsub_subscription_iam_policy" "editor" {
-  subscription = "my-subscription-name"
-  policy_data = "{\"bindings\":[{\"members\":[\"user:jane@example.com\"],\"role\":\"roles/editor\"}]}"
+  subscription = google_pubsub_subscription.example.name
+  policy_data = jsonencode(
+    {
+      bindings = [
+        {
+          members = [
+            "user:jane@example.com",
+          ]
+          role = "roles/editor"
+        }
+      ]
+    }
+  )
 }
+
diff --git a/testdata/templates/example_pubsub_subscription_iam_policy.tfplan.json b/testdata/templates/example_pubsub_subscription_iam_policy.tfplan.json
index 89bce44d..281258b9 100644
--- a/testdata/templates/example_pubsub_subscription_iam_policy.tfplan.json
+++ b/testdata/templates/example_pubsub_subscription_iam_policy.tfplan.json
@@ -4,6 +4,47 @@
   "planned_values": {
     "root_module": {
       "resources": [
+        {
+          "address": "google_pubsub_subscription.example",
+          "mode": "managed",
+          "type": "google_pubsub_subscription",
+          "name": "example",
+          "provider_name": "registry.terraform.io/hashicorp/google",
+          "schema_version": 0,
+          "values": {
+            "ack_deadline_seconds": 20,
+            "dead_letter_policy": [],
+            "enable_message_ordering": null,
+            "filter": null,
+            "labels": {
+              "test-label1": "test-value1"
+            },
+            "message_retention_duration": "604800s",
+            "name": "example-subscription",
+            "push_config": [
+              {
+                "attributes": null,
+                "oidc_token": [],
+                "push_endpoint": "https://example.com/push"
+              }
+            ],
+            "retain_acked_messages": null,
+            "retry_policy": [],
+            "timeouts": null,
+            "topic": "example-pubsub-topic"
+          },
+          "sensitive_values": {
+            "dead_letter_policy": [],
+            "expiration_policy": [],
+            "labels": {},
+            "push_config": [
+              {
+                "oidc_token": []
+              }
+            ],
+            "retry_policy": []
+          }
+        },
         {
           "address": "google_pubsub_subscription_iam_policy.editor",
           "mode": "managed",
@@ -13,7 +54,7 @@
           "schema_version": 0,
           "values": {
             "policy_data": "{\"bindings\":[{\"members\":[\"user:jane@example.com\"],\"role\":\"roles/editor\"}]}",
-            "subscription": "my-subscription-name"
+            "subscription": "example-subscription"
           },
           "sensitive_values": {}
         }
@@ -21,6 +62,66 @@
     }
   },
   "resource_changes": [
+    {
+      "address": "google_pubsub_subscription.example",
+      "mode": "managed",
+      "type": "google_pubsub_subscription",
+      "name": "example",
+      "provider_name": "registry.terraform.io/hashicorp/google",
+      "change": {
+        "actions": [
+          "create"
+        ],
+        "before": null,
+        "after": {
+          "ack_deadline_seconds": 20,
+          "dead_letter_policy": [],
+          "enable_message_ordering": null,
+          "filter": null,
+          "labels": {
+            "test-label1": "test-value1"
+          },
+          "message_retention_duration": "604800s",
+          "name": "example-subscription",
+          "push_config": [
+            {
+              "attributes": null,
+              "oidc_token": [],
+              "push_endpoint": "https://example.com/push"
+            }
+          ],
+          "retain_acked_messages": null,
+          "retry_policy": [],
+          "timeouts": null,
+          "topic": "example-pubsub-topic"
+        },
+        "after_unknown": {
+          "dead_letter_policy": [],
+          "expiration_policy": true,
+          "id": true,
+          "labels": {},
+          "project": true,
+          "push_config": [
+            {
+              "oidc_token": []
+            }
+          ],
+          "retry_policy": []
+        },
+        "before_sensitive": false,
+        "after_sensitive": {
+          "dead_letter_policy": [],
+          "expiration_policy": [],
+          "labels": {},
+          "push_config": [
+            {
+              "oidc_token": []
+            }
+          ],
+          "retry_policy": []
+        }
+      }
+    },
     {
       "address": "google_pubsub_subscription_iam_policy.editor",
       "mode": "managed",
@@ -34,7 +135,7 @@
         "before": null,
         "after": {
           "policy_data": "{\"bindings\":[{\"members\":[\"user:jane@example.com\"],\"role\":\"roles/editor\"}]}",
-          "subscription": "my-subscription-name"
+          "subscription": "example-subscription"
         },
         "after_unknown": {
           "etag": true,
@@ -46,89 +147,59 @@
       }
     }
   ],
-  "prior_state": {
-    "format_version": "0.2",
-    "terraform_version": "1.0.10",
-    "values": {
-      "root_module": {
-        "resources": [
-          {
-            "address": "data.google_iam_policy.admin",
-            "mode": "data",
-            "type": "google_iam_policy",
-            "name": "admin",
-            "provider_name": "registry.terraform.io/hashicorp/google",
-            "schema_version": 0,
-            "values": {
-              "audit_config": null,
-              "binding": [
-                {
-                  "condition": [],
-                  "members": [
-                    "user:jane@example.com"
-                  ],
-                  "role": "roles/editor"
-                }
-              ],
-              "id": "1120114865",
-              "policy_data": "{\"bindings\":[{\"members\":[\"user:jane@example.com\"],\"role\":\"roles/editor\"}]}"
-            },
-            "sensitive_values": {
-              "binding": [
-                {
-                  "condition": [],
-                  "members": [
-                    false
-                  ]
-                }
-              ]
-            }
-          }
-        ]
-      }
-    }
-  },
   "configuration": {
     "root_module": {
       "resources": [
         {
-          "address": "google_pubsub_subscription_iam_policy.editor",
+          "address": "google_pubsub_subscription.example",
           "mode": "managed",
-          "type": "google_pubsub_subscription_iam_policy",
-          "name": "editor",
+          "type": "google_pubsub_subscription",
+          "name": "example",
           "provider_config_key": "google",
           "expressions": {
-            "policy_data": {
-              "references": [
-                "data.google_iam_policy.admin.policy_data",
-                "data.google_iam_policy.admin"
-              ]
+            "ack_deadline_seconds": {
+              "constant_value": 20
             },
-            "subscription": {
-              "constant_value": "my-subscription-name"
+            "labels": {
+              "constant_value": {
+                "test-label1": "test-value1"
+              }
+            },
+            "name": {
+              "constant_value": "example-subscription"
+            },
+            "push_config": [
+              {
+                "attributes": {
+                  "constant_value": {
+                    "x-goog-version": "v1"
+                  }
+                },
+                "push_endpoint": {
+                  "constant_value": "https://example.com/push"
+                }
+              }
+            ],
+            "topic": {
+              "constant_value": "example-pubsub-topic"
             }
           },
           "schema_version": 0
         },
         {
-          "address": "data.google_iam_policy.admin",
-          "mode": "data",
-          "type": "google_iam_policy",
-          "name": "admin",
+          "address": "google_pubsub_subscription_iam_policy.editor",
+          "mode": "managed",
+          "type": "google_pubsub_subscription_iam_policy",
+          "name": "editor",
           "provider_config_key": "google",
           "expressions": {
-            "binding": [
-              {
-                "members": {
-                  "constant_value": [
-                    "user:jane@example.com"
-                  ]
-                },
-                "role": {
-                  "constant_value": "roles/editor"
-                }
-              }
-            ]
+            "policy_data": {},
+            "subscription": {
+              "references": [
+                "google_pubsub_subscription.example.name",
+                "google_pubsub_subscription.example"
+              ]
+            }
           },
           "schema_version": 0
         }
diff --git a/testdata/templates/example_spanner_database_iam_binding.json b/testdata/templates/example_spanner_database_iam_binding.json
index 43a38fcc..c299e1cf 100644
--- a/testdata/templates/example_spanner_database_iam_binding.json
+++ b/testdata/templates/example_spanner_database_iam_binding.json
@@ -1,8 +1,40 @@
 [
   {
-    "name": "//spanner.googleapis.com/placeholder-BpLnfgDs",
+    "name": "//spanner.googleapis.com/projects/{{.Provider.project}}/instances/my-instance",
+    "asset_type": "spanner.googleapis.com/Instance",
+    "ancestry_path": "{{.Ancestry}}/project/{{.Provider.project}}",
+    "resource": {
+      "version": "v1",
+      "discovery_document_uri": "https://www.googleapis.com/discovery/v1/apis/spanner/v1/rest",
+      "discovery_name": "Instance",
+      "parent": "//cloudresourcemanager.googleapis.com/projects/{{.Provider.project}}",
+      "data": {
+        "instance": {
+          "config": "projects/{{.Provider.project}}/instanceConfigs/regional-europe-west1",
+          "displayName": "main-instance",
+          "nodeCount": 1
+        },
+        "instanceId": "my-instance"
+      }
+    }
+  },
+  {
+    "name": "//spanner.googleapis.com/projects/{{.Provider.project}}/instances/my-instance/databases/my-database",
     "asset_type": "spanner.googleapis.com/Database",
     "ancestry_path": "{{.Ancestry}}/project/{{.Provider.project}}",
+    "resource": {
+      "version": "v1",
+      "discovery_document_uri": "https://www.googleapis.com/discovery/v1/apis/spanner/v1/rest",
+      "discovery_name": "Database",
+      "parent": "//cloudresourcemanager.googleapis.com/projects/{{.Provider.project}}",
+      "data": {
+        "createStatement": "CREATE DATABASE `my-database`",
+        "extraStatements": [
+          "CREATE TABLE t1 (t1 INT64 NOT NULL,) PRIMARY KEY(t1)",
+          "CREATE TABLE t2 (t2 INT64 NOT NULL,) PRIMARY KEY(t2)"
+        ]
+      }
+    },
     "iam_policy": {
       "bindings": [
         {
diff --git a/testdata/templates/example_spanner_database_iam_binding.tf b/testdata/templates/example_spanner_database_iam_binding.tf
index 4d1fc0fe..7fcc4725 100644
--- a/testdata/templates/example_spanner_database_iam_binding.tf
+++ b/testdata/templates/example_spanner_database_iam_binding.tf
@@ -27,9 +27,26 @@ provider "google" {
   {{if .Provider.credentials }}credentials = "{{.Provider.credentials}}"{{end}}
 }
 
+resource "google_spanner_instance" "main" {
+  name = "my-instance"
+  config       = "regional-europe-west1"
+  display_name = "main-instance"
+  num_nodes    = 1
+}
+
+resource "google_spanner_database" "database" {
+  instance = google_spanner_instance.main.name
+  name     = "my-database"
+  ddl = [
+    "CREATE TABLE t1 (t1 INT64 NOT NULL,) PRIMARY KEY(t1)",
+    "CREATE TABLE t2 (t2 INT64 NOT NULL,) PRIMARY KEY(t2)",
+  ]
+  deletion_protection = false
+}
+
 resource "google_spanner_database_iam_binding" "database" {
-  instance = "my-instance"
-  database = "my-database"
+  instance = google_spanner_instance.main.name
+  database = google_spanner_database.database.name
   role     = "roles/compute.networkUser"
 
   members = [
diff --git a/testdata/templates/example_spanner_database_iam_binding.tfplan.json b/testdata/templates/example_spanner_database_iam_binding.tfplan.json
index 0656bec1..1341f100 100644
--- a/testdata/templates/example_spanner_database_iam_binding.tfplan.json
+++ b/testdata/templates/example_spanner_database_iam_binding.tfplan.json
@@ -4,6 +4,32 @@
   "planned_values": {
     "root_module": {
       "resources": [
+        {
+          "address": "google_spanner_database.database",
+          "mode": "managed",
+          "type": "google_spanner_database",
+          "name": "database",
+          "provider_name": "registry.terraform.io/hashicorp/google",
+          "schema_version": 0,
+          "values": {
+            "ddl": [
+              "CREATE TABLE t1 (t1 INT64 NOT NULL,) PRIMARY KEY(t1)",
+              "CREATE TABLE t2 (t2 INT64 NOT NULL,) PRIMARY KEY(t2)"
+            ],
+            "deletion_protection": false,
+            "encryption_config": [],
+            "instance": "my-instance",
+            "name": "my-database",
+            "timeouts": null
+          },
+          "sensitive_values": {
+            "ddl": [
+              false,
+              false
+            ],
+            "encryption_config": []
+          }
+        },
         {
           "address": "google_spanner_database_iam_binding.database",
           "mode": "managed",
@@ -26,11 +52,71 @@
               false
             ]
           }
+        },
+        {
+          "address": "google_spanner_instance.main",
+          "mode": "managed",
+          "type": "google_spanner_instance",
+          "name": "main",
+          "provider_name": "registry.terraform.io/hashicorp/google",
+          "schema_version": 0,
+          "values": {
+            "config": "regional-europe-west1",
+            "display_name": "main-instance",
+            "force_destroy": false,
+            "labels": null,
+            "name": "my-instance",
+            "num_nodes": 1,
+            "timeouts": null
+          },
+          "sensitive_values": {}
         }
       ]
     }
   },
   "resource_changes": [
+    {
+      "address": "google_spanner_database.database",
+      "mode": "managed",
+      "type": "google_spanner_database",
+      "name": "database",
+      "provider_name": "registry.terraform.io/hashicorp/google",
+      "change": {
+        "actions": [
+          "create"
+        ],
+        "before": null,
+        "after": {
+          "ddl": [
+            "CREATE TABLE t1 (t1 INT64 NOT NULL,) PRIMARY KEY(t1)",
+            "CREATE TABLE t2 (t2 INT64 NOT NULL,) PRIMARY KEY(t2)"
+          ],
+          "deletion_protection": false,
+          "encryption_config": [],
+          "instance": "my-instance",
+          "name": "my-database",
+          "timeouts": null
+        },
+        "after_unknown": {
+          "ddl": [
+            false,
+            false
+          ],
+          "encryption_config": [],
+          "id": true,
+          "project": true,
+          "state": true
+        },
+        "before_sensitive": false,
+        "after_sensitive": {
+          "ddl": [
+            false,
+            false
+          ],
+          "encryption_config": []
+        }
+      }
+    },
     {
       "address": "google_spanner_database_iam_binding.database",
       "mode": "managed",
@@ -68,21 +154,69 @@
           ]
         }
       }
+    },
+    {
+      "address": "google_spanner_instance.main",
+      "mode": "managed",
+      "type": "google_spanner_instance",
+      "name": "main",
+      "provider_name": "registry.terraform.io/hashicorp/google",
+      "change": {
+        "actions": [
+          "create"
+        ],
+        "before": null,
+        "after": {
+          "config": "regional-europe-west1",
+          "display_name": "main-instance",
+          "force_destroy": false,
+          "labels": null,
+          "name": "my-instance",
+          "num_nodes": 1,
+          "timeouts": null
+        },
+        "after_unknown": {
+          "id": true,
+          "processing_units": true,
+          "project": true,
+          "state": true
+        },
+        "before_sensitive": false,
+        "after_sensitive": {}
+      }
     }
   ],
   "configuration": {
-    "provider_config": {
-      "google": {
-        "name": "google",
-        "expressions": {
-          "project": {
-            "constant_value": "{{.Provider.project}}"
-          }
-        }
-      }
-    },
     "root_module": {
       "resources": [
+        {
+          "address": "google_spanner_database.database",
+          "mode": "managed",
+          "type": "google_spanner_database",
+          "name": "database",
+          "provider_config_key": "google",
+          "expressions": {
+            "ddl": {
+              "constant_value": [
+                "CREATE TABLE t1 (t1 INT64 NOT NULL,) PRIMARY KEY(t1)",
+                "CREATE TABLE t2 (t2 INT64 NOT NULL,) PRIMARY KEY(t2)"
+              ]
+            },
+            "deletion_protection": {
+              "constant_value": false
+            },
+            "instance": {
+              "references": [
+                "google_spanner_instance.main.name",
+                "google_spanner_instance.main"
+              ]
+            },
+            "name": {
+              "constant_value": "my-database"
+            }
+          },
+          "schema_version": 0
+        },
         {
           "address": "google_spanner_database_iam_binding.database",
           "mode": "managed",
@@ -91,10 +225,16 @@
           "provider_config_key": "google",
           "expressions": {
             "database": {
-              "constant_value": "my-database"
+              "references": [
+                "google_spanner_database.database.name",
+                "google_spanner_database.database"
+              ]
             },
             "instance": {
-              "constant_value": "my-instance"
+              "references": [
+                "google_spanner_instance.main.name",
+                "google_spanner_instance.main"
+              ]
             },
             "members": {
               "constant_value": [
@@ -106,6 +246,28 @@
             }
           },
           "schema_version": 0
+        },
+        {
+          "address": "google_spanner_instance.main",
+          "mode": "managed",
+          "type": "google_spanner_instance",
+          "name": "main",
+          "provider_config_key": "google",
+          "expressions": {
+            "config": {
+              "constant_value": "regional-europe-west1"
+            },
+            "display_name": {
+              "constant_value": "main-instance"
+            },
+            "name": {
+              "constant_value": "my-instance"
+            },
+            "num_nodes": {
+              "constant_value": 1
+            }
+          },
+          "schema_version": 0
         }
       ]
     }
diff --git a/testdata/templates/example_spanner_database_iam_member.json b/testdata/templates/example_spanner_database_iam_member.json
index 43a38fcc..c299e1cf 100644
--- a/testdata/templates/example_spanner_database_iam_member.json
+++ b/testdata/templates/example_spanner_database_iam_member.json
@@ -1,8 +1,40 @@
 [
   {
-    "name": "//spanner.googleapis.com/placeholder-BpLnfgDs",
+    "name": "//spanner.googleapis.com/projects/{{.Provider.project}}/instances/my-instance",
+    "asset_type": "spanner.googleapis.com/Instance",
+    "ancestry_path": "{{.Ancestry}}/project/{{.Provider.project}}",
+    "resource": {
+      "version": "v1",
+      "discovery_document_uri": "https://www.googleapis.com/discovery/v1/apis/spanner/v1/rest",
+      "discovery_name": "Instance",
+      "parent": "//cloudresourcemanager.googleapis.com/projects/{{.Provider.project}}",
+      "data": {
+        "instance": {
+          "config": "projects/{{.Provider.project}}/instanceConfigs/regional-europe-west1",
+          "displayName": "main-instance",
+          "nodeCount": 1
+        },
+        "instanceId": "my-instance"
+      }
+    }
+  },
+  {
+    "name": "//spanner.googleapis.com/projects/{{.Provider.project}}/instances/my-instance/databases/my-database",
     "asset_type": "spanner.googleapis.com/Database",
     "ancestry_path": "{{.Ancestry}}/project/{{.Provider.project}}",
+    "resource": {
+      "version": "v1",
+      "discovery_document_uri": "https://www.googleapis.com/discovery/v1/apis/spanner/v1/rest",
+      "discovery_name": "Database",
+      "parent": "//cloudresourcemanager.googleapis.com/projects/{{.Provider.project}}",
+      "data": {
+        "createStatement": "CREATE DATABASE `my-database`",
+        "extraStatements": [
+          "CREATE TABLE t1 (t1 INT64 NOT NULL,) PRIMARY KEY(t1)",
+          "CREATE TABLE t2 (t2 INT64 NOT NULL,) PRIMARY KEY(t2)"
+        ]
+      }
+    },
     "iam_policy": {
       "bindings": [
         {
diff --git a/testdata/templates/example_spanner_database_iam_member.tf b/testdata/templates/example_spanner_database_iam_member.tf
index f7da1ce4..109c4db4 100644
--- a/testdata/templates/example_spanner_database_iam_member.tf
+++ b/testdata/templates/example_spanner_database_iam_member.tf
@@ -27,10 +27,26 @@ provider "google" {
   {{if .Provider.credentials }}credentials = "{{.Provider.credentials}}"{{end}}
 }
 
+resource "google_spanner_instance" "main" {
+  name = "my-instance"
+  config       = "regional-europe-west1"
+  display_name = "main-instance"
+  num_nodes    = 1
+}
+
+resource "google_spanner_database" "database" {
+  instance = google_spanner_instance.main.name
+  name     = "my-database"
+  ddl = [
+    "CREATE TABLE t1 (t1 INT64 NOT NULL,) PRIMARY KEY(t1)",
+    "CREATE TABLE t2 (t2 INT64 NOT NULL,) PRIMARY KEY(t2)",
+  ]
+  deletion_protection = false
+}
 
 resource "google_spanner_database_iam_member" "database" {
-  instance = "my-instance"
-  database = "my-database"
+  instance = google_spanner_instance.main.name
+  database = google_spanner_database.database.name
   role     = "roles/compute.networkUser"
   member   = "user:jane@example.com"
 }
diff --git a/testdata/templates/example_spanner_database_iam_member.tfplan.json b/testdata/templates/example_spanner_database_iam_member.tfplan.json
index caa21ef0..e37e6158 100644
--- a/testdata/templates/example_spanner_database_iam_member.tfplan.json
+++ b/testdata/templates/example_spanner_database_iam_member.tfplan.json
@@ -4,6 +4,32 @@
   "planned_values": {
     "root_module": {
       "resources": [
+        {
+          "address": "google_spanner_database.database",
+          "mode": "managed",
+          "type": "google_spanner_database",
+          "name": "database",
+          "provider_name": "registry.terraform.io/hashicorp/google",
+          "schema_version": 0,
+          "values": {
+            "ddl": [
+              "CREATE TABLE t1 (t1 INT64 NOT NULL,) PRIMARY KEY(t1)",
+              "CREATE TABLE t2 (t2 INT64 NOT NULL,) PRIMARY KEY(t2)"
+            ],
+            "deletion_protection": false,
+            "encryption_config": [],
+            "instance": "my-instance",
+            "name": "my-database",
+            "timeouts": null
+          },
+          "sensitive_values": {
+            "ddl": [
+              false,
+              false
+            ],
+            "encryption_config": []
+          }
+        },
         {
           "address": "google_spanner_database_iam_member.database",
           "mode": "managed",
@@ -21,11 +47,71 @@
           "sensitive_values": {
             "condition": []
           }
+        },
+        {
+          "address": "google_spanner_instance.main",
+          "mode": "managed",
+          "type": "google_spanner_instance",
+          "name": "main",
+          "provider_name": "registry.terraform.io/hashicorp/google",
+          "schema_version": 0,
+          "values": {
+            "config": "regional-europe-west1",
+            "display_name": "main-instance",
+            "force_destroy": false,
+            "labels": null,
+            "name": "my-instance",
+            "num_nodes": 1,
+            "timeouts": null
+          },
+          "sensitive_values": {}
         }
       ]
     }
   },
   "resource_changes": [
+    {
+      "address": "google_spanner_database.database",
+      "mode": "managed",
+      "type": "google_spanner_database",
+      "name": "database",
+      "provider_name": "registry.terraform.io/hashicorp/google",
+      "change": {
+        "actions": [
+          "create"
+        ],
+        "before": null,
+        "after": {
+          "ddl": [
+            "CREATE TABLE t1 (t1 INT64 NOT NULL,) PRIMARY KEY(t1)",
+            "CREATE TABLE t2 (t2 INT64 NOT NULL,) PRIMARY KEY(t2)"
+          ],
+          "deletion_protection": false,
+          "encryption_config": [],
+          "instance": "my-instance",
+          "name": "my-database",
+          "timeouts": null
+        },
+        "after_unknown": {
+          "ddl": [
+            false,
+            false
+          ],
+          "encryption_config": [],
+          "id": true,
+          "project": true,
+          "state": true
+        },
+        "before_sensitive": false,
+        "after_sensitive": {
+          "ddl": [
+            false,
+            false
+          ],
+          "encryption_config": []
+        }
+      }
+    },
     {
       "address": "google_spanner_database_iam_member.database",
       "mode": "managed",
@@ -55,21 +141,69 @@
           "condition": []
         }
       }
+    },
+    {
+      "address": "google_spanner_instance.main",
+      "mode": "managed",
+      "type": "google_spanner_instance",
+      "name": "main",
+      "provider_name": "registry.terraform.io/hashicorp/google",
+      "change": {
+        "actions": [
+          "create"
+        ],
+        "before": null,
+        "after": {
+          "config": "regional-europe-west1",
+          "display_name": "main-instance",
+          "force_destroy": false,
+          "labels": null,
+          "name": "my-instance",
+          "num_nodes": 1,
+          "timeouts": null
+        },
+        "after_unknown": {
+          "id": true,
+          "processing_units": true,
+          "project": true,
+          "state": true
+        },
+        "before_sensitive": false,
+        "after_sensitive": {}
+      }
     }
   ],
   "configuration": {
-    "provider_config": {
-      "google": {
-        "name": "google",
-        "expressions": {
-          "project": {
-            "constant_value": "{{.Provider.project}}"
-          }
-        }
-      }
-    },
     "root_module": {
       "resources": [
+        {
+          "address": "google_spanner_database.database",
+          "mode": "managed",
+          "type": "google_spanner_database",
+          "name": "database",
+          "provider_config_key": "google",
+          "expressions": {
+            "ddl": {
+              "constant_value": [
+                "CREATE TABLE t1 (t1 INT64 NOT NULL,) PRIMARY KEY(t1)",
+                "CREATE TABLE t2 (t2 INT64 NOT NULL,) PRIMARY KEY(t2)"
+              ]
+            },
+            "deletion_protection": {
+              "constant_value": false
+            },
+            "instance": {
+              "references": [
+                "google_spanner_instance.main.name",
+                "google_spanner_instance.main"
+              ]
+            },
+            "name": {
+              "constant_value": "my-database"
+            }
+          },
+          "schema_version": 0
+        },
         {
           "address": "google_spanner_database_iam_member.database",
           "mode": "managed",
@@ -78,10 +212,16 @@
           "provider_config_key": "google",
           "expressions": {
             "database": {
-              "constant_value": "my-database"
+              "references": [
+                "google_spanner_database.database.name",
+                "google_spanner_database.database"
+              ]
             },
             "instance": {
-              "constant_value": "my-instance"
+              "references": [
+                "google_spanner_instance.main.name",
+                "google_spanner_instance.main"
+              ]
             },
             "member": {
               "constant_value": "user:jane@example.com"
@@ -91,6 +231,28 @@
             }
           },
           "schema_version": 0
+        },
+        {
+          "address": "google_spanner_instance.main",
+          "mode": "managed",
+          "type": "google_spanner_instance",
+          "name": "main",
+          "provider_config_key": "google",
+          "expressions": {
+            "config": {
+              "constant_value": "regional-europe-west1"
+            },
+            "display_name": {
+              "constant_value": "main-instance"
+            },
+            "name": {
+              "constant_value": "my-instance"
+            },
+            "num_nodes": {
+              "constant_value": 1
+            }
+          },
+          "schema_version": 0
         }
       ]
     }
diff --git a/testdata/templates/example_spanner_database_iam_policy.json b/testdata/templates/example_spanner_database_iam_policy.json
index 8f42a9b3..36751e8e 100644
--- a/testdata/templates/example_spanner_database_iam_policy.json
+++ b/testdata/templates/example_spanner_database_iam_policy.json
@@ -1,8 +1,40 @@
 [
   {
-    "name": "//spanner.googleapis.com/placeholder-BpLnfgDs",
+    "name": "//spanner.googleapis.com/projects/{{.Provider.project}}/instances/my-instance",
+    "asset_type": "spanner.googleapis.com/Instance",
+    "ancestry_path": "{{.Ancestry}}/project/{{.Provider.project}}",
+    "resource": {
+      "version": "v1",
+      "discovery_document_uri": "https://www.googleapis.com/discovery/v1/apis/spanner/v1/rest",
+      "discovery_name": "Instance",
+      "parent": "//cloudresourcemanager.googleapis.com/projects/{{.Provider.project}}",
+      "data": {
+        "instance": {
+          "config": "projects/{{.Provider.project}}/instanceConfigs/regional-europe-west1",
+          "displayName": "main-instance",
+          "nodeCount": 1
+        },
+        "instanceId": "my-instance"
+      }
+    }
+  },
+  {
+    "name": "//spanner.googleapis.com/projects/{{.Provider.project}}/instances/my-instance/databases/my-database",
     "asset_type": "spanner.googleapis.com/Database",
     "ancestry_path": "{{.Ancestry}}/project/{{.Provider.project}}",
+    "resource": {
+      "version": "v1",
+      "discovery_document_uri": "https://www.googleapis.com/discovery/v1/apis/spanner/v1/rest",
+      "discovery_name": "Database",
+      "parent": "//cloudresourcemanager.googleapis.com/projects/{{.Provider.project}}",
+      "data": {
+        "createStatement": "CREATE DATABASE `my-database`",
+        "extraStatements": [
+          "CREATE TABLE t1 (t1 INT64 NOT NULL,) PRIMARY KEY(t1)",
+          "CREATE TABLE t2 (t2 INT64 NOT NULL,) PRIMARY KEY(t2)"
+        ]
+      }
+    },
     "iam_policy": {
       "bindings": [
         {
diff --git a/testdata/templates/example_spanner_database_iam_policy.tf b/testdata/templates/example_spanner_database_iam_policy.tf
index b8ab00d9..4bb2d25a 100644
--- a/testdata/templates/example_spanner_database_iam_policy.tf
+++ b/testdata/templates/example_spanner_database_iam_policy.tf
@@ -27,9 +27,26 @@ provider "google" {
   {{if .Provider.credentials }}credentials = "{{.Provider.credentials}}"{{end}}
 }
 
+resource "google_spanner_instance" "main" {
+  config       = "regional-europe-west1"
+  display_name = "main-instance"
+  num_nodes    = 1
+  name = "my-instance"
+}
+
+resource "google_spanner_database" "database" {
+  instance = google_spanner_instance.main.name
+  name     = "my-database"
+  ddl = [
+    "CREATE TABLE t1 (t1 INT64 NOT NULL,) PRIMARY KEY(t1)",
+    "CREATE TABLE t2 (t2 INT64 NOT NULL,) PRIMARY KEY(t2)",
+  ]
+  deletion_protection = false
+}
+
 resource "google_spanner_database_iam_policy" "database" {
-  instance    = "my-instance"
-  database    = "my-database"
+  instance = google_spanner_instance.main.name
+  database = google_spanner_database.database.name
   policy_data = jsonencode(
     {
       bindings = [
diff --git a/testdata/templates/example_spanner_database_iam_policy.tfplan.json b/testdata/templates/example_spanner_database_iam_policy.tfplan.json
index 7d9d01f7..dc3e6de9 100644
--- a/testdata/templates/example_spanner_database_iam_policy.tfplan.json
+++ b/testdata/templates/example_spanner_database_iam_policy.tfplan.json
@@ -4,6 +4,32 @@
   "planned_values": {
     "root_module": {
       "resources": [
+        {
+          "address": "google_spanner_database.database",
+          "mode": "managed",
+          "type": "google_spanner_database",
+          "name": "database",
+          "provider_name": "registry.terraform.io/hashicorp/google",
+          "schema_version": 0,
+          "values": {
+            "ddl": [
+              "CREATE TABLE t1 (t1 INT64 NOT NULL,) PRIMARY KEY(t1)",
+              "CREATE TABLE t2 (t2 INT64 NOT NULL,) PRIMARY KEY(t2)"
+            ],
+            "deletion_protection": false,
+            "encryption_config": [],
+            "instance": "my-instance",
+            "name": "my-database",
+            "timeouts": null
+          },
+          "sensitive_values": {
+            "ddl": [
+              false,
+              false
+            ],
+            "encryption_config": []
+          }
+        },
         {
           "address": "google_spanner_database_iam_policy.database",
           "mode": "managed",
@@ -17,11 +43,71 @@
             "policy_data": "{\"bindings\":[{\"members\":[\"user:jane@example.com\"],\"role\":\"roles/editor\"}]}"
           },
           "sensitive_values": {}
+        },
+        {
+          "address": "google_spanner_instance.main",
+          "mode": "managed",
+          "type": "google_spanner_instance",
+          "name": "main",
+          "provider_name": "registry.terraform.io/hashicorp/google",
+          "schema_version": 0,
+          "values": {
+            "config": "regional-europe-west1",
+            "display_name": "main-instance",
+            "force_destroy": false,
+            "labels": null,
+            "name": "my-instance",
+            "num_nodes": 1,
+            "timeouts": null
+          },
+          "sensitive_values": {}
         }
       ]
     }
   },
   "resource_changes": [
+    {
+      "address": "google_spanner_database.database",
+      "mode": "managed",
+      "type": "google_spanner_database",
+      "name": "database",
+      "provider_name": "registry.terraform.io/hashicorp/google",
+      "change": {
+        "actions": [
+          "create"
+        ],
+        "before": null,
+        "after": {
+          "ddl": [
+            "CREATE TABLE t1 (t1 INT64 NOT NULL,) PRIMARY KEY(t1)",
+            "CREATE TABLE t2 (t2 INT64 NOT NULL,) PRIMARY KEY(t2)"
+          ],
+          "deletion_protection": false,
+          "encryption_config": [],
+          "instance": "my-instance",
+          "name": "my-database",
+          "timeouts": null
+        },
+        "after_unknown": {
+          "ddl": [
+            false,
+            false
+          ],
+          "encryption_config": [],
+          "id": true,
+          "project": true,
+          "state": true
+        },
+        "before_sensitive": false,
+        "after_sensitive": {
+          "ddl": [
+            false,
+            false
+          ],
+          "encryption_config": []
+        }
+      }
+    },
     {
       "address": "google_spanner_database_iam_policy.database",
       "mode": "managed",
@@ -46,63 +132,69 @@
         "before_sensitive": false,
         "after_sensitive": {}
       }
-    }
-  ],
-  "prior_state": {
-    "format_version": "0.2",
-    "terraform_version": "1.0.10",
-    "values": {
-      "root_module": {
-        "resources": [
-          {
-            "address": "data.google_iam_policy.admin",
-            "mode": "data",
-            "type": "google_iam_policy",
-            "name": "admin",
-            "provider_name": "registry.terraform.io/hashicorp/google",
-            "schema_version": 0,
-            "values": {
-              "audit_config": null,
-              "binding": [
-                {
-                  "condition": [],
-                  "members": [
-                    "user:jane@example.com"
-                  ],
-                  "role": "roles/editor"
-                }
-              ],
-              "id": "1120114865",
-              "policy_data": "{\"bindings\":[{\"members\":[\"user:jane@example.com\"],\"role\":\"roles/editor\"}]}"
-            },
-            "sensitive_values": {
-              "binding": [
-                {
-                  "condition": [],
-                  "members": [
-                    false
-                  ]
-                }
-              ]
-            }
-          }
-        ]
+    },
+    {
+      "address": "google_spanner_instance.main",
+      "mode": "managed",
+      "type": "google_spanner_instance",
+      "name": "main",
+      "provider_name": "registry.terraform.io/hashicorp/google",
+      "change": {
+        "actions": [
+          "create"
+        ],
+        "before": null,
+        "after": {
+          "config": "regional-europe-west1",
+          "display_name": "main-instance",
+          "force_destroy": false,
+          "labels": null,
+          "name": "my-instance",
+          "num_nodes": 1,
+          "timeouts": null
+        },
+        "after_unknown": {
+          "id": true,
+          "processing_units": true,
+          "project": true,
+          "state": true
+        },
+        "before_sensitive": false,
+        "after_sensitive": {}
       }
     }
-  },
+  ],
   "configuration": {
-    "provider_config": {
-      "google": {
-        "name": "google",
-        "expressions": {
-          "project": {
-            "constant_value": "{{.Provider.project}}"
-          }
-        }
-      }
-    },
     "root_module": {
       "resources": [
+        {
+          "address": "google_spanner_database.database",
+          "mode": "managed",
+          "type": "google_spanner_database",
+          "name": "database",
+          "provider_config_key": "google",
+          "expressions": {
+            "ddl": {
+              "constant_value": [
+                "CREATE TABLE t1 (t1 INT64 NOT NULL,) PRIMARY KEY(t1)",
+                "CREATE TABLE t2 (t2 INT64 NOT NULL,) PRIMARY KEY(t2)"
+              ]
+            },
+            "deletion_protection": {
+              "constant_value": false
+            },
+            "instance": {
+              "references": [
+                "google_spanner_instance.main.name",
+                "google_spanner_instance.main"
+              ]
+            },
+            "name": {
+              "constant_value": "my-database"
+            }
+          },
+          "schema_version": 0
+        },
         {
           "address": "google_spanner_database_iam_policy.database",
           "mode": "managed",
@@ -111,39 +203,40 @@
           "provider_config_key": "google",
           "expressions": {
             "database": {
-              "constant_value": "my-database"
+              "references": [
+                "google_spanner_database.database.name",
+                "google_spanner_database.database"
+              ]
             },
             "instance": {
-              "constant_value": "my-instance"
-            },
-            "policy_data": {
               "references": [
-                "data.google_iam_policy.admin.policy_data",
-                "data.google_iam_policy.admin"
+                "google_spanner_instance.main.name",
+                "google_spanner_instance.main"
               ]
-            }
+            },
+            "policy_data": {}
           },
           "schema_version": 0
         },
         {
-          "address": "data.google_iam_policy.admin",
-          "mode": "data",
-          "type": "google_iam_policy",
-          "name": "admin",
+          "address": "google_spanner_instance.main",
+          "mode": "managed",
+          "type": "google_spanner_instance",
+          "name": "main",
           "provider_config_key": "google",
           "expressions": {
-            "binding": [
-              {
-                "members": {
-                  "constant_value": [
-                    "user:jane@example.com"
-                  ]
-                },
-                "role": {
-                  "constant_value": "roles/editor"
-                }
-              }
-            ]
+            "config": {
+              "constant_value": "regional-europe-west1"
+            },
+            "display_name": {
+              "constant_value": "main-instance"
+            },
+            "name": {
+              "constant_value": "my-instance"
+            },
+            "num_nodes": {
+              "constant_value": 1
+            }
           },
           "schema_version": 0
         }
diff --git a/testdata/templates/example_spanner_instance_iam_binding.json b/testdata/templates/example_spanner_instance_iam_binding.json
index c1cc37e2..73a1d166 100644
--- a/testdata/templates/example_spanner_instance_iam_binding.json
+++ b/testdata/templates/example_spanner_instance_iam_binding.json
@@ -1,8 +1,22 @@
 [
   {
-    "name": "//spanner.googleapis.com/placeholder-BpLnfgDs",
+    "name": "//spanner.googleapis.com/projects/{{.Provider.project}}/instances/spanner-instance",
     "asset_type": "spanner.googleapis.com/Instance",
     "ancestry_path": "{{.Ancestry}}/project/{{.Provider.project}}",
+    "resource": {
+      "version": "v1",
+      "discovery_document_uri": "https://www.googleapis.com/discovery/v1/apis/spanner/v1/rest",
+      "discovery_name": "Instance",
+      "parent": "//cloudresourcemanager.googleapis.com/projects/{{.Provider.project}}",
+      "data": {
+        "instance": {
+          "config": "projects/{{.Provider.project}}/instanceConfigs/regional-us-central1",
+          "displayName": "spanner-instance",
+          "nodeCount": 1
+        },
+        "instanceId": "spanner-instance"
+      }
+    },
     "iam_policy": {
       "bindings": [
         {
diff --git a/testdata/templates/example_spanner_instance_iam_binding.tf b/testdata/templates/example_spanner_instance_iam_binding.tf
index e7db4cb9..f2e46c69 100644
--- a/testdata/templates/example_spanner_instance_iam_binding.tf
+++ b/testdata/templates/example_spanner_instance_iam_binding.tf
@@ -27,8 +27,15 @@ provider "google" {
   {{if .Provider.credentials }}credentials = "{{.Provider.credentials}}"{{end}}
 }
 
+resource "google_spanner_instance" "spanner-instance" {
+  name         = "spanner-instance"
+  display_name = "spanner-instance"
+  config       = "regional-us-central1"
+  num_nodes    = 1
+}
+
 resource "google_spanner_instance_iam_binding" "instance" {
-  instance = "my-instance"
+  instance = google_spanner_instance.spanner-instance.name
   role     = "roles/compute.networkUser"
 
   members = [
diff --git a/testdata/templates/example_spanner_instance_iam_binding.tfplan.json b/testdata/templates/example_spanner_instance_iam_binding.tfplan.json
index edca0192..0eea8322 100644
--- a/testdata/templates/example_spanner_instance_iam_binding.tfplan.json
+++ b/testdata/templates/example_spanner_instance_iam_binding.tfplan.json
@@ -4,6 +4,24 @@
   "planned_values": {
     "root_module": {
       "resources": [
+        {
+          "address": "google_spanner_instance.spanner-instance",
+          "mode": "managed",
+          "type": "google_spanner_instance",
+          "name": "spanner-instance",
+          "provider_name": "registry.terraform.io/hashicorp/google",
+          "schema_version": 0,
+          "values": {
+            "config": "regional-us-central1",
+            "display_name": "spanner-instance",
+            "force_destroy": false,
+            "labels": null,
+            "name": "spanner-instance",
+            "num_nodes": 1,
+            "timeouts": null
+          },
+          "sensitive_values": {}
+        },
         {
           "address": "google_spanner_instance_iam_binding.instance",
           "mode": "managed",
@@ -13,7 +31,7 @@
           "schema_version": 0,
           "values": {
             "condition": [],
-            "instance": "my-instance",
+            "instance": "spanner-instance",
             "members": [
               "user:jane@example.com"
             ],
@@ -30,6 +48,36 @@
     }
   },
   "resource_changes": [
+    {
+      "address": "google_spanner_instance.spanner-instance",
+      "mode": "managed",
+      "type": "google_spanner_instance",
+      "name": "spanner-instance",
+      "provider_name": "registry.terraform.io/hashicorp/google",
+      "change": {
+        "actions": [
+          "create"
+        ],
+        "before": null,
+        "after": {
+          "config": "regional-us-central1",
+          "display_name": "spanner-instance",
+          "force_destroy": false,
+          "labels": null,
+          "name": "spanner-instance",
+          "num_nodes": 1,
+          "timeouts": null
+        },
+        "after_unknown": {
+          "id": true,
+          "processing_units": true,
+          "project": true,
+          "state": true
+        },
+        "before_sensitive": false,
+        "after_sensitive": {}
+      }
+    },
     {
       "address": "google_spanner_instance_iam_binding.instance",
       "mode": "managed",
@@ -43,7 +91,7 @@
         "before": null,
         "after": {
           "condition": [],
-          "instance": "my-instance",
+          "instance": "spanner-instance",
           "members": [
             "user:jane@example.com"
           ],
@@ -69,18 +117,30 @@
     }
   ],
   "configuration": {
-    "provider_config": {
-      "google": {
-        "name": "google",
-        "expressions": {
-          "project": {
-            "constant_value": "{{.Provider.project}}"
-          }
-        }
-      }
-    },
     "root_module": {
       "resources": [
+        {
+          "address": "google_spanner_instance.spanner-instance",
+          "mode": "managed",
+          "type": "google_spanner_instance",
+          "name": "spanner-instance",
+          "provider_config_key": "google",
+          "expressions": {
+            "config": {
+              "constant_value": "regional-us-central1"
+            },
+            "display_name": {
+              "constant_value": "spanner-instance"
+            },
+            "name": {
+              "constant_value": "spanner-instance"
+            },
+            "num_nodes": {
+              "constant_value": 1
+            }
+          },
+          "schema_version": 0
+        },
         {
           "address": "google_spanner_instance_iam_binding.instance",
           "mode": "managed",
@@ -89,7 +149,10 @@
           "provider_config_key": "google",
           "expressions": {
             "instance": {
-              "constant_value": "my-instance"
+              "references": [
+                "google_spanner_instance.spanner-instance.name",
+                "google_spanner_instance.spanner-instance"
+              ]
             },
             "members": {
               "constant_value": [
diff --git a/testdata/templates/example_spanner_instance_iam_member.json b/testdata/templates/example_spanner_instance_iam_member.json
index c1cc37e2..73a1d166 100644
--- a/testdata/templates/example_spanner_instance_iam_member.json
+++ b/testdata/templates/example_spanner_instance_iam_member.json
@@ -1,8 +1,22 @@
 [
   {
-    "name": "//spanner.googleapis.com/placeholder-BpLnfgDs",
+    "name": "//spanner.googleapis.com/projects/{{.Provider.project}}/instances/spanner-instance",
     "asset_type": "spanner.googleapis.com/Instance",
     "ancestry_path": "{{.Ancestry}}/project/{{.Provider.project}}",
+    "resource": {
+      "version": "v1",
+      "discovery_document_uri": "https://www.googleapis.com/discovery/v1/apis/spanner/v1/rest",
+      "discovery_name": "Instance",
+      "parent": "//cloudresourcemanager.googleapis.com/projects/{{.Provider.project}}",
+      "data": {
+        "instance": {
+          "config": "projects/{{.Provider.project}}/instanceConfigs/regional-us-central1",
+          "displayName": "spanner-instance",
+          "nodeCount": 1
+        },
+        "instanceId": "spanner-instance"
+      }
+    },
     "iam_policy": {
       "bindings": [
         {
diff --git a/testdata/templates/example_spanner_instance_iam_member.tf b/testdata/templates/example_spanner_instance_iam_member.tf
index 60cf6bab..1f417184 100644
--- a/testdata/templates/example_spanner_instance_iam_member.tf
+++ b/testdata/templates/example_spanner_instance_iam_member.tf
@@ -27,8 +27,15 @@ provider "google" {
   {{if .Provider.credentials }}credentials = "{{.Provider.credentials}}"{{end}}
 }
 
+resource "google_spanner_instance" "spanner-instance" {
+  name         = "spanner-instance"
+  display_name = "spanner-instance"
+  config       = "regional-us-central1"
+  num_nodes    = 1
+}
+
 resource "google_spanner_instance_iam_member" "instance" {
-  instance = "my-instance"
+  instance = google_spanner_instance.spanner-instance.name
   role     = "roles/compute.networkUser"
   member   = "user:jane@example.com"
 }
diff --git a/testdata/templates/example_spanner_instance_iam_member.tfplan.json b/testdata/templates/example_spanner_instance_iam_member.tfplan.json
index 6f529373..371286e9 100644
--- a/testdata/templates/example_spanner_instance_iam_member.tfplan.json
+++ b/testdata/templates/example_spanner_instance_iam_member.tfplan.json
@@ -4,6 +4,24 @@
   "planned_values": {
     "root_module": {
       "resources": [
+        {
+          "address": "google_spanner_instance.spanner-instance",
+          "mode": "managed",
+          "type": "google_spanner_instance",
+          "name": "spanner-instance",
+          "provider_name": "registry.terraform.io/hashicorp/google",
+          "schema_version": 0,
+          "values": {
+            "config": "regional-us-central1",
+            "display_name": "spanner-instance",
+            "force_destroy": false,
+            "labels": null,
+            "name": "spanner-instance",
+            "num_nodes": 1,
+            "timeouts": null
+          },
+          "sensitive_values": {}
+        },
         {
           "address": "google_spanner_instance_iam_member.instance",
           "mode": "managed",
@@ -13,7 +31,7 @@
           "schema_version": 0,
           "values": {
             "condition": [],
-            "instance": "my-instance",
+            "instance": "spanner-instance",
             "member": "user:jane@example.com",
             "role": "roles/compute.networkUser"
           },
@@ -25,6 +43,36 @@
     }
   },
   "resource_changes": [
+    {
+      "address": "google_spanner_instance.spanner-instance",
+      "mode": "managed",
+      "type": "google_spanner_instance",
+      "name": "spanner-instance",
+      "provider_name": "registry.terraform.io/hashicorp/google",
+      "change": {
+        "actions": [
+          "create"
+        ],
+        "before": null,
+        "after": {
+          "config": "regional-us-central1",
+          "display_name": "spanner-instance",
+          "force_destroy": false,
+          "labels": null,
+          "name": "spanner-instance",
+          "num_nodes": 1,
+          "timeouts": null
+        },
+        "after_unknown": {
+          "id": true,
+          "processing_units": true,
+          "project": true,
+          "state": true
+        },
+        "before_sensitive": false,
+        "after_sensitive": {}
+      }
+    },
     {
       "address": "google_spanner_instance_iam_member.instance",
       "mode": "managed",
@@ -38,7 +86,7 @@
         "before": null,
         "after": {
           "condition": [],
-          "instance": "my-instance",
+          "instance": "spanner-instance",
           "member": "user:jane@example.com",
           "role": "roles/compute.networkUser"
         },
@@ -56,18 +104,30 @@
     }
   ],
   "configuration": {
-    "provider_config": {
-      "google": {
-        "name": "google",
-        "expressions": {
-          "project": {
-            "constant_value": "{{.Provider.project}}"
-          }
-        }
-      }
-    },
     "root_module": {
       "resources": [
+        {
+          "address": "google_spanner_instance.spanner-instance",
+          "mode": "managed",
+          "type": "google_spanner_instance",
+          "name": "spanner-instance",
+          "provider_config_key": "google",
+          "expressions": {
+            "config": {
+              "constant_value": "regional-us-central1"
+            },
+            "display_name": {
+              "constant_value": "spanner-instance"
+            },
+            "name": {
+              "constant_value": "spanner-instance"
+            },
+            "num_nodes": {
+              "constant_value": 1
+            }
+          },
+          "schema_version": 0
+        },
         {
           "address": "google_spanner_instance_iam_member.instance",
           "mode": "managed",
@@ -76,7 +136,10 @@
           "provider_config_key": "google",
           "expressions": {
             "instance": {
-              "constant_value": "my-instance"
+              "references": [
+                "google_spanner_instance.spanner-instance.name",
+                "google_spanner_instance.spanner-instance"
+              ]
             },
             "member": {
               "constant_value": "user:jane@example.com"
diff --git a/testdata/templates/example_spanner_instance_iam_policy.json b/testdata/templates/example_spanner_instance_iam_policy.json
index f7beb4e4..2647e1bd 100644
--- a/testdata/templates/example_spanner_instance_iam_policy.json
+++ b/testdata/templates/example_spanner_instance_iam_policy.json
@@ -1,8 +1,22 @@
 [
   {
-    "name": "//spanner.googleapis.com/placeholder-BpLnfgDs",
+    "name": "//spanner.googleapis.com/projects/{{.Provider.project}}/instances/spanner-instance",
     "asset_type": "spanner.googleapis.com/Instance",
     "ancestry_path": "{{.Ancestry}}/project/{{.Provider.project}}",
+    "resource": {
+      "version": "v1",
+      "discovery_document_uri": "https://www.googleapis.com/discovery/v1/apis/spanner/v1/rest",
+      "discovery_name": "Instance",
+      "parent": "//cloudresourcemanager.googleapis.com/projects/{{.Provider.project}}",
+      "data": {
+        "instance": {
+          "config": "projects/{{.Provider.project}}/instanceConfigs/regional-us-central1",
+          "displayName": "spanner-instance",
+          "nodeCount": 1
+        },
+        "instanceId": "spanner-instance"
+      }
+    },
     "iam_policy": {
       "bindings": [
         {
diff --git a/testdata/templates/example_spanner_instance_iam_policy.tf b/testdata/templates/example_spanner_instance_iam_policy.tf
index 70bbe732..e62efc74 100644
--- a/testdata/templates/example_spanner_instance_iam_policy.tf
+++ b/testdata/templates/example_spanner_instance_iam_policy.tf
@@ -27,8 +27,15 @@ provider "google" {
   {{if .Provider.credentials }}credentials = "{{.Provider.credentials}}"{{end}}
 }
 
+resource "google_spanner_instance" "spanner-instance" {
+  name         = "spanner-instance"
+  display_name = "spanner-instance"
+  config       = "regional-us-central1"
+  num_nodes    = 1
+}
+
 resource "google_spanner_instance_iam_policy" "instance" {
-  instance    = "my-instance"
+  instance = google_spanner_instance.spanner-instance.name
   policy_data = jsonencode(
     {
       bindings = [
diff --git a/testdata/templates/example_spanner_instance_iam_policy.tfplan.json b/testdata/templates/example_spanner_instance_iam_policy.tfplan.json
index a4c72312..61d97ab0 100644
--- a/testdata/templates/example_spanner_instance_iam_policy.tfplan.json
+++ b/testdata/templates/example_spanner_instance_iam_policy.tfplan.json
@@ -4,6 +4,24 @@
   "planned_values": {
     "root_module": {
       "resources": [
+        {
+          "address": "google_spanner_instance.spanner-instance",
+          "mode": "managed",
+          "type": "google_spanner_instance",
+          "name": "spanner-instance",
+          "provider_name": "registry.terraform.io/hashicorp/google",
+          "schema_version": 0,
+          "values": {
+            "config": "regional-us-central1",
+            "display_name": "spanner-instance",
+            "force_destroy": false,
+            "labels": null,
+            "name": "spanner-instance",
+            "num_nodes": 1,
+            "timeouts": null
+          },
+          "sensitive_values": {}
+        },
         {
           "address": "google_spanner_instance_iam_policy.instance",
           "mode": "managed",
@@ -12,7 +30,7 @@
           "provider_name": "registry.terraform.io/hashicorp/google",
           "schema_version": 0,
           "values": {
-            "instance": "my-instance",
+            "instance": "spanner-instance",
             "policy_data": "{\"bindings\":[{\"members\":[\"user:jane@example.com\"],\"role\":\"roles/editor\"}]}"
           },
           "sensitive_values": {}
@@ -21,6 +39,36 @@
     }
   },
   "resource_changes": [
+    {
+      "address": "google_spanner_instance.spanner-instance",
+      "mode": "managed",
+      "type": "google_spanner_instance",
+      "name": "spanner-instance",
+      "provider_name": "registry.terraform.io/hashicorp/google",
+      "change": {
+        "actions": [
+          "create"
+        ],
+        "before": null,
+        "after": {
+          "config": "regional-us-central1",
+          "display_name": "spanner-instance",
+          "force_destroy": false,
+          "labels": null,
+          "name": "spanner-instance",
+          "num_nodes": 1,
+          "timeouts": null
+        },
+        "after_unknown": {
+          "id": true,
+          "processing_units": true,
+          "project": true,
+          "state": true
+        },
+        "before_sensitive": false,
+        "after_sensitive": {}
+      }
+    },
     {
       "address": "google_spanner_instance_iam_policy.instance",
       "mode": "managed",
@@ -33,7 +81,7 @@
         ],
         "before": null,
         "after": {
-          "instance": "my-instance",
+          "instance": "spanner-instance",
           "policy_data": "{\"bindings\":[{\"members\":[\"user:jane@example.com\"],\"role\":\"roles/editor\"}]}"
         },
         "after_unknown": {
@@ -47,18 +95,30 @@
     }
   ],
   "configuration": {
-    "provider_config": {
-      "google": {
-        "name": "google",
-        "expressions": {
-          "project": {
-            "constant_value": "{{.Provider.project}}"
-          }
-        }
-      }
-    },
     "root_module": {
       "resources": [
+        {
+          "address": "google_spanner_instance.spanner-instance",
+          "mode": "managed",
+          "type": "google_spanner_instance",
+          "name": "spanner-instance",
+          "provider_config_key": "google",
+          "expressions": {
+            "config": {
+              "constant_value": "regional-us-central1"
+            },
+            "display_name": {
+              "constant_value": "spanner-instance"
+            },
+            "name": {
+              "constant_value": "spanner-instance"
+            },
+            "num_nodes": {
+              "constant_value": 1
+            }
+          },
+          "schema_version": 0
+        },
         {
           "address": "google_spanner_instance_iam_policy.instance",
           "mode": "managed",
@@ -67,7 +127,10 @@
           "provider_config_key": "google",
           "expressions": {
             "instance": {
-              "constant_value": "my-instance"
+              "references": [
+                "google_spanner_instance.spanner-instance.name",
+                "google_spanner_instance.spanner-instance"
+              ]
             },
             "policy_data": {}
           },