If else in for_each statement in Terraform - if-statement

I'n actually reading a Json File with multiple Key value pairs in it, I need to create a resource based on the input user gives, for example, if he gives the 'A' I should choose from the first Key, if he gives 'B' I should chose the Second Key. Is it Possible in Terraform. I was able to do the If condition in For_each but I can only run it on one set of values, I need to choose the other set based on the user's input. Please help me out. Thanks in Advance.

Related

How AWS DynamoDB query result is a list of items while partition key is a unique value

I'm new to AWS DynamoDB and wanted to clarify something.
As I learned when we use query we should use the partition key which is unique among the list of items, then how the result from a query is a list!!! it should be one row!! and why do we even need adding more condition?
I think I am missing something here, can someone please help me to understand?
I need this because I want to query on list of applications with specific status value or for specific range of time but if I am supposed to provide the appId what is the point of the condition?
Thank you in advance.
Often your table will have sort key, which together with your partition key will create composite primary key. In this scenario a query can return multiple items. To return only one value, not a list, you can use get_item instead if you know unique value of the composite primary key.

How do I call a specific value from a dictionary inside a dictionary?

Currently am trying to make code which can pick out either specific or aggregate values for certain actions. I am using a nested dictionary for this, but am having issues calling specific values of nested dictionary. The code runs, but always brings the same value, not matter which key I originally tried to call
I have tried to have it print a variable set to the value of the key in the dictionary. I have also tried to use v.get() to retrieve the value from the dictionary.
properties={'lake':{'repairs':9001,'upgrades':3,'police investigations':69}
,'meadow':{'repairs':3,'upgrades':8}
,'beach':{'repairs':4,'upgrades':2}
,'country':{'repairs':5,'upgrades':54}}
choice=raw_input('Do you want to learn about a specific property or total actions? (type specific or total) ')
choice=choice.lower()
if choice[0]=='s':
for k,v in properties.items():
print(properties.keys())
properti=raw_input('Which property would you like to look at? (enter nothing to exit) ')
print properties[properti]
action=raw_input('What action is it you want to learn about? ')
result=v[action]
print('The '+properti+' property has had '+str(result)+' '+action+' completed.')
I expect when I call for a specific property, choose lake, then choose repairs, that I'd get the 9001. Or even going for meadow, I'd get 3 repairs. Currently I am always getting the country property's amounts for both repairs and upgrades.
Change the following
result=v[action]
to
result=properties[properti][action]

User Friendly Unique Identifier For DynamoDB

In my DynamoDB table named users, I need a unique identifier, which is easy for users to remember.
In a RDBMS I can use auto increment id to meet the requirement.
As there is no way to have auto increment id in DynamoDB, is there a way to meet this requirement?
If I keep last used id in another table (lastIdTable) retrieve it before adding new document, increment that number and save updated numbers in both tables (lastIdTable and users), that will be very inefficient.
UPDATE
Please note that there's no way of using an existing attribute or getting users input for this purpose.
Since it seems you must create a memorable userId without any information about the user, I’d recommend that you create a random phrase of 2-4 simple words from a standard dictionary.
For example, you might generate the phrase correct horse battery staple. (I know this is a userId and not a password, but the memorability consideration still applies.)
Whether you use a random number (which has similar memorability to a sequential number) or a random phrase (which I think is much more memorable), you will need to do a conditional write with the condition that the ID does not already exist, and if it does exist, you should generate a new ID and try again.
email address seems the best choice...
Either as a partition key, or use a GUID as the partition key and have a Global Secondary Index over email address.
Or as Matthew suggested in a comment, let the users pick a user name.
Docker container naming strategy might give you some idea. https://github.com/moby/moby/blob/master/pkg/namesgenerator/names-generator.go
It will result in unique (limited) yet human friendly
Examples
awesome_einstein
nasty_weinstein
perv_epstein
A similar one: https://github.com/jjmontesl/codenamize

Scalding operate on group after groupBy

I am writing a scalding job.
Here's what I want to do: first groupBy a Key. That should give me a bunch of (Key, Iterator[Value]) pairs for each Key (correct me if I'm wrong here). Then for each Ley, I want to apply a function on its associated Iterator[Value].
How should I do this? I am currently using a groupBy followed by a mapGroup. I get an Iterator[Value] but that iterator only has one value for some reason. mapGroup is not getting to operate on multiple values. It's important that I get to see all the values for any given key at the same time. Any ideas?
Thanks!

What is the key used in Session based windowing on Google dataflow

I am new to dataflow. I came across this example in the google documentation.
PCollection<String> items = ...;
PCollection<String> session_windowed_items = items.apply(
Window.<String>into(Sessions.withGapDuration(Duration.standardMinutes(10))));
1) In the above example, what would be the key used by dataflow to create windows?
2) If my input source is pubsub, should I set any message attributes and how can we specify what key dataflow should use when we go with Session based windowing.
Elements are assigned to sessions at the first grouping operation after the Window.into. Whatever key affects the GroupByKey, Combine.perKey, Sum.perKey, CoGroupByKey, etc. operation will be the grouping key.
You do not need to set message attributes to specify the key. Instead, you would write a ParDo to transform the existing elements into KV<K, V> values, and the key there would be derived from that.
You may want to read about group-by-key for for more info.