import ( "github.com/hashicorp/terraform/helper/schema" "github.com/hashicorp/terraform/helper/schema/terraform" ) func resourceMyResource() *schema.Resource { return &schema.Resource{ // ... // SetConnInfo allows resource data to be populated with connection information SetConnInfo: resourceMyResourceSetConnInfo, // ... } } func resourceMyResourceSetConnInfo(d *schema.ResourceData, m interface{}) error { // Set the connection information for the resource d.SetConnInfo(map[string]string{ "username": "myusername", "password": "mypassword", }) return nil }
import ( "github.com/hashicorp/terraform/helper/schema" "github.com/hashicorp/terraform/helper/schema/terraform" ) func resourceMyResource() *schema.Resource { return &schema.Resource{ // ... // SetConnInfo allows resource data to be populated with connection information SetConnInfo: resourceMyResourceSetConnInfo, // ... } } func resourceMyResourceSetConnInfo(d *schema.ResourceData, m interface{}) error { // Set the connection information for the resource using other data in the ResourceData object hostname := d.Get("hostname").(string) username := d.Get("username").(string) password := d.Get("password").(string) d.SetConnInfo(map[string]string{ "hostname": hostname, "username": username, "password": password, }) return nil }This example shows how to use SetConnInfo to set connection information for a resource based on other data in the ResourceData object, specifically the hostname, username, and password.