Created
April 7, 2022 15:01
-
-
Save jkodroff/e58626da3093c5e970f23de8640025ee to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// TfDataSourceToPulumi converts a given Terraform data source name tfName (e.g. "provider_foo_bar") and returns the | |
// standard conversion to a Pulumi function name (e.g. "getFooBar") | |
func TfDataSourceToPulumi(tfName string) string { | |
parts := strings.Split(tfName, "_") | |
if len(parts) < 2 { | |
return "" | |
} | |
// The first segment is the provider name, which we do not include in the Pulumi name. | |
parts = parts[1:] | |
for i, part := range parts { | |
parts[i] = strings.Title(part) | |
} | |
return fmt.Sprintf("get%s", strings.Join(parts, "")) | |
} | |
// TfResourceToPulumi converts a given Terraform resource name tfName (e.g. "provider_foo_bar") and returns the | |
// standard conversion to a Pulumi resource name (e.g. "FooBar") | |
func TfResourceToPulumi(tfName string) string { | |
parts := strings.Split(tfName, "_") | |
if len(parts) < 2 { | |
return "" | |
} | |
// The first segment is the provider name, which we do not include in the Pulumi name. | |
parts = parts[1:] | |
for i, part := range parts { | |
parts[i] = strings.Title(part) | |
} | |
return strings.Join(parts, "") | |
} | |
func TestTfDataSourceToPulumi(t *testing.T) { | |
assert.Equal(t, "", TfDataSourceToPulumi("invalid")) | |
assert.Equal(t, "getFoo", TfDataSourceToPulumi("provider_foo")) | |
assert.Equal(t, "getFooBar", TfDataSourceToPulumi("provider_foo_bar")) | |
assert.Equal(t, "getFooBarBaz", TfDataSourceToPulumi("provider_foo_bar_baz")) | |
} | |
func TestTfResourceToPulumi(t *testing.T) { | |
assert.Equal(t, "", TfResourceToPulumi("invalid")) | |
assert.Equal(t, "Foo", TfResourceToPulumi("provider_foo")) | |
assert.Equal(t, "FooBarBaz", TfResourceToPulumi("provider_foo_bar_baz")) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment