From ef8e3614559029872d58d4ceb32e82d8a9a68b96 Mon Sep 17 00:00:00 2001 From: Laurent Ganne Date: Mon, 10 May 2021 12:55:23 +0000 Subject: [PATCH] Added openstack compute instance user_data property --- CHANGELOG.md | 4 ++++ data/tosca/yorc-openstack-types.yml | 6 +++++- prov/terraform/openstack/osinstance.go | 5 ++++- prov/terraform/openstack/osinstance_test.go | 2 +- prov/terraform/openstack/resources.go | 1 + prov/terraform/openstack/testdata/simpleOSInstance.yaml | 1 + 6 files changed, 16 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 44360fa90..ad89d3a71 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## UNRELEASED +### ENHANCEMENTS + +* Add the ability to define OpenStack Compute Instance user_data ([GH-735](https://github.com/ystia/yorc/issues/735)) + ### BUG FIXES * Workflow with asynchronous action never stops after another step failure ([GH-733](https://github.com/ystia/yorc/issues/733)) diff --git a/data/tosca/yorc-openstack-types.yml b/data/tosca/yorc-openstack-types.yml index 0c0f0ef13..eda6cd3f7 100644 --- a/data/tosca/yorc-openstack-types.yml +++ b/data/tosca/yorc-openstack-types.yml @@ -3,7 +3,7 @@ tosca_definitions_version: yorc_tosca_simple_yaml_1_0 metadata: template_name: yorc-openstack-types template_author: yorc - template_version: 1.2.1 + template_version: 1.3.0 imports: - yorc: @@ -144,6 +144,10 @@ node_types: entry_schema: type: string required: false + user_data: + type: string + description: User data to provide when launching the instance + required: false requirements: - group: capability: yorc.capabilities.Group diff --git a/prov/terraform/openstack/osinstance.go b/prov/terraform/openstack/osinstance.go index e89e10139..592c01fe0 100644 --- a/prov/terraform/openstack/osinstance.go +++ b/prov/terraform/openstack/osinstance.go @@ -172,11 +172,14 @@ func generateComputeInstance(ctx context.Context, opts osInstanceOptions) (Compu if toscaVal != nil && toscaVal.RawString() != "" { err = json.Unmarshal([]byte(toscaVal.RawString()), &instance.Metadata) if err != nil { - err = errors.Wrapf(err, "Expected a map of strings for the metadata value of node %s instance %s, got: %s", + return instance, errors.Wrapf(err, "Expected a map of strings for the metadata value of node %s instance %s, got: %s", opts.nodeName, opts.instanceName, toscaVal.RawString()) } } + instance.UserData, err = deployments.GetStringNodeProperty(ctx, opts.deploymentID, + opts.nodeName, "user_data", false) + return instance, err } diff --git a/prov/terraform/openstack/osinstance_test.go b/prov/terraform/openstack/osinstance_test.go index ec2e668a1..276ce47c8 100644 --- a/prov/terraform/openstack/osinstance_test.go +++ b/prov/terraform/openstack/osinstance_test.go @@ -97,7 +97,7 @@ func testSimpleOSInstance(t *testing.T) { require.Len(t, compute.Metadata, 2) require.Equal(t, "firstValue", compute.Metadata["firstKey"]) require.Equal(t, "secondValue", compute.Metadata["secondKey"]) - + require.Contains(t, compute.UserData, "cloud-config") require.Len(t, compute.Provisioners, 0) require.Contains(t, infrastructure.Resource, "null_resource") require.Len(t, infrastructure.Resource["null_resource"], 1) diff --git a/prov/terraform/openstack/resources.go b/prov/terraform/openstack/resources.go index 09469c465..4e6a6371d 100644 --- a/prov/terraform/openstack/resources.go +++ b/prov/terraform/openstack/resources.go @@ -46,6 +46,7 @@ type ComputeInstance struct { KeyPair string `json:"key_pair,omitempty"` SchedulerHints SchedulerHints `json:"scheduler_hints,omitempty"` Metadata map[string]string `json:"metadata,omitempty"` + UserData string `json:"user_data,omitempty"` commons.Resource } diff --git a/prov/terraform/openstack/testdata/simpleOSInstance.yaml b/prov/terraform/openstack/testdata/simpleOSInstance.yaml index 115b361b5..b60a5cf96 100644 --- a/prov/terraform/openstack/testdata/simpleOSInstance.yaml +++ b/prov/terraform/openstack/testdata/simpleOSInstance.yaml @@ -26,6 +26,7 @@ topology_template: key_pair: yorc security_groups: openbar,default metadata: {get_input: vm_metadata} + user_data: "#cloud-config\nwrite_files:\n- content: |\n test\n owner: root:root\n path: /etc/test.txt\n permissions: '0644'" capabilities: endpoint: properties: