lundi 24 mai 2021

How to automatically add aws(can be any cloud) provider details into terragrunt.hcl

I have Terragrunt folder structure like below,

|-- eu-west-1
|   |-- product
|   |   |-- prod
|   |   |   |-- 5.7
|   |   |   |-- 6.2
|   |   |   |-- development
|   |   |   |   |-- fargate-clusters
|   |   |   |   |   |-- module.tf.json
|   |   |   |   |   `-- terragrunt.hcl
|   |   |   |   `-- uiapp
|   |   |   |       |-- terragrunt.hcl
|   |   |   |       `-- module.tf.json
|   |   |   `-- env.hcl
|   |   |-- dev
|   |   |   |-- 5.7
|   |   |   |   |-- fargate-clusters
|   |   |   |   |   |-- module.tf.json
|   |   |   |   |   `-- terragrunt.hcl
|   |   |   |   `-- uiapp
|   |   |   |       |-- terragrunt.hcl
|   |   |   |       `-- module.tf.json
|   |   |   |-- development
|   |   |   |   |-- fargate-clusters
|   |   |   |   |   |-- module.tf.json
|   |   |   |   |   `-- terragrunt.hcl
|   |   |   |   `-- uiapp
|   |   |   |       |-- terragrunt.hcl
|   |   |   |       `-- module.tf.json
|   |   |   `-- env.hcl
|   |-- region.hcl
|-- README.md
`-- terragrunt.hcl

And I have multiple accounts configured inside my terragrunt.hcl

provider "aws" {
  alias  = "product-dev"
  region = "${local.aws_region}"
  assume_role {
    role_arn     = "arn:aws:iam::123456789:role/TerraformRole"
  }
}

There are more than AWS 50 accounts we are managing and we keep on adding new accounts into Terragrunt.

Is there a known pattern already to dynamically tell terraform/terragrunt about the new acccount id and the IAM role to assume?

As of now, every time I have to manually add the provider into terragrunt.hcl and account id into env.hcl

dimanche 23 mai 2021

Laravel - Correct way to process query result

Is there a design, pattern or area, to process result of a query?

Ex: I have a query to returns a list of timestamps. I need to calculate some information based on this information and return it to the user.

Where would be the best place to process this data, in the repository, controller, or some separate place?

Toaster system design

I am studying system design questions for interviews. I am so new to this type of question. I have a question and want you to help me better understand this kind of question and how should I approach it.

Sample question: Design a toaster.

My ideas:

  • Toaster can have multiple racks/slots (1,2,3,4)

  • There will be ToastType. I thought it will be enum { Bagel, bread, muffin}

  • There will be shade level. This can have different values based on the Toaster model. Mainly it is int field can have value 1 to 7.

  • Also there can be "defrost", "reheat" and "cancel" options. Those can be also varied based on Toaster Model

  • Toaster will have the "Toast" method

  • ToasterManager class will get a toaster with specific config and items and call the "Toast" method.

  • I can use a factory design pattern for the Toaster to create a clean, extendible solution. New Toasters can easily be added.

I can't put those ideas into classes. I am also confused that this problem should be solved using a state design pattern or a simple OOP implementation type of question. I feel that I am lost between ideas. Can you help me to clarify and show me how should approach those problems?

Thanks

Python design pattern for HTTP Requests monitoring

I have been quite into design patterns as I can see it as a huge advatange to follow and easy to maintain in the future. I did find DP Guru that provides different design patterns however my next project is about sending multiple GET requests to multiple sites concurrently (threading) and to monitor it and then see if there has been any changes on the webpage (A check can be every 2min).

I was not able to find then "perfect" design pattern for it and I am here to ask you guys which design pattern would fit a project that is based on doing GET requests to multiple sites concurrently?

samedi 22 mai 2021

How to deal with duplicated function code that alters parent state

Say we got a Page-component that delegates the rendering of notifications to a Notification-component. The Page-component's render method contains the following ...

{this.state.notifications &&
            <Notifications
                     notifications={this.state.notifications}
                     removeNotifAt={index => this.setState(prevState => {
                         const copy = [...prevState.notifications]
                         copy.splice(index, 1)
                         return { notifications: copy }
                     })}
                     removeNotifyBy={id => this.setState(prevState => {
                         const copy = [...prevState.notifications]
                         const index = copy.findIndex((notif, _) => { return notif.id === id })
                         copy.splice(index, 1)
                         return { notifications: copy }
                     })}
            />
}

... as you might notice, Notifications require some rather large function to alter the state of its parent. Since they access this.state, these functions have to be defined in the parent of Notifications, in this case Page.

Now, one can imagine that multiple pages have notifications that needs rendering and so they all have to code-duplicate the code snippet above. As we all know, code-duplication is bad, so how can we best avoid it?

It's impossible to extract the functions removeNotifyAt and removeNotifyBy out into functions defined in, say, Notifications.js since they need to access this.state.

So, what's the react-way of dealing with such duplicate functions that you can't extract away because it needs to access this.state? I suppose I am not the first one stumpling upon this, giving how trivial of a case this is.

Number pattern in c programming

          11
       11 10 11
    11 10 9  10 11
 11 10 9  8  9  10 11

I am Not able to solve this question, any anyone please help me to solve this number pattern in c programming.

Appropriate design patterns for a certain condition? [closed]

To start with the project that I am currently making, I need to input two arguments, "online or offline" and another "online or offline" when running the program.

  1. The first argument is input and the second argument is output.
  2. Each of the arguments can either be online or offline.
  3. When the first argument is set as online, a certain process such as showListofSomething() should be derived from an online rest API, if offline, just from a text file with mock data.
  4. When the second argument is set as online, the output should be stored in the database, if offline, just in a text file.

For example, the program runs with the command, run --args="online offline".

When switching in between online and offline, I used a facade pattern and therefore my code in the main class became simple

e.g) facade.online(); or facade.offline();

So what I want to ask is,

I need to cover up the two arguments, not just one like the above. So, which design pattern should I use in order to write code in the main class like:

facade.online().offline(); or facade.offline().offline()?

Is the builder pattern appropriate to be used for this?