func shouldDeleteResourceGroup()

in main.go [147:185]


func shouldDeleteResourceGroup(rg *armresources.ResourceGroup, ttl time.Duration, regex string) (string, bool) {
	if _, ok := rg.Tags[doNotDeleteTag]; ok {
		return "", false
	}

	if regex != "" {
		match, err := regexMatchesResourceGroupName(regex, *rg.Name)
		if err != nil {
			log.Printf("failed to regex Resource Group Name: %s", err)
			return "", false
		}
		if !match {
			log.Printf("RG '%s' did not match regex", *rg.Name)
			return "", false
		}
		log.Printf("RG '%s' matched regex '%s'", *rg.Name, regex)
	}

	creationTimestamp, ok := rg.Tags[creationTimestampTag]
	if !ok {
		return fmt.Sprintf("probably a long time because it does not have a '%s' tag. Found tags: %v", creationTimestampTag, rg.Tags), true
	}

	var t time.Time
	var err error
	for _, layout := range rfc3339Layouts {
		t, err = time.Parse(layout, *creationTimestamp)
		if err == nil {
			break
		}
	}

	if err != nil {
		log.Printf("failed to parse timestamp: %s", err)
		return "", false
	}

	return fmt.Sprintf("%d days (%d hours)", int(time.Since(t).Hours()/24), int(time.Since(t).Hours())), time.Since(t) >= ttl
}