async Task <R53HealthSpec> ResolveR53HealthCheckSpec(Instance inst, Dictionary <string, string> tags) { if (!tags.TryGetValue(R53HealthCheckTriggerTagName, out var specTag)) { return(null); } specTag = _ec2Eval.Evaluate(specTag, inst); var hc = new R53HealthSpec { RefName = $"vmbot-{inst.InstanceId}", }; if (specTag.StartsWith(HealthCheckS3RefPrefix)) { hc.Config = await ParseS3RefHealthCheck(specTag, inst); } else { hc.Config = await ParseInlineHealthCheck(specTag); } _logger.LogInformation("Resolved Health Check Spec as:"); _logger.LogInformation(JsonSerializer.Serialize(hc)); return(hc); }
async Task <HealthCheck> FindExistingHealthCheck(R53HealthSpec r53Health) { HealthCheck existingHealth = null; if (r53Health != null) { var listRequ = new ListHealthChecksRequest(); var listResp = await _r53.ListHealthChecksAsync(listRequ); _logger.LogInformation("Looking for existing Health Check for RefName: " + r53Health.RefName); while (listResp.HealthChecks?.Count > 0) { existingHealth = listResp.HealthChecks.FirstOrDefault(hc => hc.CallerReference == r53Health.RefName); if (existingHealth != null) { // Found a match break; } if (!listResp.IsTruncated) { // No more records break; } // Get the next page of results listRequ.Marker = listResp.Marker; listResp = await _r53.ListHealthChecksAsync(listRequ); } if (existingHealth == null) { _logger.LogInformation("Found NO EXISTING Health Check for resolved spec"); } else { _logger.LogInformation("Found existing Health Check for resolved spec: " + existingHealth.Id); } } return(existingHealth); }