mirror of
https://github.com/opentofu/opentofu.git
synced 2025-02-25 18:45:20 -06:00
Merge pull request #454 from stuntgoat/goog-external
providers/google: add external_address; needed for connection
This commit is contained in:
commit
4822419414
@ -100,6 +100,11 @@ func resourceComputeInstance() *schema.Resource {
|
|||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
Computed: true,
|
Computed: true,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
"external_address": &schema.Schema{
|
||||||
|
Type: schema.TypeString,
|
||||||
|
Computed: true,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -335,12 +340,27 @@ func resourceComputeInstanceRead(d *schema.ResourceData, meta interface{}) error
|
|||||||
d.Set("can_ip_forward", instance.CanIpForward)
|
d.Set("can_ip_forward", instance.CanIpForward)
|
||||||
|
|
||||||
// Set the networks
|
// Set the networks
|
||||||
|
externalIP := ""
|
||||||
for i, iface := range instance.NetworkInterfaces {
|
for i, iface := range instance.NetworkInterfaces {
|
||||||
prefix := fmt.Sprintf("network.%d", i)
|
prefix := fmt.Sprintf("network.%d", i)
|
||||||
d.Set(prefix+".name", iface.Name)
|
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)
|
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.
|
// Set the metadata fingerprint if there is one.
|
||||||
if instance.Metadata != nil {
|
if instance.Metadata != nil {
|
||||||
d.Set("metadata_fingerprint", instance.Metadata.Fingerprint)
|
d.Set("metadata_fingerprint", instance.Metadata.Fingerprint)
|
||||||
@ -506,3 +526,16 @@ func resourceInstanceTags(d *schema.ResourceData) *compute.Tags {
|
|||||||
|
|
||||||
return tags
|
return tags
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// resourceInstanceNatIP acquires the first NatIP with a "ONE_TO_ONE_NAT" type
|
||||||
|
// in the compute.NetworkInterface's AccessConfigs.
|
||||||
|
func resourceInstanceNatIP(iface *compute.NetworkInterface) (natIP string) {
|
||||||
|
for _, config := range iface.AccessConfigs {
|
||||||
|
if config.Type == "ONE_TO_ONE_NAT" {
|
||||||
|
natIP = config.NatIP
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return natIP
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user