applyAutomaticInstanceID checks if the resource is one of a set of *magical* IDs that automatically index their identifier for automatic authentication.
(resource *tfjson.StateResource, agents []*proto.Agent)
| 1254 | // applyAutomaticInstanceID checks if the resource is one of a set of *magical* IDs |
| 1255 | // that automatically index their identifier for automatic authentication. |
| 1256 | func applyAutomaticInstanceID(resource *tfjson.StateResource, agents []*proto.Agent) { |
| 1257 | // These resource types are for automatically associating an instance ID |
| 1258 | // with an agent for authentication. |
| 1259 | key, isValid := map[string]string{ |
| 1260 | "google_compute_instance": "instance_id", |
| 1261 | "aws_instance": "id", |
| 1262 | "aws_spot_instance_request": "spot_instance_id", |
| 1263 | "azurerm_linux_virtual_machine": "virtual_machine_id", |
| 1264 | "azurerm_windows_virtual_machine": "virtual_machine_id", |
| 1265 | }[resource.Type] |
| 1266 | if !isValid { |
| 1267 | return |
| 1268 | } |
| 1269 | |
| 1270 | // The resource type doesn't support |
| 1271 | // automatically setting the instance ID. |
| 1272 | instanceIDRaw, isValid := resource.AttributeValues[key] |
| 1273 | if !isValid { |
| 1274 | return |
| 1275 | } |
| 1276 | instanceID, isValid := instanceIDRaw.(string) |
| 1277 | if !isValid { |
| 1278 | return |
| 1279 | } |
| 1280 | for _, agent := range agents { |
| 1281 | // Didn't use instance identity. |
| 1282 | if agent.GetToken() != "" { |
| 1283 | continue |
| 1284 | } |
| 1285 | if agent.GetInstanceId() != "" { |
| 1286 | // If an instance ID is manually specified, do not override! |
| 1287 | continue |
| 1288 | } |
| 1289 | |
| 1290 | agent.Auth = &proto.Agent_InstanceId{ |
| 1291 | InstanceId: instanceID, |
| 1292 | } |
| 1293 | } |
| 1294 | } |
| 1295 | |
| 1296 | // findResourcesInGraph traverses directionally in a graph until a resource is found, |
| 1297 | // then it stores the depth it was found at, and continues working up the tree. |
no test coverage detected