Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
badra001 committed Apr 28, 2023
1 parent 1cd2c99 commit 9ca59d9
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 8 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ No modules.
| <a name="input_enable_sns"></a> [enable\_sns](#input\_enable\_sns) | Enable use of SNS for reporting errors | `bool` | `false` | no |
| <a name="input_enable_sqs"></a> [enable\_sqs](#input\_enable\_sqs) | Enable use of SQS for SNS to send errors. Requires the use of enable\_sns as well | `bool` | `false` | no |
| <a name="input_kms_key_name"></a> [kms\_key\_name](#input\_kms\_key\_name) | Different KMS Key (for SNS and SQS) to override default of var.name | `string` | `null` | no |
| <a name="input_lambda_environment_variables"></a> [lambda\_environment\_variables](#input\_lambda\_environment\_variables) | Map of lambda environment variables and values | `map(string)` | <pre>{<br> "DNS_RR_TimeToLive": 60,<br> "DebugLogLevel": "INFO",<br> "DynamoDBName": null,<br> "HeritageIdentifier": "dynr53",<br> "HeritageTXTRecordPrefix": "_txt",<br> "MaxApiRetry": 10,<br> "SleepTime": 60,<br> "SnsEnable": false,<br> "SnsTopicArn": "",<br> "TagKeyCname": "boc:dns:cname",<br> "TagKeyFlags": "boc:dns:flags",<br> "TagKeyHostName": "boc:dns:name",<br> "TagKeyPtrname": "boc:dns:ptrname",<br> "TagKeyZone": "boc:dns:zone"<br>}</pre> | no |
| <a name="input_lambda_environment_variables"></a> [lambda\_environment\_variables](#input\_lambda\_environment\_variables) | Map of lambda environment variables and values | `map(string)` | <pre>{<br> "DNS_RR_TimeToLive": 60,<br> "DebugLogLevel": "INFO",<br> "DynamoDBName": null,<br> "EMRTagPrefix": "aws",<br> "HeritageIdentifier": "dynr53",<br> "HeritageTXTRecordPrefix": "_txt",<br> "MaxApiRetry": 10,<br> "RemoteRoleArnFormat": "arn:%s:iam::%s:role/r-inf-dynamic-route53-actions",<br> "SleepTime": 60,<br> "SnsEnable": false,<br> "SnsTopicArn": "",<br> "TagKeyCname": "boc:dns:cname",<br> "TagKeyFlags": "boc:dns:flags",<br> "TagKeyHostName": "boc:dns:name",<br> "TagKeyPtrname": "boc:dns:ptrname",<br> "TagKeyZone": "boc:dns:zone"<br>}</pre> | no |
| <a name="input_lambda_environment_variables_override"></a> [lambda\_environment\_variables\_override](#input\_lambda\_environment\_variables\_override) | Map of lambda environment variables and values to override from the defaults | `map(string)` | `{}` | no |
| <a name="input_lambda_name"></a> [lambda\_name](#input\_lambda\_name) | Different Lambda name to override default of var.name | `string` | `null` | no |
| <a name="input_name"></a> [name](#input\_name) | Name to use within all the created resources (default: inf-dynamic-route53) | `string` | `"inf-dynamic-route53"` | no |
Expand Down
18 changes: 11 additions & 7 deletions code/ddns-lambda.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
LOGGER = logging.getLogger()
account_id = None
region = None
VERSION = '2.0.0rc3'
VERSION = '2.0.0rc4'

# Read Env variables
DEBUG_LOG_LEVEL = os.environ.get('DebugLogLevel', 'INFO')
Expand All @@ -88,8 +88,10 @@
DNS_RR_TTL = 60 if DNS_RR_TTL == 0 else DNS_RR_TTL
TF_MODULE_VERSION = os.environ.get('tf_module_version', '(unknown)')
MAX_API_RETRY = int(os.environ.get('MaxApiRetry', '10'))
REMOTE_ROLE_ARN_FORMAT = 'arn:%s:iam::%s:role/r-inf-dynamic-route53-actions'
REMOTE_ROLE_NAME = 'r-inf-dynamic-route53-actions'
REMOTE_ROLE_ARN_FORMAT = os.environ.get(
'RemoteRoleArnFormat', 'arn:%s:iam::%s:role/r-inf-dynamic-route53-actions')
REMOTE_ROLE_NAME = REMOTE_ROLE_ARN_FORMAT.partition('/')[2]
EMR_TAG_PREFIX = os.environ.get('EMRTagPrefix', 'aws')

# for SNS topic
SNS_TOPIC_ARN = os.environ.get('SnsTopicArn', '')
Expand Down Expand Up @@ -3046,7 +3048,7 @@ def tags_to_dict(tags):

tag_dict = {}
if len(tags) > 0:
tag_dict = {tag.get('Key', '').lstrip().rstrip(): tag.get('Value', '') for tag in tags}
tag_dict = {tag.get('Key', '').lstrip().rstrip() : tag.get('Value', '') for tag in tags}
return tag_dict


Expand Down Expand Up @@ -3275,7 +3277,8 @@ def create_fqdn(host, zone):

def discover_emr_cluster(tags):
"""
This tags a dict of tags and determines if the appropriate EMR tags are set.
This tags a dict of tags and determines if the appropriate EMR tags are set. For testing, you can set EmrTagPrefix to emr, and then set
your tags to emr: vs aws: as listed below (because you cannot create a tag that starts with aws:).
If set, this is a member of an EMR cluster with the cluster_id as the value:
- aws:elasticmapreduce:job-flow-id = j-xxxxxxx
Expand All @@ -3288,8 +3291,9 @@ def discover_emr_cluster(tags):
"""

cluster_tuple = namedtuple('EMRCluster', ['is_cluster', 'is_master', 'cluster_id'])
cluster_id = tags.get('emr:elasticmapreduce:job-flow-id', '')
is_master = tags.get('emr:elasticmapreduce:instance-group-role', '') == 'MASTER'
cluster_id = tags.get('{EMR_TAG_PREFIX}:elasticmapreduce:job-flow-id', '')
is_master = tags.get(
'{EMR_TAG_PREFIX}:elasticmapreduce:instance-group-role', '') == 'MASTER'
is_cluster = cluster_id != ''

result = cluster_tuple(is_cluster, is_master, cluster_id)
Expand Down
Binary file modified code/ddns-lambda.zip
Binary file not shown.
3 changes: 3 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ variable "lambda_environment_variables" {
SleepTime = 60
SnsEnable = false
SnsTopicArn = ""
RemoteRoleArnFormat = "arn:%s:iam::%s:role/r-inf-dynamic-route53-actions"
EMRTagPrefix = "aws"
TagKeyCname = "boc:dns:cname"
TagKeyHostName = "boc:dns:name"
TagKeyZone = "boc:dns:zone"
Expand All @@ -55,6 +57,7 @@ variable "lambda_environment_variables" {
}
}


variable "lambda_environment_variables_override" {
description = "Map of lambda environment variables and values to override from the defaults"
type = map(string)
Expand Down

0 comments on commit 9ca59d9

Please sign in to comment.