Skip to content

Commit

Permalink
Merge pull request #736 from ystia/feature/GH-735-openstack-user-data
Browse files Browse the repository at this point in the history
Added openstack compute instance user_data property
  • Loading branch information
laurentganne authored May 10, 2021
2 parents 7292c4c + ef8e361 commit 8d7a40d
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
6 changes: 5 additions & 1 deletion data/tosca/yorc-openstack-types.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: <yorc-types.yml>
Expand Down Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion prov/terraform/openstack/osinstance.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion prov/terraform/openstack/osinstance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions prov/terraform/openstack/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
1 change: 1 addition & 0 deletions prov/terraform/openstack/testdata/simpleOSInstance.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 8d7a40d

Please sign in to comment.