What I want to do is feed a list of key names to a module that will be used to generate many secrets with different random passwords in secrets manager.
I have tried many different things but have failed so far.
This is what I have currently:
module "secrets-manager-1" {
source = "lgallard/secrets-manager/aws"
for_each = var.list
secrets = {
"${each.value}" = {
description = each.value
recovery_window_in_days = 7
secret_string = random_password.special_password.result
}
}
tags = var.standard_tags
}
resource "random_password" "special_password" {
count = 2
length = 16
special = true
}
variable "list" {
type = list(string)
default = [
"secret_key_1",
"secret_key_2"
]
}
The Error:
│ Error: Invalid for_each argument
│
│ on ..\..\modules\jitsi\jitsi_secrets.tf line 54, in module "secrets-manager-1":
│ 54: for_each = var.list
│ ├────────────────
│ │ var.list is list of string with 2 elements
│
│ The given "for_each" argument value is unsuitable: the "for_each" argument must be a map, or set of strings, and you have provided a value of type list of string.
╵
Releasing state lock. This may take a few moments...
Unfortunately what you are providing is not even valid Terraform code. What I believe you would want to achieve the following:
// Create N random password. In this case N = 2
resource "random_password" "special_password" {
count = 2
length = 16
special = true
}
// Import a third party module
module "secrets-manager-1" {
source = "lgallard/secrets-manager/aws"
// Loop through the random_passowrd resouces and create the secrets
secrets = {
for index, pwd in random_password.special_password.*.result : "${element(var.list, index)}" => {
secret_string: "${pwd}",
recovery_window_in_days = 7
}
}
}
You may want to check out the splat expressions for being able to iterate over multiple resources. This is used for the for expression in the secrets-manager-1 module.
Related
I am trying to solve Leetcode 160. Intersection of Two Linked Lists:
Given the heads of two singly linked-lists headA and headB, return the node at which the two lists intersect. If the two linked lists have no intersection at all, return null.
For example, the following two linked lists begin to intersect at node c1:
The test cases are generated such that there are no cycles anywhere in the entire linked structure.
Note that the linked lists must retain their original structure after the function returns.
I wanted to use the two pointers to solve it, but the Leet Code site gives me a Time Limit Exceeded error.
My code is shown below:
ListNode *getIntersectionNode(ListNode *headA, ListNode *headB) {
ListNode *tempA = headA, *tempB = headB;
while (tempA != tempB) {
if (tempA->next != NULL) { tempA = tempA->next;}
else { tempA->next = headB;}
if (tempB->next != NULL) { tempB = tempB->next;}
else { tempB->next = headA; }
}
return tempA;
}
I then tried this existing solution and it works, but I cannot tell what's different:
ListNode *getIntersectionNode(ListNode *headA, ListNode *headB) {
ListNode *tempA = headA, *tempB = headB;
while (tempA != tempB) {
if (tempA != NULL) { tempA = tempA->next;}
else { tempA = headB;}
if (tempB != NULL) { tempB = tempB->next;}
else { tempB = headA;}
}
return tempA;
}
The algorithm should be a "read-only" algorithm, i.e. there should be no reason to modify the linked lists to determine the solution.
Yet, that is what the first version of the code does: it assigns a new reference to a node's next property. This should never happen: there is no good reason why a node's next property would need to get a new value when the only thing you want to do is "calculate" where a certain node is located and return it.
In this particular case tempA->next = headB; is linking the end of linked list A with the start of linked list B. To picture this, let's imagine the two lists are initially like this:
tempA
↓
┌────────────┐
headA:─► │ data: 2 │
│ next: ───────┐
└────────────┘ │ ┌────────────┐
└──► │ data: 3 │
┌──► │ next: NULL │
┌────────────┐ ┌────────────┐ │ └────────────┘
headB:─► │ data: 4 │ │ data: 5 │ │
│ next: ──────────► │ next: ───────┘
└────────────┘ └────────────┘
↑
tempB
The loop will in the first iterations always execute the if cases, and so after one iteration tempA and tempB will reference the next nodes:
┌────────────┐
headA:─► │ data: 2 │ tempA
│ next: ───────┐ ↓
└────────────┘ │ ┌────────────┐
└──► │ data: 3 │
┌──► │ next: NULL │
┌────────────┐ ┌────────────┐ │ └────────────┘
headB:─► │ data: 4 │ │ data: 5 │ │
│ next: ──────────► │ next: ───────┘
└────────────┘ └────────────┘
↑
tempB
And now, in the second iteration, the first else block will execute tempA->next = headB; which alters that tail node's next property, bringing about the following situation:
┌────────────┐
headA:─► │ data: 2 │ tempA
│ next: ───────┐ ↓
└────────────┘ │ ┌────────────┐
└──► │ data: 3 │
┌──► │ next: ────────┐
┌────────────┐ ┌────────────┐ │ └────────────┘ │
headB:─► │ data: 4 │ │ data: 5 │ │ │
┌─► │ next: ──────────► │ next: ───────┘ │
│ └────────────┘ └────────────┘ │
└───────────────────────────────────────────────────────────┘
↑
tempB
This is introducing a cycle in the linked list: there is now no more tail node -- there is no node anymore whose next property is NULL. As you can see that means the while condition will from now on always be true,... this has become an infinite loop. This explains why the platform that runs this code is signaling a "time limit exceeded" error.
I am new to terraform can some one point me what is the issue here ??
Error: Inconsistent conditional result types
│
│ on .terraform\modules\frontend_website.cloudfront\main.tf line 17, in resource "aws_cloudfront_distribution" "www_distribution":
│ 17: for_each = length(var.custom_error_response) == 0 ? [] : var.custom_error_response
│ ├────────────────
│ │ var.custom_error_response is object with 4 attributes
│
│ The true and false result expressions must have consistent types. The given
│ expressions are tuple and object, respectively.
dynamic "custom_error_response" {
for_each = length(var.custom_error_response) == 0 ? [] : var.custom_error_response
content {
error_caching_min_ttl = lookup(custom_error_response.value, "error_caching_min_ttl", "3000")
error_code = lookup(custom_error_response.value, "error_code", "404")
response_code = lookup(custom_error_response.value, "response_code", "200")
response_page_path = lookup(custom_error_response.value, "response_page_path", "/index.html")
}
}
Thanks Mark for the reply , i fixed it instead of object i put a square bracket and made it is array of object , that fixed it , thanks
I am getting an error "unhashable dict" for tmp_str = [{category : name }]. category and name are variables.
Tried options are
tmp_str = [{category : name }]
tmp_str = {category : name }
Complete code is here
def isAttributesIntheName(file_name,message):
table = db_client.Table(table_name)
count = table.item_count
json_msg = json.dumps(message)
print (json_msg)
numCount = 0
loop = 0
print (count)
for numCount in range (count):
name = table.scan()['Items'][numCount]['name']
result = file_name.lower().find(name)
category = table.get_item(Key={'name':name})
if result > 0:
tmp_str = [{category : name }]
json_str1 = dict(**json_str,**{tmp_str })
loop = loop + 1
print (json.dumps(json_str1))
For the specific error you are asking about, the variable category (results of querying your database table) is not a hashable type - e.g. is mutable type such as a dict or list. Dict keys need to be immutable so they can be hashed form a hash key.
It looks like you are querying a DynamoDB and the datatype returned by get_item is a dict, and within that dict there is a key 'Item' that has the data you are requesting in another dict. Here are the docs for get_item:
https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/dynamodb.html#DynamoDB.Table.get_item
Here is more info on "hashable":
What does "hashable" mean in Python?
My code requirement is something like this.
Using my temp_name variable, I want to search a list. If it does not exist in the list, I would like to use the same.
If it exists, then I will increment the count by 1 and search again until I find a unique name which does not exist.
count = 1
name = department
temp_name = "name" + '-' + str(count)
My List is as follows:
departments {
department-1
department-7
department-2
department-6
department-9
}
Could you please have a look.
I am basically querying all EC2 instances in AWS by their names.
import boto3
ec2= boto3.resource('ec2')
# Get information for all running instances
running_instances = ec2.instances.filter(Filters=[{
'Name': 'instance-state-name',
'Values': ['running']}])
for instance in running_instances:
for tag in instance.tags:
if 'Name'in tag['Key']:
name = tag['Value']
print name
And want to spin a new instance using a unique name which does not exist.
There is a bit of confusion between names and values of variables here:
name = department
temp_name = "name" + '-' + str(count)
You are looking for department-1 etc but temp_name actually contains name-1 etc. Fixing that,
departments = ["department-1","department-7","department-2","department-6","department-9"]
count = 1
temp_name = "department-%d" % count
while temp_name in departments:
count += 1
temp_name = "department-%d" % count
print temp_name
And, after that, probably,
departments.append(temp_name)
I want to configure a config.toml file in meta-toolkit with default filter chain but specifying each of the filters. I plan to make modifications to some of the filters so I want to have a baseline filter chain.
I have tried the following attributes:
[[analyzers]]
method = "ngram-word"
ngram = 1
[[analyzers.filter]]
type = "icu-tokenizer"
[[analyzers.filter]]
type = "lowercase"
[[analyzers.filter]]
type = "alpha"
[[analyzers.filter]]
type = "length"
min = 2
max = 35
[[analyzers.filter]]
type = "list"
filename = "../data/lemur-stopwords.txt"
[[analyzers.filter]]
type = "porter2-stemmer"
[[analyzers.filter]]
type = "empty-sentence"
I'm getting:
token_stream_exception: what(): file required for list_filter config
The attribute should be file instead of filename.
[[analyzers.filter]]
type = "list"
file = "../data/lemur-stopwords.txt"