github.com/graywolf-at-work-2/terraform-vendor@v1.4.5/internal/communicator/shared/shared.go (about) 1 package shared 2 3 import ( 4 "fmt" 5 "net" 6 7 "github.com/hashicorp/terraform/internal/configs/configschema" 8 "github.com/zclconf/go-cty/cty" 9 ) 10 11 // ConnectionBlockSupersetSchema is a schema representing the superset of all 12 // possible arguments for "connection" blocks across all supported connection 13 // types. 14 // 15 // This currently lives here because we've not yet updated our communicator 16 // subsystem to be aware of schema itself. Once that is done, we can remove 17 // this and use a type-specific schema from the communicator to validate 18 // exactly what is expected for a given connection type. 19 var ConnectionBlockSupersetSchema = &configschema.Block{ 20 Attributes: map[string]*configschema.Attribute{ 21 // Common attributes for both connection types 22 "host": { 23 Type: cty.String, 24 Required: true, 25 }, 26 "type": { 27 Type: cty.String, 28 Optional: true, 29 }, 30 "user": { 31 Type: cty.String, 32 Optional: true, 33 }, 34 "password": { 35 Type: cty.String, 36 Optional: true, 37 }, 38 "port": { 39 Type: cty.Number, 40 Optional: true, 41 }, 42 "timeout": { 43 Type: cty.String, 44 Optional: true, 45 }, 46 "script_path": { 47 Type: cty.String, 48 Optional: true, 49 }, 50 // For type=ssh only (enforced in ssh communicator) 51 "target_platform": { 52 Type: cty.String, 53 Optional: true, 54 }, 55 "private_key": { 56 Type: cty.String, 57 Optional: true, 58 }, 59 "certificate": { 60 Type: cty.String, 61 Optional: true, 62 }, 63 "host_key": { 64 Type: cty.String, 65 Optional: true, 66 }, 67 "agent": { 68 Type: cty.Bool, 69 Optional: true, 70 }, 71 "agent_identity": { 72 Type: cty.String, 73 Optional: true, 74 }, 75 "proxy_scheme": { 76 Type: cty.String, 77 Optional: true, 78 }, 79 "proxy_host": { 80 Type: cty.String, 81 Optional: true, 82 }, 83 "proxy_port": { 84 Type: cty.Number, 85 Optional: true, 86 }, 87 "proxy_user_name": { 88 Type: cty.String, 89 Optional: true, 90 }, 91 "proxy_user_password": { 92 Type: cty.String, 93 Optional: true, 94 }, 95 "bastion_host": { 96 Type: cty.String, 97 Optional: true, 98 }, 99 "bastion_host_key": { 100 Type: cty.String, 101 Optional: true, 102 }, 103 "bastion_port": { 104 Type: cty.Number, 105 Optional: true, 106 }, 107 "bastion_user": { 108 Type: cty.String, 109 Optional: true, 110 }, 111 "bastion_password": { 112 Type: cty.String, 113 Optional: true, 114 }, 115 "bastion_private_key": { 116 Type: cty.String, 117 Optional: true, 118 }, 119 "bastion_certificate": { 120 Type: cty.String, 121 Optional: true, 122 }, 123 124 // For type=winrm only (enforced in winrm communicator) 125 "https": { 126 Type: cty.Bool, 127 Optional: true, 128 }, 129 "insecure": { 130 Type: cty.Bool, 131 Optional: true, 132 }, 133 "cacert": { 134 Type: cty.String, 135 Optional: true, 136 }, 137 "use_ntlm": { 138 Type: cty.Bool, 139 Optional: true, 140 }, 141 }, 142 } 143 144 // IpFormat formats the IP correctly, so we don't provide IPv6 address in an IPv4 format during node communication. We return the ip parameter as is if it's an IPv4 address or a hostname. 145 func IpFormat(ip string) string { 146 ipObj := net.ParseIP(ip) 147 // Return the ip/host as is if it's either a hostname or an IPv4 address. 148 if ipObj == nil || ipObj.To4() != nil { 149 return ip 150 } 151 152 return fmt.Sprintf("[%s]", ip) 153 }