本文整理匯總了Golang中github.com/hashicorp/terraform/helper/schema.ResourceData.SetConnInfo方法的典型用法代碼示例。如果您正苦於以下問題:Golang ResourceData.SetConnInfo方法的具體用法?Golang ResourceData.SetConnInfo怎麽用?Golang ResourceData.SetConnInfo使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/hashicorp/terraform/helper/schema.ResourceData
的用法示例。
在下文中一共展示了ResourceData.SetConnInfo方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: resourceVultrServerRead
func resourceVultrServerRead(d *schema.ResourceData, meta interface{}) error {
client := meta.(*lib.Client)
server, err := client.GetServer(d.Id())
if err != nil {
// check if the server not longer exists.
if err.Error() == "Invalid server." {
d.SetId("")
return nil
}
return fmt.Errorf("Error retrieving server: %s", err)
}
d.Set("name", server.Name)
d.Set("region_id", server.RegionID)
d.Set("plan_id", server.PlanID)
d.Set("status", server.Status)
d.Set("power_status", server.PowerStatus)
d.Set("default_password", server.DefaultPassword)
d.Set("ipv4_address", server.MainIP)
d.Set("ipv6_address", server.MainIPV6)
d.Set("ipv4_private_address", server.InternalIP)
d.SetConnInfo(map[string]string{
"type": "ssh",
"host": server.MainIP,
"password": server.DefaultPassword,
})
return nil
}
示例2: resourceScalewayServerRead
func resourceScalewayServerRead(d *schema.ResourceData, m interface{}) error {
scaleway := m.(*Client).scaleway
server, err := scaleway.GetServer(d.Id())
if err != nil {
if serr, ok := err.(api.ScalewayAPIError); ok {
log.Printf("[DEBUG] Error reading server: %q\n", serr.APIMessage)
if serr.StatusCode == 404 {
d.SetId("")
return nil
}
}
return err
}
d.Set("private_ip", server.PrivateIP)
d.Set("public_ip", server.PublicAddress.IP)
d.Set("state", server.State)
d.Set("state_detail", server.StateDetail)
d.Set("tags", server.Tags)
d.SetConnInfo(map[string]string{
"type": "ssh",
"host": server.PublicAddress.IP,
})
return nil
}
示例3: resourceServerRead
func resourceServerRead(d *schema.ResourceData, m interface{}) error {
scaleway := m.(*api.ScalewayAPI)
server, err := scaleway.GetServer(d.Id())
if err != nil {
// TODO: make sure it's ScalewayAPIError or it might crash
serr := err.(api.ScalewayAPIError)
// if the resource was destroyed, destroy the resource locally
if serr.StatusCode == 404 {
d.SetId("")
return nil
}
return err
}
// S.t. it's compactible with terraform-ansible
d.Set("ipv4_address_private", server.PrivateIP)
d.Set("state", server.State)
d.Set("state_detail", server.StateDetail)
d.SetConnInfo(map[string]string{
"type": "ssh",
"host": server.PublicAddress.IP,
})
// TODO: set more fields
return nil
}
示例4: resourceLxdContainerRead
func resourceLxdContainerRead(d *schema.ResourceData, meta interface{}) error {
client := meta.(*LxdProvider).Client
sshIP := ""
gotIp := false
cycles := 0
// wait for NIC to come up and get IP from DHCP
for !gotIp && cycles < 15 {
cycles += 1
ct, _ := client.ContainerState(d.Get("name").(string))
d.Set("status", ct.Status)
for iface, net := range ct.Network {
if iface != "lo" {
for _, ip := range net.Addresses {
if ip.Family == "inet" {
d.Set("ip_address", ip.Address)
d.Set("mac_address", net.Hwaddr)
gotIp = true
}
}
}
}
time.Sleep(1 * time.Second)
}
// Initialize the connection info
d.SetConnInfo(map[string]string{
"type": "ssh",
"host": sshIP,
})
return nil
}
示例5: resourceVMRead
func resourceVMRead(d *schema.ResourceData, meta interface{}) error {
vm, err := vbox.GetMachine(d.Id())
if err != nil {
/* VM no longer exist */
if err == vbox.ErrMachineNotExist {
d.SetId("")
return nil
}
return err
}
// if vm.State != vbox.Running {
// setState(d, vm.State)
// return nil
// }
setState(d, vm.State)
d.Set("name", vm.Name)
d.Set("cpus", vm.CPUs)
bytes := uint64(vm.Memory) * humanize.MiByte
repr := humanize.IBytes(bytes)
d.Set("memory", strings.ToLower(repr))
userData, err := vm.GetExtraData("user_data")
if err != nil {
return err
}
if userData != nil && *userData != "" {
d.Set("user_data", *userData)
}
err = net_vbox_to_tf(vm, d)
if err != nil {
return err
}
/* Set connection info to first non NAT IPv4 address */
for i, nic := range vm.NICs {
if nic.Network == vbox.NICNetNAT {
continue
}
availKey := fmt.Sprintf("network_adapter.%d.ipv4_address_available", i)
if d.Get(availKey).(string) != "yes" {
continue
}
ipv4Key := fmt.Sprintf("network_adapter.%d.ipv4_address", i)
ipv4 := d.Get(ipv4Key).(string)
if ipv4 == "" {
continue
}
d.SetConnInfo(map[string]string{
"type": "ssh",
"host": ipv4,
})
break
}
return nil
}
示例6: resourceDigitalOceanDropletRead
func resourceDigitalOceanDropletRead(d *schema.ResourceData, meta interface{}) error {
client := meta.(*godo.Client)
id, err := strconv.Atoi(d.Id())
if err != nil {
return fmt.Errorf("invalid droplet id: %v", err)
}
// Retrieve the droplet properties for updating the state
droplet, resp, err := client.Droplets.Get(id)
if err != nil {
// check if the droplet no longer exists.
if resp.StatusCode == 404 {
log.Printf("[WARN] DigitalOcean Droplet (%s) not found", d.Id())
d.SetId("")
return nil
}
return fmt.Errorf("Error retrieving droplet: %s", err)
}
if droplet.Image.Slug != "" {
d.Set("image", droplet.Image.Slug)
} else {
d.Set("image", droplet.Image.ID)
}
d.Set("name", droplet.Name)
d.Set("region", droplet.Region.Slug)
d.Set("size", droplet.Size.Slug)
d.Set("status", droplet.Status)
d.Set("locked", strconv.FormatBool(droplet.Locked))
if publicIPv6 := findIPv6AddrByType(droplet, "public"); publicIPv6 != "" {
d.Set("ipv6", true)
d.Set("ipv6_address", publicIPv6)
d.Set("ipv6_address_private", findIPv6AddrByType(droplet, "private"))
}
d.Set("ipv4_address", findIPv4AddrByType(droplet, "public"))
if privateIPv4 := findIPv4AddrByType(droplet, "private"); privateIPv4 != "" {
d.Set("private_networking", true)
d.Set("ipv4_address_private", privateIPv4)
}
// Initialize the connection info
d.SetConnInfo(map[string]string{
"type": "ssh",
"host": findIPv4AddrByType(droplet, "public"),
})
return nil
}
示例7: resourcePacketDeviceRead
func resourcePacketDeviceRead(d *schema.ResourceData, meta interface{}) error {
client := meta.(*packngo.Client)
// Retrieve the device properties for updating the state
device, _, err := client.Devices.Get(d.Id())
if err != nil {
return fmt.Errorf("Error retrieving device: %s", err)
}
d.Set("name", device.Hostname)
d.Set("plan", device.Plan.Slug)
d.Set("facility", device.Facility.Code)
d.Set("operating_system", device.OS.Slug)
d.Set("state", device.State)
d.Set("billing_cycle", device.BillingCycle)
d.Set("locked", device.Locked)
d.Set("created", device.Created)
d.Set("updated", device.Updated)
tags := make([]string, 0)
for _, tag := range device.Tags {
tags = append(tags, tag)
}
d.Set("tags", tags)
provisionerAddress := ""
networks := make([]map[string]interface{}, 0, 1)
for _, ip := range device.Network {
network := make(map[string]interface{})
network["address"] = ip.Address
network["gateway"] = ip.Gateway
network["family"] = ip.Family
network["cidr"] = ip.Cidr
network["public"] = ip.Public
networks = append(networks, network)
if ip.Family == 4 && ip.Public == true {
provisionerAddress = ip.Address
}
}
d.Set("network", networks)
log.Printf("[DEBUG] Provisioner Address set to %v", provisionerAddress)
if provisionerAddress != "" {
d.SetConnInfo(map[string]string{
"type": "ssh",
"host": provisionerAddress,
})
}
return nil
}
示例8: resourceComputeInstanceRead
func resourceComputeInstanceRead(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
instance, err := config.clientCompute.Instances.Get(
config.Project, d.Get("zone").(string), d.Id()).Do()
if err != nil {
if gerr, ok := err.(*googleapi.Error); ok && gerr.Code == 404 {
// The resource doesn't exist anymore
d.SetId("")
return nil
}
return fmt.Errorf("Error reading instance: %s", err)
}
d.Set("can_ip_forward", instance.CanIpForward)
// Set the networks
externalIP := ""
for i, iface := range instance.NetworkInterfaces {
prefix := fmt.Sprintf("network.%d", i)
d.Set(prefix+".name", iface.Name)
// Use the first external IP found for the default connection info.
natIP := resourceInstanceNatIP(iface)
if externalIP == "" && natIP != "" {
externalIP = natIP
}
d.Set(prefix+".external_address", natIP)
d.Set(prefix+".internal_address", iface.NetworkIP)
}
// Initialize the connection info
d.SetConnInfo(map[string]string{
"type": "ssh",
"host": externalIP,
})
// Set the metadata fingerprint if there is one.
if instance.Metadata != nil {
d.Set("metadata_fingerprint", instance.Metadata.Fingerprint)
}
// Set the tags fingerprint if there is one.
if instance.Tags != nil {
d.Set("tags_fingerprint", instance.Tags.Fingerprint)
}
return nil
}
示例9: resourceServerCreate
func resourceServerCreate(d *schema.ResourceData, m interface{}) error {
address := d.Get("address").(string)
d.Set("increment", d.Get("increment").(string))
d.SetId(address)
d.SetConnInfo(map[string]string{
"type": "ssh",
"host": address,
})
log.Printf("[DEBUG] :::::::::::::::::::::::::: ")
log.Printf("%+v\n", d)
log.Printf("[DEBUG] :::::::::::::::::::::::::: ")
return nil
}
示例10: resourceDigitalOceanDropletRead
func resourceDigitalOceanDropletRead(d *schema.ResourceData, meta interface{}) error {
client := meta.(*digitalocean.Client)
// Retrieve the droplet properties for updating the state
droplet, err := client.RetrieveDroplet(d.Id())
if err != nil {
// check if the droplet no longer exists.
if err.Error() == "Error retrieving droplet: API Error: 404 Not Found" {
d.SetId("")
return nil
}
return fmt.Errorf("Error retrieving droplet: %s", err)
}
if droplet.ImageSlug() != "" {
d.Set("image", droplet.ImageSlug())
} else {
d.Set("image", droplet.ImageId())
}
d.Set("name", droplet.Name)
d.Set("region", droplet.RegionSlug())
d.Set("size", droplet.SizeSlug)
d.Set("status", droplet.Status)
d.Set("locked", droplet.IsLocked())
if droplet.IPV6Address("public") != "" {
d.Set("ipv6", true)
d.Set("ipv6_address", droplet.IPV6Address("public"))
d.Set("ipv6_address_private", droplet.IPV6Address("private"))
}
d.Set("ipv4_address", droplet.IPV4Address("public"))
if droplet.NetworkingType() == "private" {
d.Set("private_networking", true)
d.Set("ipv4_address_private", droplet.IPV4Address("private"))
}
// Initialize the connection info
d.SetConnInfo(map[string]string{
"type": "ssh",
"host": droplet.IPV4Address("public"),
})
return nil
}
示例11: resourcePacketDeviceRead
func resourcePacketDeviceRead(d *schema.ResourceData, meta interface{}) error {
client := meta.(*packngo.Client)
// Retrieve the device properties for updating the state
dev, _, err := client.Devices.Get(d.Id())
if err != nil {
// check if the device no longer exists.
// TODO: This is all wrong for Packet.
if strings.Contains(err.Error(), "404 Not Found") {
d.SetId("")
return nil
}
return fmt.Errorf("Error retrieving device: %s", err)
}
d.Set("os", dev.OS.Slug)
d.Set("hostname", dev.Hostname)
d.Set("facility", dev.Facility.Code)
d.Set("plan", dev.Plan.Slug)
d.Set("state", dev.State)
d.Set("locked", dev.Locked)
var publicIPv4 string
for _, addr := range dev.Network {
switch addr.Family {
case 4:
if addr.Public {
publicIPv4 = addr.Address
d.Set("ipv4_address", addr.Address)
} else {
d.Set("ipv4_address_private", addr.Address)
}
case 6:
if addr.Public {
d.Set("ipv6_address", addr.Address)
}
}
}
// Initialize the connection info
d.SetConnInfo(map[string]string{
"type": "ssh",
"host": publicIPv4,
})
return nil
}
示例12: readInstance
func readInstance(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*AWSClient).ec2conn
resp, err := conn.DescribeInstances(&ec2.DescribeInstancesInput{
InstanceIds: []*string{aws.String(d.Get("spot_instance_id").(string))},
})
if err != nil {
// If the instance was not found, return nil so that we can show
// that the instance is gone.
if ec2err, ok := err.(awserr.Error); ok && ec2err.Code() == "InvalidInstanceID.NotFound" {
return fmt.Errorf("no instance found")
}
// Some other error, report it
return err
}
// If nothing was found, then return no state
if len(resp.Reservations) == 0 {
return fmt.Errorf("no instances found")
}
instance := resp.Reservations[0].Instances[0]
// Set these fields for connection information
if instance != nil {
d.Set("public_dns", instance.PublicDnsName)
d.Set("public_ip", instance.PublicIpAddress)
d.Set("private_dns", instance.PrivateDnsName)
d.Set("private_ip", instance.PrivateIpAddress)
// set connection information
if instance.PublicIpAddress != nil {
d.SetConnInfo(map[string]string{
"type": "ssh",
"host": *instance.PublicIpAddress,
})
} else if instance.PrivateIpAddress != nil {
d.SetConnInfo(map[string]string{
"type": "ssh",
"host": *instance.PrivateIpAddress,
})
}
}
return nil
}
示例13: resourceFromJson
func resourceFromJson(d *schema.ResourceData, vmJson []byte) error {
l := log.New(os.Stderr, "", 0)
l.Printf("VM definition: %s", vmJson)
vm := &bigvServer{}
if err := json.Unmarshal(vmJson, vm); err != nil {
return err
}
d.SetId(strconv.Itoa(vm.Id))
d.Set("name", vm.Name)
d.Set("cores", vm.Cores)
d.Set("memory", vm.Memory)
d.Set("power_on", vm.Power)
d.Set("reboot", vm.Reboot)
d.Set("group_id", vm.GroupId)
d.Set("zone", vm.Zone)
// If we don't get discs back, this was probably an update request
if len(vm.Discs) == 1 {
d.Set("disk_size", vm.Discs[0].Size)
}
// Distribution is empty in create response, leave it with what we sent in
if vm.Distribution != "" {
d.Set("os", vm.Distribution)
}
// Not finding the ips is fine, because they're not sent back in the create request
if len(vm.Nics) > 0 {
// This is fairly^Wvery^Wacceptably hacky
d.Set("ipv4", vm.Nics[0].Ips[0])
d.Set("ipv6", vm.Nics[0].Ips[1])
d.SetConnInfo(map[string]string{
"type": "ssh",
"host": vm.Nics[0].Ips[0],
"password": d.Get("root_password").(string),
})
}
return nil
}
示例14: resourceChefNodeCreate
func resourceChefNodeCreate(d *schema.ResourceData, meta interface{}) error {
client := meta.(*chefGo.Client)
name := d.Get("name").(string)
environment := d.Get("environment").(string)
attributes, err := readAttributes(d.Get("attributes").(string))
if err != nil {
return err
}
var run_list []string
schema_run_list := d.Get("run_list").(interface{})
if err := mapstructure.Decode(schema_run_list, &run_list); err != nil {
return err
}
node := chefGo.Node{
Name: name,
Environment: environment,
NormalAttributes: attributes,
AutomaticAttributes: map[string]interface{}{},
DefaultAttributes: map[string]interface{}{},
OverrideAttributes: map[string]interface{}{},
ChefType: "node",
JsonClass: "Chef::Node",
RunList: run_list,
}
log.Printf("[DEBUG] node create configuration: %#v", node)
_, err = client.Nodes.Post(node)
if err != nil {
return fmt.Errorf("Error creating chef node: %s", err)
}
d.SetId(node.Name)
d.SetConnInfo(map[string]string{
"type": "ssh",
"host": node.Name,
})
return resourceChefNodeRead(d, meta)
}
示例15: resourceMachineRead
func resourceMachineRead(d *schema.ResourceData, config *Config) error {
api, err := config.Cloud()
if err != nil {
return err
}
machine, err := api.GetMachine(d.Id())
if err != nil {
return err
}
d.SetId(machine.Id)
d.Set("name", machine.Name)
d.Set("type", machine.Type)
d.Set("state", machine.State)
d.Set("dataset", machine.Dataset)
d.Set("memory", machine.Memory)
d.Set("disk", machine.Disk)
d.Set("ips", machine.IPs)
d.Set("tags", machine.Tags)
d.Set("created", machine.Created)
d.Set("updated", machine.Updated)
d.Set("package", machine.Package)
d.Set("image", machine.Image)
d.Set("primaryip", machine.PrimaryIP)
d.Set("networks", machine.Networks)
// d.Set("firewall_enabled", machine.FirewallEnabled) // but that field doesn't exist...
// computed attributes from metadata
for schemaName, metadataKey := range resourceMachineMetadataKeys {
d.Set(schemaName, machine.Metadata[metadataKey])
}
// Initialize connection info to enable remote-exec
d.SetConnInfo(map[string]string{
"type": "ssh",
"host": machine.PrimaryIP,
})
return nil
}