Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve machine identifier format #726

Merged
merged 1 commit into from
Dec 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion iterative/aws/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}) {
Expand Down
8 changes: 4 additions & 4 deletions iterative/azure/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions iterative/resource_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -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: "",
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions iterative/testdata/script_template_cloud_aws.golden
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,15 @@ 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' \
--repo '14 value with "quotes" and spaces' \
--token '13 value with "quotes" and spaces' \
--single \
\
--tf-resource eyJtb2RlIjoibWFuYWdlZCIsInR5cGUiOiJpdGVyYXRpdmVfY21sX3J1bm5lciIsIm5hbWUiOiJydW5uZXIiLCJwcm92aWRlciI6InByb3ZpZGVyW1wicmVnaXN0cnkudGVycmFmb3JtLmlvL2l0ZXJhdGl2ZS9pdGVyYXRpdmVcI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W5zdGFuY2VfZ3B1IjoiIiwiaW5zdGFuY2VfaGRkX3NpemUiOjEyLCJpbnN0YW5jZV9pcCI6IiIsImluc3RhbmNlX2xhdW5jaF90aW1lIjoiIiwiaW5zdGFuY2VfdHlwZSI6IiIsInJlZ2lvbiI6IjkgdmFsdWUgd2l0aCBcInF1b3Rlc1wiIGFuZCBzcGFjZXMiLCJzc2hfbmFtZSI6IiIsInNzaF9wcml2YXRlIjoiIiwic3NoX3B1YmxpYyI6IiIsImF3c19zZWN1cml0eV9ncm91cCI6IiJ9fV19
EOF
sudo chmod +x /usr/bin/cml.sh

Expand Down
4 changes: 2 additions & 2 deletions iterative/testdata/script_template_cloud_azure.golden
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,15 @@ 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' \
--repo '14 value with "quotes" and spaces' \
--token '13 value with "quotes" and spaces' \
--single \
\
--tf-resource eyJtb2RlIjoibWFuYWdlZCIsInR5cGUiOiJpdGVyYXRpdmVfY21sX3J1bm5lciIsIm5hbWUiOiJydW5uZXIiLCJwcm92aWRlciI6InByb3ZpZGVyW1wicmVnaXN0cnkudGVycmFmb3JtLmlvL2l0ZXJhdGl2ZS9pdGVyYXRpdmVcIl0iLCJpbnN0YW5jZXMiOlt7InByaXZhdGUiOiIiLCJzY2hlbWFfdmVyc2lvbiI6MCwiYXR0cmlidXRlcyI6eyJuYW1lIjoiMTAgdmFsdWUgd2l0aCBcInF1b3Rlc1wiIGFuZCBzcGFjZXMiLCJsYWJlbHMiOiIiLCJpZGxlX3RpbWVvdXQiOjExLCJyZXBvIjoiIiwidG9rZW4iOiIiLCJkcml2ZXIiOiIiLCJjbG91ZCI6ImF6dXJ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2hfcHVibGljIjoiIiwiYXdzX3NlY3VyaXR5X2dyb3VwIjoiIn19XX0=
EOF
sudo chmod +x /usr/bin/cml.sh

Expand Down
4 changes: 2 additions & 2 deletions iterative/testdata/script_template_cloud_gcp.golden
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,15 @@ 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' \
--repo '14 value with "quotes" and spaces' \
--token '13 value with "quotes" and spaces' \
--single \
\
--tf-resource eyJtb2RlIjoibWFuYWdlZCIsInR5cGUiOiJpdGVyYXRpdmVfY21sX3J1bm5lciIsIm5hbWUiOiJydW5uZXIiLCJwcm92aWRlciI6InByb3ZpZGVyW1wicmVnaXN0cnkudGVycmFmb3JtLmlvL2l0ZXJhdGl2ZS9pdGVyYXRpdmVcIl0iLCJpbnN0YW5jZXMiOlt7InByaXZhdGUiOiIiLCJzY2hlbWFfdmVyc2lvbiI6MCwiYXR0cmlidXRlcyI6eyJuYW1lIjoiMTAgdmFsdWUgd2l0aCBcInF1b3Rlc1wiIGFuZCBzcGFjZXMiLCJsYWJlbHMiOiIiLCJpZGxlX3RpbWVvdXQiOjExLCJyZXBvIjoiIiwidG9rZW4iOiIiLCJkcml2ZXIiOiIiLCJjbG91ZCI6ImdjcCIsInNwb3QiOmZhbHNlLCJjdXN0b21fZGF0YSI6IiIsImlkIjoiIiwiaW1hZ2UiOiIiLCJpbnN0YW5jZV9ncHUiOiIiLCJpbnN0YW5jZV9oZGRfc2l6ZSI6MTIsImluc3RhbmNlX2lwIjoiIiwiaW5zdGFuY2VfbGF1bmNoX3RpbWUiOiIiLCJpbnN0YW5jZV90eXBlIjoiIiwicmVnaW9uIjoiOSB2YWx1ZSB3aXRoIFwicXVvdGVzXCIgYW5kIHNwYWNlcyIsInNzaF9uYW1lIjoiIiwic3NoX3ByaXZhdGUiOiIiLCJzc2hfcHVibGljIjoiIiwiYXdzX3NlY3VyaXR5X2dyb3VwIjoiIn19XX0=
--tf-resource eyJtb2RlIjoibWFuYWdlZCIsInR5cGUiOiJpdGVyYXRpdmVfY21sX3J1bm5lciIsIm5hbWUiOiJydW5uZXIiLCJwcm92aWRlciI6InByb3ZpZGVyW1wicmVnaXN0cnkudGVycmFmb3JtLmlvL2l0ZXJhdGl2ZS9pdGVyYXRpdmVcIl0iLCJpbnN0YW5jZXMiOlt7InByaXZhdGUiOiIiLCJzY2hlbWFfdmVyc2lvbiI6MCwiYXR0cmlidXRlcyI6eyJuYW1lIjoiIiwibGFiZWxzIjoiIiwiaWRsZV90aW1lb3V0IjoxMSwicmVwbyI6IiIsInRva2VuIjoiIiwiZHJpdmVyIjoiIiwiY2xvdWQiOiJnY3AiLCJzcG90IjpmYWxzZSwiY3VzdG9tX2RhdGEiOiIiLCJpZCI6IiIsImltYWdlIjoiIiwiaW5zdGFuY2VfZ3B1IjoiIiwiaW5zdGFuY2VfaGRkX3NpemUiOjEyLCJpbnN0YW5jZV9pcCI6IiIsImluc3RhbmNlX2xhdW5jaF90aW1lIjoiIiwiaW5zdGFuY2VfdHlwZSI6IiIsInJlZ2lvbiI6IjkgdmFsdWUgd2l0aCBcInF1b3Rlc1wiIGFuZCBzcGFjZXMiLCJzc2hfbmFtZSI6IiIsInNzaF9wcml2YXRlIjoiIiwic3NoX3B1YmxpYyI6IiIsImF3c19zZWN1cml0eV9ncm91cCI6IiJ9fV19
EOF
sudo chmod +x /usr/bin/cml.sh

Expand Down
4 changes: 2 additions & 2 deletions iterative/testdata/script_template_cloud_invalid.golden
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,15 @@ 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' \
--repo '14 value with "quotes" and spaces' \
--token '13 value with "quotes" and spaces' \
--single \
\
--tf-resource eyJtb2RlIjoibWFuYWdlZCIsInR5cGUiOiJpdGVyYXRpdmVfY21sX3J1bm5lciIsIm5hbWUiOiJydW5uZXIiLCJwcm92aWRlciI6InByb3ZpZGVyW1wicmVnaXN0cnkudGVycmFmb3JtLmlvL2l0ZXJhdGl2ZS9pdGVyYXRpdmVcIl0iLCJpbnN0YW5jZXMiOlt7InByaXZhdGUiOiIiLCJzY2hlbWFfdmVyc2lvbiI6MCwiYXR0cmlidXRlcyI6eyJuYW1lIjoiMTAgdmFsdWUgd2l0aCBcInF1b3Rlc1wiIGFuZCBzcGFjZXMiLCJsYWJlbHMiOiIiLCJpZGxlX3RpbWVvdXQiOjExLCJyZXBvIjoiIiwidG9rZW4iOiIiLCJkcml2ZXIiOiIiLCJjbG91ZCI6ImludmFsaWQiLCJzcG90IjpmYWxzZSwiY3VzdG9tX2RhdGEiOiIiLCJpZCI6IiIsImltYWdlIjoiIiwiaW5zdGFuY2VfZ3B1IjoiIiwiaW5zdGFuY2VfaGRkX3NpemUiOjEyLCJpbnN0YW5jZV9pcCI6IiIsImluc3RhbmNlX2xhdW5jaF90aW1lIjoiIiwiaW5zdGFuY2VfdHlwZSI6IiIsInJlZ2lvbiI6IjkgdmFsdWUgd2l0aCBcInF1b3Rlc1wiIGFuZCBzcGFjZXMiLCJzc2hfbmFtZSI6IiIsInNzaF9wcml2YXRlIjoiIiwic3NoX3B1YmxpYyI6IiIsImF3c19zZWN1cml0eV9ncm91cCI6IiJ9fV19
--tf-resource eyJtb2RlIjoibWFuYWdlZCIsInR5cGUiOiJpdGVyYXRpdmVfY21sX3J1bm5lciIsIm5hbWUiOiJydW5uZXIiLCJwcm92aWRlciI6InByb3ZpZGVyW1wicmVnaXN0cnkudGVycmFmb3JtLmlvL2l0ZXJhdGl2ZS9pdGVyYXRpdmVcIl0iLCJpbnN0YW5jZXMiOlt7InByaXZhdGUiOiIiLCJzY2hlbWFfdmVyc2lvbiI6MCwiYXR0cmlidXRlcyI6eyJuYW1lIjoiIiwibGFiZWxzIjoiIiwiaWRsZV90aW1lb3V0IjoxMSwicmVwbyI6IiIsInRva2VuIjoiIiwiZHJpdmVyIjoiIiwiY2xvdWQiOiJpbnZhbGlkIiwic3BvdCI6ZmFsc2UsImN1c3RvbV9kYXRhIjoiIiwiaWQiOiIiLCJpbWFnZSI6IiIsImluc3RhbmNlX2dwdSI6IiIsImluc3RhbmNlX2hkZF9zaXplIjoxMiwiaW5zdGFuY2VfaXAiOiIiLCJpbnN0YW5jZV9sYXVuY2hfdGltZSI6IiIsImluc3RhbmNlX3R5cGUiOiIiLCJyZWdpb24iOiI5IHZhbHVlIHdpdGggXCJxdW90ZXNcIiBhbmQgc3BhY2VzIiwic3NoX25hbWUiOiIiLCJzc2hfcHJpdmF0ZSI6IiIsInNzaF9wdWJsaWMiOiIiLCJhd3Nfc2VjdXJpdHlfZ3JvdXAiOiIifX1dfQ==
EOF
sudo chmod +x /usr/bin/cml.sh

Expand Down
4 changes: 2 additions & 2 deletions iterative/testdata/script_template_cloud_kubernetes.golden
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ 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' \
--repo '14 value with "quotes" and spaces' \
--token '13 value with "quotes" and spaces' \
--single \
\
--tf-resource eyJtb2RlIjoibWFuYWdlZCIsInR5cGUiOiJpdGVyYXRpdmVfY21sX3J1bm5lciIsIm5hbWUiOiJydW5uZXIiLCJwcm92aWRl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vdWQiOiJrdWJlcm5ldGVzIiwic3BvdCI6ZmFsc2UsImN1c3RvbV9kYXRhIjoiIiwiaWQiOiIiLCJpbWFnZSI6IiIsImluc3RhbmNlX2dwdSI6IiIsImluc3RhbmNlX2hkZF9zaXplIjoxMiwiaW5zdGFuY2VfaXAiOiIiLCJpbnN0YW5jZV9sYXVuY2hfdGltZSI6IiIsImluc3RhbmNlX3R5cGUiOiIiLCJyZWdpb24iOiI5IHZhbHVlIHdpdGggXCJxdW90ZXNcIiBhbmQgc3BhY2VzIiwic3NoX25hbWUiOiIiLCJzc2hfcHJpdmF0ZSI6IiIsInNzaF9wdWJsaWMiOiIiLCJhd3Nfc2VjdXJpdHlfZ3JvdXAiOiIifX1dfQ==
10 changes: 4 additions & 6 deletions iterative/utils/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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))
}
}

Expand Down
13 changes: 13 additions & 0 deletions iterative/utils/helpers_test.go
Original file line number Diff line number Diff line change
@@ -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())
}