def create(ctx, iface, resource_config, **_): '''Creates an AWS RDS Subnet Group''' # Build API params params = \ dict() if not resource_config else resource_config.copy() node_subnet_ids = params.get('SubnetIds', list()) instance_subnet_ids = \ ctx.instance.runtime_properties['resource_config'].get('SubnetIds', list()) if not node_subnet_ids: if not instance_subnet_ids: raise NonRecoverableError( 'Missing required parameter in input: SubnetIds') params['SubnetIds'] = instance_subnet_ids # if it is set then we need to combine them to what we already have as # runtime_properties else: for subnet_id in instance_subnet_ids: if subnet_id not in node_subnet_ids: node_subnet_ids.append(subnet_id) params['SubnetIds'] = node_subnet_ids if iface.resource_id: params.update({'DBSubnetGroupName': iface.resource_id}) create_response = iface.create(params) resource_id = create_response['DBSubnetGroup']['DBSubnetGroupName'] utils.update_resource_id(ctx.instance, resource_id) utils.update_resource_arn( ctx.instance, create_response['DBSubnetGroup']['DBSubnetGroupArn'])
def create(ctx, iface, resource_config, **_): """Creates an AWS Autoscaling Lifecycle Hook""" params = \ dict() if not resource_config else resource_config.copy() resource_id = \ iface.resource_id or \ utils.get_resource_id( ctx.node, ctx.instance, params.get(RESOURCE_NAME), use_instance_id=True) params[RESOURCE_NAME] = resource_id utils.update_resource_id(ctx.instance, resource_id) # Ensure the $GROUP_NAME parameter is populated. autoscaling_group = params.get(GROUP_NAME) if not autoscaling_group: autoscaling_group = \ utils.find_resource_id_by_type( ctx.instance, GROUP_TYPE) params[GROUP_NAME] = autoscaling_group ctx.instance.runtime_properties[GROUP_NAME] = \ autoscaling_group if not iface.resource_id: setattr(iface, 'resource_id', params.get(RESOURCE_NAME)) # Actually create the resource iface.create(params)
def create(ctx, iface, resource_config, **_): '''Creates AWS EC2 Keypairs''' params = \ dict() if not resource_config else resource_config.copy() params[KEYNAME] = utils.get_resource_name(params.get(KEYNAME)) key_name = params[KEYNAME] if PUBLIC_KEY_MATERIAL in params: create_response = \ iface.import_keypair( params, log_response=ctx.node.properties['log_create_response']) else: create_response = iface.create( params, log_response=ctx.node.properties['log_create_response']) # Allow the end user to store the key material in a secret. if ctx.node.properties['create_secret']: try: client = get_rest_client() except KeyError: # No pun intended. raise NonRecoverableError( 'create_secret is only supported with a Cloudify Manager.') # This makes the line too long for flake8 if included in args. secret_name = ctx.node.properties.get('secret_name', key_name) secrets_count = len(client.secrets.list(key=secret_name)) secret_value = create_response.get('KeyMaterial') try: if secrets_count == 0: client.secrets.create( key=secret_name, value=secret_value) elif secrets_count == 1 and \ ctx.node.properties.get( 'update_existing_secret', False) is True: client.secrets.update( key=secret_name, value=secret_value) except CloudifyClientError as e: raise NonRecoverableError(str(e)) cleaned_create_response = \ utils.JsonCleanuper(create_response).to_dict() # Allow the end user to opt-in to storing the key # material in the runtime properties. # Default is false if 'KeyMaterial' in cleaned_create_response and not \ ctx.node.properties['store_in_runtime_properties']: del cleaned_create_response['KeyMaterial'] ctx.instance.runtime_properties['create_response'] = \ cleaned_create_response iface.update_resource_id(cleaned_create_response.get(KEYNAME)) utils.update_resource_id(ctx.instance, key_name)
def create(ctx, iface, resource_config, **_): """Creates an AWS EC2 NetworkInterface""" # Create a copy of the resource config for clean manipulation. params = \ dict() if not resource_config else resource_config.copy() subnet_id = params.get(SUBNET_ID) if not subnet_id: targ = \ utils.find_rel_by_node_type(ctx.instance, SUBNET_TYPE) or \ utils.find_rel_by_node_type(ctx.instance, SUBNET_TYPE_DEPRECATED) # Attempt to use the VPC ID from parameters. # Fallback to connected VPC. params[SUBNET_ID] = \ subnet_id or \ targ.target.instance.runtime_properties.get(EXTERNAL_RESOURCE_ID) # Actually create the resource eni = iface.create(params) eni_id = eni.get(NETWORKINTERFACE_ID, '') iface.update_resource_id(eni_id) utils.update_resource_id(ctx.instance, eni_id) ctx.instance.runtime_properties['device_index'] = \ ctx.instance.runtime_properties.get('device_index', 1)
def create(ctx, iface, resource_config, **_): """Creates an AWS ELB classic policy""" # Create a copy of the resource config for clean manipulation. params = \ dict() if not resource_config else resource_config.copy() resource_id = \ iface.resource_id or \ utils.get_resource_id( ctx.node, ctx.instance, params.get(RESOURCE_NAME), use_instance_id=True) params[RESOURCE_NAME] = resource_id utils.update_resource_id(ctx.instance, resource_id) ctx.instance.runtime_properties[RESOURCE_NAME] = \ resource_id lb_name = params.get(LB_NAME) if not lb_name: targs = \ utils.find_rels_by_node_type( ctx.instance, LB_TYPE) lb_name = \ targs[0].target.instance.runtime_properties[ EXTERNAL_RESOURCE_ID] params.update({LB_NAME: lb_name}) ctx.instance.runtime_properties[LB_NAME] = \ lb_name # Actually create the resource iface.create(params)
def create(ctx, iface, resource_config, **_): '''Creates an AWS EC2 Subnet''' params = dict() if not resource_config else resource_config.copy() vpc_id = params.get(VPC_ID) cidr_block = params.get(CIDR_BLOCK) # If either of these values is missing, # they must be filled from a connected VPC. if not vpc_id or not cidr_block: targ = \ utils.find_rel_by_node_type( ctx.instance, VPC_TYPE) or utils.find_rel_by_node_type( ctx.instance, VPC_TYPE_DEPRECATED) # Attempt to use the VPC ID from parameters. # Fallback to connected VPC. params[VPC_ID] = \ vpc_id or \ targ.target.instance.runtime_properties.get( EXTERNAL_RESOURCE_ID) # Attempt to use the CIDR Block from parameters. # Fallback to connected VPC. params[CIDR_BLOCK] = \ cidr_block or \ targ.instance.runtime_properties.get( 'resource_config', {}).get(CIDR_BLOCK) subnet = iface.create(params) subnet_id = subnet.get(SUBNET_ID) iface.update_resource_id(subnet_id) utils.update_resource_id(ctx.instance, subnet_id)
def create(ctx, iface, resource_config, **_): """Creates an AWS KMS Key Alias""" # Create a copy of the resource config for clean manipulation. params = \ dict() if not resource_config else resource_config.copy() resource_id = \ utils.get_resource_id( ctx.node, ctx.instance, params.get(RESOURCE_NAME), use_instance_id=True ) params[RESOURCE_NAME] = resource_id utils.update_resource_id(ctx.instance, resource_id) target_key_id = params.get(TARGET_KEY_ID) if not target_key_id: target_key = \ utils.find_rel_by_node_type( ctx.instance, KEY_TYPE) target_key_id = \ target_key.target.instance.runtime_properties[EXTERNAL_RESOURCE_ID] params[TARGET_KEY_ID] = target_key_id # Actually create the resource iface.create(params)
def create(ctx, iface, resource_config, **_): """Creates an AWS KMS Key Grant""" # Create a copy of the resource config for clean manipulation. params = \ dict() if not resource_config else resource_config.copy() resource_id = \ utils.get_resource_id( ctx.node, ctx.instance, params.get(RESOURCE_NAME), use_instance_id=True ) params[RESOURCE_NAME] = resource_id utils.update_resource_id(ctx.instance, resource_id) key_id = params.get(KEY_ID) if not key_id: target_key = \ utils.find_rel_by_node_type( ctx.instance, KEY_TYPE) key_id = \ target_key.target.instance.runtime_properties[EXTERNAL_RESOURCE_ID] params[KEY_ID] = key_id ctx.instance.runtime_properties[KEY_ID] = key_id # Actually create the resource output = iface.create(params) ctx.instance.runtime_properties[GRANT_TOKEN] = \ output.get(GRANT_TOKEN) utils.update_resource_id(ctx.instance, output.get(GRANT_ID))
def create(ctx, iface, resource_config, **_): '''Creates an AWS IAM Role''' # Build API params params = \ dict() if not resource_config else resource_config.copy() resource_id = \ utils.get_resource_id( ctx.node, ctx.instance, params.get(RESOURCE_NAME), use_instance_id=True ) or iface.resource_id params[RESOURCE_NAME] = resource_id utils.update_resource_id(ctx.instance, resource_id) if 'AssumeRolePolicyDocument' in params and \ isinstance(params['AssumeRolePolicyDocument'], dict): params['AssumeRolePolicyDocument'] = \ json_dumps(params['AssumeRolePolicyDocument']) # Actually create the resource create_response = iface.create(params) resource_id = create_response['Role']['RoleName'] iface.update_resource_id(resource_id) utils.update_resource_id(ctx.instance, resource_id) utils.update_resource_arn(ctx.instance, create_response['Role']['Arn'])
def create(ctx, iface, resource_config, **_): '''Creates an AWS EC2 Route Table''' params = dict() if not resource_config else resource_config.copy() vpc_id = params.get(VPC_ID) # If either of these values is missing, # they must be filled from a connected VPC. if not vpc_id: targ = \ utils.find_rel_by_node_type(ctx.instance, VPC_TYPE) or \ utils.find_rel_by_node_type(ctx.instance, VPC_TYPE_DEPRECATED) # Attempt to use the VPC ID from parameters. # Fallback to connected VPC. params[VPC_ID] = vpc_id or targ.target\ .instance.runtime_properties.get(EXTERNAL_RESOURCE_ID) # Actually create the resource create_response = iface.create(params) ctx.instance.runtime_properties['create_response'] = \ utils.JsonCleanuper(create_response).to_dict() route_table_id = create_response.get(ROUTETABLE_ID) iface.update_resource_id(route_table_id) utils.update_resource_id(ctx.instance, route_table_id)
def create(ctx, iface, resource_config, **_): '''Creates an AWS IAM Profile''' # Build API params params = \ dict() if not resource_config else resource_config.copy() resource_id = \ utils.get_resource_id( ctx.node, ctx.instance, params.get(RESOURCE_NAME), use_instance_id=True ) or iface.resource_id params[RESOURCE_NAME] = resource_id utils.update_resource_id(ctx.instance, resource_id) role_name = params.pop('RoleName', None) res_id, res_arn = iface.create(params) utils.update_resource_id(ctx.instance, res_id) utils.update_resource_arn(ctx.instance, res_arn) role_name = role_name or \ utils.find_resource_id_by_type(ctx.instance, IAM_ROLE_TYPE) if role_name: add_role_params = { RESOURCE_NAME: iface.resource_id, 'RoleName': role_name } iface.add_role_to_instance_profile(add_role_params) ctx.instance.runtime_properties['RoleName'] = role_name
def create(ctx, iface, resource_config, **_): """Creates an AWS S3 Bucket Policy""" # Create a copy of the resource config for clean manipulation. params = \ dict() if not resource_config else resource_config.copy() # Get the bucket name from either params or a relationship. bucket_name = params.get(BUCKET) if not bucket_name: targ = utils.find_rel_by_node_type(ctx.instance, BUCKET_TYPE) bucket_name = \ targ.target.instance.runtime_properties.get( EXTERNAL_RESOURCE_ID ) params[BUCKET] = bucket_name ctx.instance.runtime_properties[BUCKET] = bucket_name utils.update_resource_id(ctx.instance, bucket_name) # Get the policy name from either params or a relationship. bucket_policy = params.get(POLICY) if not isinstance(bucket_policy, basestring): bucket_policy = json.dumps(bucket_policy) params[POLICY] = bucket_policy ctx.instance.runtime_properties[POLICY] = bucket_policy # Actually create the resource iface.create(params)
def create(ctx, iface, resource_config, **_): '''Creates an AWS ELB rule''' # Build API params params = \ ctx.instance.runtime_properties['resource_config'] or resource_config if LISTENER_ARN not in params: targs = \ utils.find_rels_by_node_type( ctx.instance, LISTENER_TYPE) listener_arn = \ targs[0].target.instance.runtime_properties[EXTERNAL_RESOURCE_ARN] params.update({LISTENER_ARN: listener_arn}) del targs for action in params.get('Actions', []): target_grp = action.get(TARGET_ARN) if not ARN_MATCHER.match(action.get(target_grp, '')): targs = \ utils.find_rels_by_node_type( ctx.instance, TARGET_TYPE) for targ in targs: target_group_arn = \ targ.target.instance.runtime_properties[ EXTERNAL_RESOURCE_ARN] if targ.target.node.name == target_grp: action.update({TARGET_ARN: target_group_arn}) # Actually create the resource res_id = iface.create(params) utils.update_resource_id(ctx.instance, res_id) utils.update_resource_arn(ctx.instance, res_id)
def configure(ctx, resource_config, **_): '''Configures an AWS RDS Parameter''' # Save the parameters if resource_config.get('ParameterName') and not utils.get_resource_id(): utils.update_resource_id(ctx.instance, resource_config['ParameterName']) ctx.instance.runtime_properties['resource_config'] = resource_config
def create(ctx, iface, resource_config, **_): '''Creates an AWS IAM Role Policy''' # Build API params params = \ dict() if not resource_config else resource_config.copy() resource_id = \ utils.get_resource_id( ctx.node, ctx.instance, params.get(RESOURCE_NAME), use_instance_id=True ) or iface.resource_id params[RESOURCE_NAME] = resource_id utils.update_resource_id(ctx.instance, resource_id) # Add RoleName role_name = params.get(ROLE_NAME, '') if not role_name: params[ROLE_NAME] = \ utils.find_resource_id_by_type( ctx.instance, ROLE_TYPE) if 'PolicyDocument' in params and \ isinstance(params['PolicyDocument'], dict): params['PolicyDocument'] = json_dumps(params['PolicyDocument']) # Actually create the resource iface.create(params)
def create(ctx, iface, resource_config, **_): """Creates an AWS EC2 NetworkAcl""" # Create a copy of the resource config for clean manipulation. params = \ dict() if not resource_config else resource_config.copy() vpc_id = params.get(VPC_ID) if not vpc_id: targ = \ utils.find_rel_by_node_type(ctx.instance, VPC_TYPE) or \ utils.find_rel_by_node_type(ctx.instance, VPC_TYPE_DEPRECATED) # Attempt to use the VPC ID from parameters. # Fallback to connected VPC. params[VPC_ID] = \ vpc_id or \ targ.target.instance.runtime_properties.get(EXTERNAL_RESOURCE_ID) # Actually create the resource create_response = iface.create(params)['NetworkAcl'] ctx.instance.runtime_properties['create_response'] = \ utils.JsonCleanuper(create_response).to_dict() network_acl_id = create_response.get(NETWORKACL_ID, '') iface.update_resource_id(network_acl_id) utils.update_resource_id(ctx.instance, network_acl_id)
def create(ctx, iface, resource_config, **_): """Creates an AWS EC2 Vpc Peering""" params = dict() if not resource_config else resource_config.copy() # Accepter and Requester options are not part of create api, so we # Should check them if they are exists and then remove them accepter_vpc_options = params.get(ACCEPTER_VPC_PEERING_CONNECTION) requester_vpc_options = params.get(REQUESTER_VPC_PEERING_CONNECTION) if accepter_vpc_options: del params[ACCEPTER_VPC_PEERING_CONNECTION] if requester_vpc_options: del params[REQUESTER_VPC_PEERING_CONNECTION] # Actually create the resource create_response = iface.create(params)[VPC_PEERING_CONNECTION] ctx.instance.runtime_properties['create_response'] = \ utils.JsonCleanuper(create_response).to_dict() if create_response: resource_id = \ utils.get_resource_id( ctx.node, ctx.instance, create_response.get(VPC_PEERING_CONNECTION_ID), use_instance_id=True ) utils.update_resource_id(ctx.instance, resource_id) prepare_describe_vpc_peering_filter(resource_config.copy(), iface)
def create(ctx, iface, resource_config, **_): '''Creates an AWS EC2 Security Group''' params = \ dict() if not resource_config else resource_config.copy() vpc_id = params.get(VPC_ID) # Try to get the group_name and if it does not exits then try to # generate new one based on instance_id group_name = params.get(GROUP_NAME) params[GROUP_NAME] = utils.get_ec2_vpc_resource_name(group_name) if not vpc_id: vpc = \ utils.find_rel_by_node_type( ctx.instance, VPC_TYPE) or utils.find_rel_by_node_type( ctx.instance, VPC_TYPE_DEPRECATED) params[VPC_ID] = \ vpc_id or \ vpc.target.instance.runtime_properties.get( EXTERNAL_RESOURCE_ID) # Actually create the resource create_response = iface.create(params) ctx.instance.runtime_properties['create_response'] = \ utils.JsonCleanuper(create_response).to_dict() group_id = create_response.get(GROUPID, '') iface.update_resource_id(group_id) utils.update_resource_id(ctx.instance, group_id)
def attach(ctx, iface, resource_config, **_): """ Attaches an AWS EC2 EBS Volume TO Instance :param ctx: :param iface: :param resource_config: :param _: :return: """ params = \ dict() if not resource_config else resource_config.copy() # Attach ebs volume to ec2 instance resource create_response = iface.create(params) # Check if the resource attaching done if create_response: ctx.instance.runtime_properties['eps_attach'] =\ utils.JsonCleanuper(create_response).to_dict() # Update the esp_id (volume_id) esp_id = create_response.get(VOLUME_ID, '') utils.update_resource_id(ctx.instance, esp_id) iface.update_resource_id(esp_id) else: raise NonRecoverableError( '{0} ID# "{1}" reported an empty response' .format(RESOURCE_TYPE_VOLUME_ATTACHMENT, iface.resource_id))
def attach_to(ctx, iface, resource_config, **_): '''Attaches an IAM User to something else''' if utils.is_node_type(ctx.target.node, 'cloudify.nodes.aws.iam.Group'): resource_config['UserName'] = iface.resource_id IAMGroup(ctx.target.node, logger=ctx.logger, resource_id=utils.get_resource_id( node=ctx.target.node, instance=ctx.target.instance, raise_on_missing=True)).attach_user(resource_config) elif utils.is_node_type(ctx.target.node, 'cloudify.nodes.aws.iam.LoginProfile'): iface.create_login_profile( resource_config or ctx.target.instance.runtime_properties.get('resource_config')) elif utils.is_node_type(ctx.target.node, 'cloudify.nodes.aws.iam.AccessKey'): resp = iface.create_access_key( resource_config or ctx.target.instance.runtime_properties.get('resource_config')) utils.update_resource_id(ctx.target.instance, resp['AccessKeyId']) ctx.target.instance.runtime_properties['SecretAccessKey'] = \ resp['SecretAccessKey'] elif utils.is_node_type(ctx.target.node, 'cloudify.nodes.aws.iam.Policy'): resource_config['PolicyArn'] = utils.get_resource_arn( node=ctx.target.node, instance=ctx.target.instance, raise_on_missing=True) iface.attach_policy(resource_config)
def create(ctx, iface, resource_config, **_): '''Creates an AWS EC2 Internet Gateway''' params = dict() if not resource_config else resource_config.copy() internet_gateway = iface.create(params) utils.update_resource_id(ctx.instance, internet_gateway.get(INTERNETGATEWAY_ID))
def create(ctx, iface, resource_config, **_): """Creates an AWS Autoscaling Group""" params = \ dict() if not resource_config else resource_config.copy() resource_id = \ iface.resource_id or \ utils.get_resource_id( ctx.node, ctx.instance, params.get(RESOURCE_NAME), use_instance_id=True) params[RESOURCE_NAME] = resource_id utils.update_resource_id(ctx.instance, resource_id) # Try to populate the Launch Configuration field # with a relationship lc_name = params.get(LC_NAME) instance_id = params.get(INSTANCE_ID) if not lc_name and not instance_id: lc_name = \ utils.find_resource_id_by_type( ctx.instance, LC_TYPE) if lc_name: params.update({LC_NAME: lc_name}) # If no LC_NAME, try to populate the # InstanceId field with a relationship. if not lc_name: instance_id = \ utils.find_resource_id_by_type( ctx.instance, INSTANCE_TYPE) params[INSTANCE_ID] = instance_id subnet_list_string = params.get(SUBNET_LIST) subnet_list = \ subnet_list_string.split(', ') if \ subnet_list_string else [] subnet_list = \ utils.add_resources_from_rels( ctx.instance, SUBNET_TYPE, subnet_list) subnet_list = \ utils.add_resources_from_rels( ctx.instance, SUBNET_TYPE_DEPRECATED, subnet_list) if subnet_list: params[SUBNET_LIST] = ', '.join(subnet_list) # Actually create the resource resource_id, resource_arn = iface.create(params) iface.update_resource_id(resource_id) utils.update_resource_id(ctx.instance, resource_id) utils.update_resource_arn(ctx.instance, resource_arn)
def create(ctx, iface, resource_config, **_): """Creates an AWS Autoscaling Autoscaling Launch Configuration""" params = \ dict() if not resource_config else resource_config.copy() resource_id = \ iface.resource_id or \ utils.get_resource_id( ctx.node, ctx.instance, params.get(RESOURCE_NAME), use_instance_id=True) params[RESOURCE_NAME] = resource_id utils.update_resource_id(ctx.instance, resource_id) # Add Security Groups secgroups_list = params.get(SECGROUPS, []) params[SECGROUPS] = \ utils.add_resources_from_rels( ctx.instance, SECGROUP_TYPE, secgroups_list) image_id = params.get(IMAGEID) # Add Instance and Instance Type instance_id = params.get(INSTANCEID) instance_type = params.get(INSTANCE_TYPE_PROPERTY) if not image_id and not instance_id: instance_id = utils.find_resource_id_by_type( ctx.instance, INSTANCE_TYPE_NEW) or \ utils.find_resource_id_by_type( ctx.instance, INSTANCE_TYPE) params.update({INSTANCEID: instance_id}) if instance_id and not instance_type: targ = utils.find_rel_by_node_type( ctx.instance, INSTANCE_TYPE_NEW) or \ utils.find_rel_by_node_type( ctx.instance, INSTANCE_TYPE) if targ: instance_type = \ targ.target.instance.runtime_properties.get( 'resource_config', {}).get( INSTANCE_TYPE_PROPERTY) or \ targ.target.node.properties.get( INSTANCE_TYPE_PROPERTY_DEPRECATED) params.update({INSTANCE_TYPE_PROPERTY: instance_type}) utils.update_resource_id(ctx.instance, params.get(RESOURCE_NAME)) iface.update_resource_id(params.get(RESOURCE_NAME)) # Actually create the resource if not iface.resource_id: setattr(iface, 'resource_id', params.get(RESOURCE_NAME)) iface.create(params) resource_arn = iface.properties[LC_ARN] utils.update_resource_arn(ctx.instance, resource_arn)
def create(ctx, iface, resource_config, **_): '''Creates an AWS EC2 Internet Gateway''' params = dict() if not resource_config else resource_config.copy() create_response = iface.create(params)['InternetGateway'] ctx.instance.runtime_properties['create_response'] = \ utils.JsonCleanuper(create_response).to_dict() utils.update_resource_id(ctx.instance, create_response.get(INTERNETGATEWAY_ID))
def create(ctx, iface, resource_config, **_): '''Creates an AWS RDS Option Group''' # Build API params resource_config.update(dict(OptionGroupName=iface.resource_id)) # Actually create the resource res_id, res_arn = iface.create(resource_config) utils.update_resource_id(ctx.instance, res_id) utils.update_resource_arn(ctx.instance, res_arn)
def create(ctx, iface, resource_config, **_): '''Creates an AWS RDS Subnet Group''' # Build API params params = ctx.instance.runtime_properties['resource_config'] or dict() params.update(dict(DBSubnetGroupName=iface.resource_id)) # Actually create the resource res_id, res_arn = iface.create(params) utils.update_resource_id(ctx.instance, res_id) utils.update_resource_arn(ctx.instance, res_arn)
def test_update_resource_id(self): mock_instance = MagicMock() mock_instance.runtime_properties = {} utils.update_resource_id(mock_instance, 'val') self.assertEqual(mock_instance.runtime_properties, {'aws_resource_id': 'val'})
def create(ctx, iface, resource_config, **_): '''Creates an AWS RDS Instance Read Replica''' # Build API params params = ctx.instance.runtime_properties['resource_config'] or dict() params.update(dict(DBInstanceIdentifier=iface.resource_id)) # Actually create the resource res_id, res_arn = iface.create(params) utils.update_resource_id(ctx.instance, res_id) utils.update_resource_arn(ctx.instance, res_arn)
def create(ctx, iface, resource_config, **_): '''Creates an AWS EC2 Vpc''' params = \ dict() if not resource_config else resource_config.copy() vpc = iface.create(params) vpc_id = vpc.get(VPC_ID, '') iface.update_resource_id(vpc_id) utils.update_resource_id(ctx.instance, vpc_id)
def prepare(ctx, resource_config, **_): '''Prepares an AWS Lambda Permission''' # Save the parameters if not utils.get_resource_id(): if resource_config.get('StatementId'): utils.update_resource_id(ctx.instance, resource_config['StatementId']) else: utils.update_resource_id(ctx.instance, str(uuid4())) ctx.instance.runtime_properties['resource_config'] = resource_config