Skip to content

Commit

Permalink
Merge pull request #371 from cloudify-cosmo/RD-2908-vm-tags
Browse files Browse the repository at this point in the history
add cloudify_tag property to plugin.yaml
  • Loading branch information
EarthmanT authored Aug 29, 2021
2 parents 7392be3 + bb7daf0 commit d947824
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 21 deletions.
3 changes: 2 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,8 @@ commands:
command: pip install https://github.com/cloudify-incubator/cloudify-ecosystem-test/archive/latest.zip
- attach_workspace:
at: workspace
- run: python .circleci/validate_version.py
- run: ecosystem-test validate-plugin-version


generate_py36_wagon:
steps:
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.txt
Original file line number Diff line number Diff line change
Expand Up @@ -154,3 +154,5 @@
- Fix issue introduced in the detach ebs change.
2.12.3:
- RD-2927: Upload local files to S3.
2.12.4:
- Add tagging option for nodes create in aws.
28 changes: 28 additions & 0 deletions cloudify_aws/common/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,10 @@ def wrapper(**kwargs):
resource_id = utils.get_resource_id(
node=ctx.node,
instance=ctx.instance)
if ctx.node.properties.get('cloudify_tagging', False):
add_default_tag(ctx, iface)
else:
ctx.logger.info("Not adding default Cloudify tags.")
tags = utils.get_tags_list(
ctx.node.properties.get('Tags'),
ctx.instance.runtime_properties.get('Tags'),
Expand Down Expand Up @@ -504,3 +508,27 @@ def wrapper(**kwargs):
'Resources': [resource_id]})
return fn(**kwargs)
return wrapper


def add_default_tag(_ctx, iface):
ctx.logger.info("Adding default cloudify_tagging.")

iface.tag(
{'Tags': [
{'Key': 'CreatedBy', 'Value': "{}-{}-{}".format(
_ctx.tenant_name,
_ctx.deployment.id,
_ctx.instance.id)
}
],
'Resources': [iface.resource_id]}
)
iface.tag(
{'Tags': [
{'Key': 'Name', 'Value': "{}_{}".format(
_ctx.node.name, _ctx.instance.id)
}
],
'Resources': [iface.resource_id]}
)
ctx.logger.info("Added default cloudify_tagging.")
27 changes: 14 additions & 13 deletions examples/elb-feature-demo/blueprint.yaml
Original file line number Diff line number Diff line change
@@ -1,29 +1,30 @@
tosca_definitions_version: cloudify_dsl_1_3

imports:
- http://www.getcloudify.org/spec/cloudify/4.5/types.yaml
- plugin.yaml
# - plugin:cloudify-aws-plugin
- https://cloudify.co/spec/cloudify/5.1.0/types.yaml
- plugin:cloudify-aws-plugin

inputs:

aws_access_key_id:
aws_region_name:
type: string
default: { get_secret: aws_access_key_id }
default: 'us-east-1'

aws_secret_access_key:
availability_zone1:
type: string
default: { get_secret: aws_secret_access_key }
description: The availability zone in the AWS Region.
default: { concat: [ { get_input: aws_region_name }, 'a' ] }

aws_region_name:
availability_zone2:
type: string
default: { get_secret: ec2_region_name }
description: The availability zone in the AWS Region.
default: { concat: [ { get_input: aws_region_name }, 'b' ] }

dsl_definitions:

client_config: &client_config
aws_access_key_id: { get_input: aws_access_key_id }
aws_secret_access_key: { get_input: aws_secret_access_key }
aws_access_key_id: { get_secret: aws_access_key_id }
aws_secret_access_key: { get_secret: aws_secret_access_key }
region_name: { get_input: aws_region_name }

node_templates:
Expand Down Expand Up @@ -209,7 +210,7 @@ node_templates:
properties:
resource_config:
CidrBlock: '10.0.1.0/24'
AvailabilityZone: { concat: [ { get_input: aws_region_name }, 'a' ] }
AvailabilityZone: { get_input: availability_zone1 }
client_config: *client_config
Tags:
- Key: Name
Expand All @@ -224,7 +225,7 @@ node_templates:
client_config: *client_config
resource_config:
CidrBlock: '10.0.2.0/24'
AvailabilityZone: { concat: [ { get_input: aws_region_name }, 'c' ] }
AvailabilityZone: { get_input: availability_zone2 }
Tags:
- Key: Name
Value: MySubnet2
Expand Down
64 changes: 57 additions & 7 deletions plugin.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ plugins:

aws:
executor: central_deployment_agent
source: https://github.com/cloudify-cosmo/cloudify-aws-plugin/archive/2.12.3.zip
package_name: cloudify-aws-plugin
package_version: '2.12.3'
package_version: '2.12.4'

data_types:

Expand Down Expand Up @@ -1428,12 +1427,12 @@ node_types:
resource_config:
description: >
Configuration key-value data to be passed as-is to the corresponding
Boto3 method, except for dicionary containing Payload key. Payload
content will be encoded according to Boto3 requirements.
If the Payload value is a dictionary it will be JSON encoded and
converted into bytes. If the Payload value is string it will be
Boto3 method, except for dicionary containing Payload key. Payload
content will be encoded according to Boto3 requirements.
If the Payload value is a dictionary it will be JSON encoded and
converted into bytes. If the Payload value is string it will be
treated as the path for file that will be used to populate the value.
In other cases (integer, bool, etc.) Payload will be passed as is.
In other cases (integer, bool, etc.) Payload will be passed as is.
Key names must match the case that Boto3 requires.
type: cloudify.datatypes.aws.lambda.Invoke.config
required: false
Expand Down Expand Up @@ -1811,6 +1810,10 @@ node_types:
<<: *external_resource
<<: *client_config
<<: *resource_id
cloudify_tagging:
description: an automatic tag to identify the ec2 instance
type: boolean
default: true
resource_config:
description: >
Configuration key-value data to be passed as-is to the corresponding
Expand Down Expand Up @@ -1838,6 +1841,10 @@ node_types:
<<: *external_resource
<<: *client_config
<<: *resource_id
cloudify_tagging:
description: an automatic tag to identify the ec2 instance
type: boolean
default: true
resource_config:
description: >
Configuration key-value data to be passed as-is to the corresponding
Expand Down Expand Up @@ -1865,6 +1872,10 @@ node_types:
<<: *external_resource
<<: *client_config
<<: *resource_id
cloudify_tagging:
description: an automatic tag to identify the ec2 instance
type: boolean
default: true
resource_config:
description: >
Configuration key-value data to be passed as-is to the corresponding
Expand All @@ -1886,6 +1897,10 @@ node_types:
<<: *external_resource
<<: *client_config
<<: *resource_id
cloudify_tagging:
description: an automatic tag to identify the ec2 instance
type: boolean
default: true
resource_config:
description: >
Configuration key-value data to be passed as-is to the corresponding
Expand All @@ -1910,6 +1925,10 @@ node_types:
<<: *external_resource
<<: *client_config
<<: *resource_id
cloudify_tagging:
description: an automatic tag to identify the ec2 instance
type: boolean
default: true
resource_config:
description: >
Configuration key-value data to be passed as-is to the corresponding
Expand All @@ -1934,6 +1953,10 @@ node_types:
<<: *external_resource
<<: *client_config
<<: *resource_id
cloudify_tagging:
description: an automatic tag to identify the ec2 instance
type: boolean
default: true
resource_config:
description: >
Configuration key-value data to be passed as-is to the corresponding
Expand All @@ -1958,6 +1981,10 @@ node_types:
<<: *external_resource
<<: *client_config
<<: *resource_id
cloudify_tagging:
description: an automatic tag to identify the ec2 instance
type: boolean
default: true
resource_config:
description: >
Configuration key-value data to be passed as-is to the corresponding
Expand Down Expand Up @@ -1985,6 +2012,10 @@ node_types:
<<: *external_resource
<<: *client_config
<<: *resource_id
cloudify_tagging:
description: an automatic tag to identify the ec2 instance
type: boolean
default: true
resource_config:
description: >
Configuration key-value data to be passed as-is to the corresponding
Expand Down Expand Up @@ -2172,6 +2203,10 @@ node_types:
<<: *client_config
<<: *resource_id
<<: *tags_property
cloudify_tagging:
description: an automatic tag to identify the ec2 instance
type: boolean
default: false

cloudify.nodes.aws.ec2.Vpc:
derived_from: cloudify.nodes.aws.ec2.BaseType
Expand Down Expand Up @@ -2405,6 +2440,10 @@ node_types:
<<: *client_config
<<: *resource_id
<<: *tags_property
cloudify_tagging:
description: an automatic tag to identify the ec2 instance
type: boolean
default: false
resource_config:
description: >
Configuration key-value data to be passed as-is to the corresponding
Expand Down Expand Up @@ -2533,6 +2572,8 @@ node_types:
description: >
If "create_secret" property is true, and the secret name already exists, overwrite the secret.
default: false
cloudify_tagging:
default: False
interfaces:
cloudify.interfaces.lifecycle:
create:
Expand Down Expand Up @@ -3503,6 +3544,10 @@ node_types:
<<: *external_resource
<<: *client_config
<<: *resource_id
cloudify_tagging:
description: an automatic tag to identify the ec2 instance
type: boolean
default: false
resource_config:
description: >
Configuration key-value data to be passed as-is to the corresponding
Expand Down Expand Up @@ -3537,6 +3582,10 @@ node_types:
<<: *external_resource
<<: *client_config
<<: *resource_id
cloudify_tagging:
description: an automatic tag to identify the ec2 instance
type: boolean
default: false
resource_config:
description: >
Configuration key-value data to be passed as-is to the corresponding
Expand Down Expand Up @@ -4019,3 +4068,4 @@ workflows:
description: The ID of the blueprint that should be used to deploy the new resources. Default is current blueprint.
type: string
default: 'existing-eks-cluster'

0 comments on commit d947824

Please sign in to comment.