INNER CODE UNIT · Go
buildTerraformImportCommand
cloudflare/cf-terraforming · internal/app/cf-terraforming/cmd/import.go:772
func buildTerraformImportCommand(i int, resourceType, resourceID, endpoint string) string {
resourceImportAddress := buildRawImportAddress(resourceType, resourceID, endpoint)
return fmt.Sprintf("%s %s.%s %s\n", terraformImportCmdPrefix, resourceType, fmt.Sprintf("%s_%s_%d", terraformResourceNamePrefix, resourceID, i), resourceImportAddress)
}
// buildRawImportAddress takes the resourceType and resourceID in order to look up
// the resource type import string and then return a suitable address.
//
// Note: `endpoint` is only used on > v4. Otherwise, it is ignored.
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"