INNER CODE UNIT · Go

buildRawImportAddress

cloudflare/cf-terraforming · internal/app/cf-terraforming/cmd/import.go:781

func buildRawImportAddress(resourceType, resourceID, endpoint string) string {
	if strings.HasPrefix(providerVersionString, "5") {
		prefix := ""
		if strings.Contains(endpoint, "{accounts_or_zones}") {
			if accountID != "" {
				prefix = "accounts"
				endpoint = strings.Replace(endpoint, "/{accounts_or_zones}/{account_or_zone_id}/", "/accounts/{account_id}/", 1)
			} else {
				prefix = "zones"
				endpoint = strings.Replace(endpoint, "/{accounts_or_zones}/{account_or_zone_id}/", "/zones/{zone_id}/", 1)
			}
		}

		r, _ := regexp.Compile("({[a-z0-9_]*})")
		matches := r.FindAllString(endpoint, -1)

		if len(matches) > 0 {
			// Naive assumptions below but if we only have a single placeholder (`{}`)

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…