From 4bf24d5f973820f28086ed38fec241c43523bfb0 Mon Sep 17 00:00:00 2001 From: Travis Truman Date: Tue, 14 Jul 2015 13:40:58 -0400 Subject: [PATCH 1/2] Clarifying the resource state persistence mechanism for custom Provider/Resource authors --- website/source/docs/plugins/provider.html.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/website/source/docs/plugins/provider.html.md b/website/source/docs/plugins/provider.html.md index 5c3c720be..780d347a0 100644 --- a/website/source/docs/plugins/provider.html.md +++ b/website/source/docs/plugins/provider.html.md @@ -142,7 +142,11 @@ The CRUD operations in more detail, along with their contracts: * `Create` - This is called to create a new instance of the resource. Terraform guarantees that an existing ID is not set on the resource - data. That is, you're working with a new resource. + data. That is, you're working with a new resource. Therefore, you are + responsible for calling `setId` on your `schema.ResourceData` using a + value suitable for your resource. This ensures whatever resource + state you set on `schema.ResourceData` will be persisted in local state. + If you neglect to `setId`, no resource state will be persisted. * `Read` - This is called to resync the local state with the remote state. Terraform guarantees that an existing ID will be set. This ID should be From d7e0e3fbe87289c74817b474b8008dedeac14d92 Mon Sep 17 00:00:00 2001 From: Travis Truman Date: Sun, 19 Jul 2015 14:15:56 -0400 Subject: [PATCH 2/2] Responding to feedback --- website/source/docs/plugins/provider.html.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/website/source/docs/plugins/provider.html.md b/website/source/docs/plugins/provider.html.md index 780d347a0..1ca41655b 100644 --- a/website/source/docs/plugins/provider.html.md +++ b/website/source/docs/plugins/provider.html.md @@ -143,10 +143,10 @@ The CRUD operations in more detail, along with their contracts: * `Create` - This is called to create a new instance of the resource. Terraform guarantees that an existing ID is not set on the resource data. That is, you're working with a new resource. Therefore, you are - responsible for calling `setId` on your `schema.ResourceData` using a + responsible for calling `SetId` on your `schema.ResourceData` using a value suitable for your resource. This ensures whatever resource state you set on `schema.ResourceData` will be persisted in local state. - If you neglect to `setId`, no resource state will be persisted. + If you neglect to `SetId`, no resource state will be persisted. * `Read` - This is called to resync the local state with the remote state. Terraform guarantees that an existing ID will be set. This ID should be @@ -164,7 +164,8 @@ The CRUD operations in more detail, along with their contracts: * `Exists` - This is called to verify a resource still exists. It is called prior to `Read`, and lowers the burden of `Read` to be able - to assume the resource exists. + to assume the resource exists. If the resource is no longer present in + remote state, calling `SetId` with an empty string will signal its removal. ## Schemas