From 9ec1836ddad70601f17e13e1276664d79cabd713 Mon Sep 17 00:00:00 2001 From: Helio Machado <0x2b3bfa0+git@googlemail.com> Date: Thu, 1 Dec 2022 00:34:58 +0000 Subject: [PATCH] Improve `machine` identifier format --- iterative/aws/provider.go | 2 +- iterative/azure/provider.go | 8 ++++---- iterative/resource_runner.go | 4 ++-- iterative/testdata/script_template_cloud_aws.golden | 4 ++-- .../testdata/script_template_cloud_azure.golden | 4 ++-- iterative/testdata/script_template_cloud_gcp.golden | 4 ++-- .../testdata/script_template_cloud_invalid.golden | 4 ++-- .../script_template_cloud_kubernetes.golden | 4 ++-- iterative/utils/helpers.go | 10 ++++------ iterative/utils/helpers_test.go | 13 +++++++++++++ 10 files changed, 34 insertions(+), 23 deletions(-) create mode 100644 iterative/utils/helpers_test.go diff --git a/iterative/aws/provider.go b/iterative/aws/provider.go index 6368f81e..a91c2ae2 100644 --- a/iterative/aws/provider.go +++ b/iterative/aws/provider.go @@ -46,7 +46,7 @@ func ResourceMachineCreate(ctx context.Context, d *schema.ResourceData, m interf availabilityZone := GetAvailabilityZone(d.Get("region").(string)) metadata := map[string]string{ - "Name": d.Get("name").(string), + "Name": d.Id(), "Id": d.Id(), } for key, value := range d.Get("metadata").(map[string]interface{}) { diff --git a/iterative/azure/provider.go b/iterative/azure/provider.go index 23423200..b43ed547 100644 --- a/iterative/azure/provider.go +++ b/iterative/azure/provider.go @@ -20,7 +20,7 @@ import ( azresources "terraform-provider-iterative/task/az/resources" ) -//ResourceMachineCreate creates AWS instance +// ResourceMachineCreate creates AWS instance func ResourceMachineCreate(ctx context.Context, d *schema.ResourceData, m interface{}) error { subscriptionID, err := subscriptionID() if err != nil { @@ -59,7 +59,7 @@ func ResourceMachineCreate(ctx context.Context, d *schema.ResourceData, m interf sku := imageParts[2] version := imageParts[3] - vmName := d.Get("name").(string) + vmName := d.Id() gpName := d.Id() nsgName := gpName + "-nsg" vnetName := gpName + "-vnet" @@ -296,7 +296,7 @@ func ResourceMachineCreate(ctx context.Context, d *schema.ResourceData, m interf return nil } -//ResourceMachineDelete deletes Azure instance +// ResourceMachineDelete deletes Azure instance func ResourceMachineDelete(ctx context.Context, d *schema.ResourceData, m interface{}) error { subscriptionID, err := subscriptionID() if err != nil { @@ -398,7 +398,7 @@ func getUserAssignedIdentityMap(identitiesRaw string) (map[string]*compute.Virtu return identityMap, nil } -//GetRegion maps region to real cloud regions +// GetRegion maps region to real cloud regions func GetRegion(region string) string { instanceRegions := make(map[string]string) instanceRegions["us-east"] = "eastus" diff --git a/iterative/resource_runner.go b/iterative/resource_runner.go index dfeadcfe..08f9156c 100644 --- a/iterative/resource_runner.go +++ b/iterative/resource_runner.go @@ -418,7 +418,7 @@ func provisionerCode(d *schema.ResourceData) (string, error) { Cloud: d.Get("cloud").(string), Spot: d.Get("spot").(bool), Region: d.Get("region").(string), - Name: d.Get("name").(string), + Name: d.Id(), Labels: "", IdleTimeout: d.Get("idle_timeout").(int), Repo: "", @@ -460,7 +460,7 @@ func provisionerCode(d *schema.ResourceData) (string, error) { data["driver"] = d.Get("driver").(string) data["labels"] = d.Get("labels").(string) data["idle_timeout"] = strconv.Itoa(d.Get("idle_timeout").(int)) - data["name"] = d.Get("name").(string) + data["name"] = d.Id() data["cloud"] = d.Get("cloud").(string) data["startup_script"] = d.Get("startup_script").(string) data["tf_resource"] = base64.StdEncoding.EncodeToString(jsonResource) diff --git a/iterative/testdata/script_template_cloud_aws.golden b/iterative/testdata/script_template_cloud_aws.golden index 046e2684..7cf75df2 100644 --- a/iterative/testdata/script_template_cloud_aws.golden +++ b/iterative/testdata/script_template_cloud_aws.golden @@ -58,7 +58,7 @@ export AWS_SESSION_TOKEN='2 value with "quotes" and spaces' while lsof /var/lib/dpkg/lock; do sleep 1; done HOME="$(mktemp -d)" exec $(which cml-runner || echo $(which cml-internal || echo cml) runner) \ - --name '10 value with "quotes" and spaces' \ + \ --labels '16 value with "quotes" and spaces' \ --idle-timeout 11 \ --driver '15 value with "quotes" and spaces' \ @@ -66,7 +66,7 @@ HOME="$(mktemp -d)" exec $(which cml-runner || echo $(which cml-internal || echo --token '13 value with "quotes" and spaces' \ --single \ \ - --tf-resource eyJtb2RlIjoibWFuYWdlZCIsInR5cGUiOiJpdGVyYXRpdmVfY21sX3J1bm5lciIsIm5hbWUiOiJydW5uZXIiLCJwcm92aWRlciI6InByb3ZpZGVyW1wicmVnaXN0cnkudGVycmFmb3JtLmlvL2l0ZXJhdGl2ZS9pdGVyYXRpdmVcIl0iLCJpbnN0YW5jZXMiOlt7InByaXZhdGUiOiIiLCJzY2hlbWFfdmVyc2lvbiI6MCwiYXR0cmlidXRlcyI6eyJuYW1lIjoiMTAgdmFsdWUgd2l0aCBcInF1b3Rlc1wiIGFuZCBzcGFjZXMiLCJsYWJlbHMiOiIiLCJpZGxlX3RpbWVvdXQiOjExLCJyZXBvIjoiIiwidG9rZW4iOiIiLCJkcml2ZXIiOiIiLCJjbG91ZCI6ImF3cyIsInNwb3QiOmZhbHNlLCJjdXN0b21fZGF0YSI6IiIsImlkIjoiIiwiaW1hZ2UiOiIiLCJpbnN0YW5jZV9ncHUiOiIiLCJpbnN0YW5jZV9oZGRfc2l6ZSI6MTIsImluc3RhbmNlX2lwIjoiIiwiaW5zdGFuY2VfbGF1bmNoX3RpbWUiOiIiLCJpbnN0YW5jZV90eXBlIjoiIiwicmVnaW9uIjoiOSB2YWx1ZSB3aXRoIFwicXVvdGVzXCIgYW5kIHNwYWNlcyIsInNzaF9uYW1lIjoiIiwic3NoX3ByaXZhdGUiOiIiLCJzc2hfcHVibGljIjoiIiwiYXdzX3NlY3VyaXR5X2dyb3VwIjoiIn19XX0= + --tf-resource eyJtb2RlIjoibWFuYWdlZCIsInR5cGUiOiJpdGVyYXRpdmVfY21sX3J1bm5lciIsIm5hbWUiOiJydW5uZXIiLCJwcm92aWRlciI6InByb3ZpZGVyW1wicmVnaXN0cnkudGVycmFmb3JtLmlvL2l0ZXJhdGl2ZS9pdGVyYXRpdmVcIl0iLCJpbnN0YW5jZXMiOlt7InByaXZhdGUiOiIiLCJzY2hlbWFfdmVyc2lvbiI6MCwiYXR0cmlidXRlcyI6eyJuYW1lIjoiIiwibGFiZWxzIjoiIiwiaWRsZV90aW1lb3V0IjoxMSwicmVwbyI6IiIsInRva2VuIjoiIiwiZHJpdmVyIjoiIiwiY2xvdWQiOiJhd3MiLCJzcG90IjpmYWxzZSwiY3VzdG9tX2RhdGEiOiIiLCJpZCI6IiIsImltYWdlIjoiIiwiaW5zdGFuY2VfZ3B1IjoiIiwiaW5zdGFuY2VfaGRkX3NpemUiOjEyLCJpbnN0YW5jZV9pcCI6IiIsImluc3RhbmNlX2xhdW5jaF90aW1lIjoiIiwiaW5zdGFuY2VfdHlwZSI6IiIsInJlZ2lvbiI6IjkgdmFsdWUgd2l0aCBcInF1b3Rlc1wiIGFuZCBzcGFjZXMiLCJzc2hfbmFtZSI6IiIsInNzaF9wcml2YXRlIjoiIiwic3NoX3B1YmxpYyI6IiIsImF3c19zZWN1cml0eV9ncm91cCI6IiJ9fV19 EOF sudo chmod +x /usr/bin/cml.sh diff --git a/iterative/testdata/script_template_cloud_azure.golden b/iterative/testdata/script_template_cloud_azure.golden index 0caebf2a..5bdf161e 100644 --- a/iterative/testdata/script_template_cloud_azure.golden +++ b/iterative/testdata/script_template_cloud_azure.golden @@ -59,7 +59,7 @@ export AZURE_TENANT_ID='6 value with "quotes" and spaces' while lsof /var/lib/dpkg/lock; do sleep 1; done HOME="$(mktemp -d)" exec $(which cml-runner || echo $(which cml-internal || echo cml) runner) \ - --name '10 value with "quotes" and spaces' \ + \ --labels '16 value with "quotes" and spaces' \ --idle-timeout 11 \ --driver '15 value with "quotes" and spaces' \ @@ -67,7 +67,7 @@ HOME="$(mktemp -d)" exec $(which cml-runner || echo $(which cml-internal || echo --token '13 value with "quotes" and spaces' \ --single \ \ - --tf-resource eyJtb2RlIjoibWFuYWdlZCIsInR5cGUiOiJpdGVyYXRpdmVfY21sX3J1bm5lciIsIm5hbWUiOiJ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pdmVyIjoiIiwiY2xvdWQiOiJhenVyZSIsInNwb3QiOmZhbHNlLCJjdXN0b21fZGF0YSI6IiIsImlkIjoiIiwiaW1hZ2UiOiIiLCJpbnN0YW5jZV9ncHUiOiIiLCJpbnN0YW5jZV9oZGRfc2l6ZSI6MTIsImluc3RhbmNlX2lwIjoiIiwiaW5zdGFuY2VfbGF1bmNoX3RpbWUiOiIiLCJpbnN0YW5jZV90eXBlIjoiIiwicmVnaW9uIjoiOSB2YWx1ZSB3aXRoIFwicXVvdGVzXCIgYW5kIHNwYWNlcyIsInNzaF9uYW1lIjoiIiwic3NoX3ByaXZhdGUiOiIiLCJzc2hfcHVibGljIjoiIiwiYXdzX3NlY3VyaXR5X2dyb3VwIjoiIn19XX0= EOF sudo chmod +x /usr/bin/cml.sh diff --git a/iterative/testdata/script_template_cloud_gcp.golden b/iterative/testdata/script_template_cloud_gcp.golden index 6046bc06..617de679 100644 --- a/iterative/testdata/script_template_cloud_gcp.golden +++ b/iterative/testdata/script_template_cloud_gcp.golden @@ -57,7 +57,7 @@ export CML_GCP_ACCESS_TOKEN='' while lsof /var/lib/dpkg/lock; do sleep 1; done HOME="$(mktemp -d)" exec $(which cml-runner || echo $(which cml-internal || echo cml) runner) \ - --name '10 value with "quotes" and spaces' \ + \ --labels '16 value with "quotes" and spaces' \ --idle-timeout 11 \ --driver '15 value with "quotes" and spaces' \ @@ -65,7 +65,7 @@ HOME="$(mktemp -d)" exec $(which cml-runner || echo $(which cml-internal || echo --token '13 value with "quotes" and spaces' \ --single \ \ - --tf-resource eyJtb2RlIjoibWFuYWdlZCIsInR5cGUiOiJpdGVyYXRpdmVfY21sX3J1bm5lciIsIm5hbWUiOiJydW5uZXIiLCJwcm92aWRlciI6InByb3ZpZGVyW1wicmVnaXN0cnkudGVycmFmb3JtLmlvL2l0ZXJhdGl2ZS9pdGVyYXRpdmVcIl0iLCJpbnN0YW5jZXMiOlt7InByaXZhdGUiOiIiLCJzY2hlbWFfdmVyc2lvbiI6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5jZV9pcCI6IiIsImluc3RhbmNlX2xhdW5jaF90aW1lIjoiIiwiaW5zdGFuY2VfdHlwZSI6IiIsInJlZ2lvbiI6IjkgdmFsdWUgd2l0aCBcInF1b3Rlc1wiIGFuZCBzcGFjZXMiLCJzc2hfbmFtZSI6IiIsInNzaF9wcml2YXRlIjoiIiwic3NoX3B1YmxpYyI6IiIsImF3c19zZWN1cml0eV9ncm91cCI6IiJ9fV19 EOF sudo chmod +x /usr/bin/cml.sh diff --git a/iterative/testdata/script_template_cloud_invalid.golden b/iterative/testdata/script_template_cloud_invalid.golden index deee8565..57b2fd08 100644 --- a/iterative/testdata/script_template_cloud_invalid.golden +++ b/iterative/testdata/script_template_cloud_invalid.golden @@ -55,7 +55,7 @@ sudo tee /usr/bin/cml.sh << 'EOF' while lsof /var/lib/dpkg/lock; do sleep 1; done HOME="$(mktemp -d)" exec $(which cml-runner || echo $(which cml-internal || echo cml) runner) \ - --name '10 value with "quotes" and spaces' \ + \ --labels '16 value with "quotes" and spaces' \ --idle-timeout 11 \ --driver '15 value with "quotes" and spaces' \ @@ -63,7 +63,7 @@ HOME="$(mktemp -d)" exec $(which cml-runner || echo $(which cml-internal || echo --token '13 value with "quotes" and spaces' \ --single \ \ - --tf-resource eyJtb2RlIjoibWFuYWdlZCIsInR5cGUiOiJpdGVyYXRpdmVfY21sX3J1bm5lciIsIm5hbWUiOiJydW5uZXIiLCJwcm92aWRlciI6InByb3ZpZGVyW1wicmVnaXN0cnkudGVycmFmb3JtLmlvL2l0ZXJhdGl2ZS9pdGVyYXRpdmVcIl0iLCJpbnN0YW5jZXMiOlt7InByaXZhdGUiOiIiLCJzY2hlbWFfdmVyc2lvbiI6MCwiYXR0cmlidXRlcyI6eyJuYW1lIjoiMTAgdmFsdWUgd2l0aCBcInF1b3Rlc1wiIGFuZCBzcGFjZXMiLCJsYWJlbHMiOiIiLCJpZGxlX3RpbWVvdXQiOjExLCJyZXBvIjoiIiwidG9rZW4iOiIiLCJkcml2ZXIi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HJpdmF0ZSI6IiIsInNzaF9wdWJsaWMiOiIiLCJhd3Nfc2VjdXJpdHlfZ3JvdXAiOiIifX1dfQ== EOF sudo chmod +x /usr/bin/cml.sh diff --git a/iterative/testdata/script_template_cloud_kubernetes.golden b/iterative/testdata/script_template_cloud_kubernetes.golden index 9928d5fa..1d357dc3 100644 --- a/iterative/testdata/script_template_cloud_kubernetes.golden +++ b/iterative/testdata/script_template_cloud_kubernetes.golden @@ -8,7 +8,7 @@ export KUBERNETES_CONFIGURATION='8 value with "quotes" and spaces' while lsof /var/lib/dpkg/lock; do sleep 1; done HOME="$(mktemp -d)" exec $(which cml-runner || echo $(which cml-internal || echo cml) runner) \ - --name '10 value with "quotes" and spaces' \ + \ --labels '16 value with "quotes" and spaces' \ --idle-timeout 11 \ --driver '15 value with "quotes" and spaces' \ @@ -16,4 +16,4 @@ HOME="$(mktemp -d)" exec $(which cml-runner || echo $(which cml-internal || echo --token '13 value with "quotes" and spaces' \ --single \ \ - --tf-resource eyJtb2RlIjoibWFuYWdlZCIsInR5cGUiOiJpdGVyYXRpdmVfY21sX3J1bm5lciIsIm5hbWUiOiJydW5uZXIiLCJwcm92aWRlciI6InByb3ZpZGVyW1wicmVnaXN0cnkudGVycmFmb3JtLmlvL2l0ZXJhdGl2ZS9pdGVyYXRpdmVcIl0iLCJpbnN0YW5jZXMiOlt7InByaXZhdGUiOiIiLCJzY2hlbWFfdmVyc2lvbiI6MCwiYXR0cmlidXRlcyI6eyJuYW1lIjoiMTAgdmFsdWUgd2l0aCBcInF1b3Rlc1wiIGFuZCBzcGFjZXMiLCJsYWJlbHMiOiIiLCJpZGxlX3RpbWVvdXQiOjExLCJyZXBvIjoiIiwidG9rZW4iOiIiLCJkcml2ZXIiOiIiLCJjbG91ZCI6Imt1YmVybmV0ZXMiLCJzcG90IjpmYWxzZSwiY3VzdG9tX2RhdGEiOiIiLCJpZCI6IiIsImltYWdlIjoiIiwiaW5zdGFuY2VfZ3B1IjoiIiwiaW5zdGFu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 100644 --- a/iterative/utils/helpers.go +++ b/iterative/utils/helpers.go @@ -6,10 +6,11 @@ import ( "os" "strings" - "github.com/aohorodnyk/uid" "github.com/blang/semver/v4" "github.com/google/go-github/v42/github" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + + "terraform-provider-iterative/task/common" ) func GetCML(version string) string { @@ -81,11 +82,8 @@ func MachinePrefix(d *schema.ResourceData) string { func SetId(d *schema.ResourceData) { if len(d.Id()) == 0 { - d.SetId("iterative-" + uid.NewProvider36Size(8).MustGenerate().String()) - - if len(d.Get("name").(string)) == 0 { - d.Set("name", d.Id()) - } + id := common.NewRandomIdentifier(d.Get("name").(string)) + d.SetId(strings.Replace(id.Long(), "tpi-", "cml-", 1)) } } diff --git a/iterative/utils/helpers_test.go b/iterative/utils/helpers_test.go new file mode 100644 index 00000000..96cd63c8 --- /dev/null +++ b/iterative/utils/helpers_test.go @@ -0,0 +1,13 @@ +package utils + +import ( + "testing" + + "github.com/stretchr/testify/require" +) + +func TestIdentifier(t *testing.T) { + d := generateSchemaData(t, map[string]interface{}{"name": "example"}) + SetId(d) + require.Regexp(t, "^cml-example-", d.Id()) +}