How to make AWS Api Gateway deployment depend on dynamic list using Terraform - terraform-provider-aws

When I generate resources, methods etc. using "for_each", how can I make a deployment depend on them? Terraform requires a static list as value for "depends_on"

I think what you are looking for here is this (somewhat hidden) reference in terraform documents about triggers
I was facing the same issue (using for_each to create gateway methods, integrations) but was not able to reliably trigger api-gateway redeployment, until this...
... or removing the .id references to calculate a hash against whole resources. Be aware that using whole resources will show a difference after the initial implementation. It will stabilize to only change when resources change afterwards
This allow us to do the following in triggers
triggers = {
redeployment = sha1(jsonencode([
aws_api_gateway_resource.gateway_resources,
aws_api_gateway_method.gateway_methods,
aws_api_gateway_integration.gateway_integrations,
]))}
By removing .id (and thus not needing to reference each.key, or any element in the dynamic list) you let terraform decide if the hash of the file changed. If it did it will redeploy, if it doesnt change, then no redeploy required :)
Reference https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/api_gateway_deployment#terraform-resources
Look at the comments on 'triggers'

Related

How do you manage adding new attributes on existing objects when using firebase?

I have an app using React + Redux and coupled with Firebase for the backend.
Often times, I will want to add some new attributes to existing objects.
When doing so, existing objects won't get the attribute until they're modified with the new version of the app that handles those new attributes.
For example, let's say I have a /categories/ node, in there I've got objects such as this :
{
name: "Medical"
}
Now let's say I want to add an icon field with a default of "
Is it possible to update all categories at once so that field always exists with the default value?
Or do you handle this in the client code?
Right now I'm always testing the values to see if they're here or not, but it doesn't seem like a very good way to go about it. I'd like to have one place to define defaults.
It seems like having classes for each object type would be interesting but I'm not sure how to go about this in Redux.
Do you just use the reducer to turn all categories into class instances when you fetch them for example? I'm worried this would be heavy performance wise.
Any write operation to the Firebase Database requires that you know the exact path to the node that you're writing.
There is no built-in operation to bulk update nodes with a path that is only partially known.
You can either keep your client-side code robust enough to handle the missing properties, or you can indeed run a migration script to add the new property to each relevant node. But since that script will have to know the exact path of each node to write, it will likely first have to read/query the database to determine those paths. Depending on the number of items to update, it could possibly use multi-location updates after that to update multiple nodes in one call. E.g.
firebase.database().ref("categories").update({
"idOfMedicalCategory/icon": "newIconForMedical",
"idOfCommercialCategory/icon": "newIconForCommercial"
"idOfTechCategory/icon": "newIconForTech"
})

Passing value between two components in angular2-meteor project

I am using angular2-meteor.
When I try to pass a value between two components (when the value change in the first component, create an event in second component and use this new value), I have two ways right now:
One way is meteor way: using this.autorun and Session.get.
Another way is angular2 way: using Injectable service with EventEmitter.
Which way should be prior? Or is there any other better way? Thanks
Now I used angular2-meteor a while.
Although the angular2-meteor tutorial has no example so far about using or choosing Angular 2 service or Meteor Session.
But I feel angular 2 takes the lead in the front end, while meteor makes reactivity easier and also handle all back end things.
So I went with angular2 way using service to share between components. And service is very powerful like #todd-w-crone said.
If anyone has better answer, I will switch to accept that one.
I find it practical to create a new service called App.states.ts which is accessed globally and mimics Session (get / set).
I commonly import this service to all necessary components to get or set new value such as User.status, company.profile, lastProduct, etc.
Since this service is #injectable it can also make use of other services, in case a value hasn't been set already.
This allows me to ask for a variable in a component appState.getLastModifiedItem(), then in app.states.ts I'll write this function to pass this.modifiedItem or either:
Request another service item.service.ts to fetch data
Call another function with itemCollection.findOne({...}) and return such value.
You can configure Mongo queries as you want and either store static data in appState or keep subscription items in appState.
Do take into consideration that all subscriptions handled by an #injectable within a component are imported by such component. Be wary of conflicting subscriptions between components/services.

OpenStack - Check for Availability of Container C# .NET

I have integrated openstack to my .net solution. I am using CloudFilesProvider to create and delete a container. Is there any provision to check for the existence of a container using C#.
I know it is possible to check by getting ObjectStore and find ContainerExists property. But i am not sure how to get this property filled.
Any help will be greatly appreciated.
ObjectStore is an enumeration that defines the possible values returned by calls like IObjectStorageProvider.CreateContainer. For example, you could get an ObjectStore by attempting to create the container you're checking, and the return value would be ContainerExists if the container already exists. Unfortunately you could always end up with ContainerCreated returned by that call, i.e. if you use CreateContainer to check for a container's existence, then even if the container didn't exist before "checking", it would afterwards.
While it's definitely not clean, one option is calling GetContainerMetadata. The call will throw an ItemNotFoundException if the container doesn't exist.
Are you, by chance, using this Container as a CDN?
When deleting a CDN, you must also call the method "DisableCDNOnContainer" against the Container. Also, if you call the method "ListCDNContainers", you must filter out deleted CDN Containers by checking the property "CDNEnabled".
This is because deleted Containers "hang around" until their ttl expires.

How can I make changes on my Collections locally (minimongo)?

What to do when I want to make changes on my data Collection but I do not want to persist it? In other words, I want to make changes on minimongo, locally, but I do not want to spread it to world.
Use _collection.
MyCollection = new Meteor.Collection('my-collection');
// Subscribe as you see fit
Meteor.subscribe('my-publication');
// Now, to make updates locally you can access the documents in the collection without
// making any calls to the sever.
MyCollection._collection.insert({key:value});
MyCollection._collection.update({key:value}, {key:value});
Works with the usual mini-mongo operations.
This is undocumented and might change in future releases of Meteor without notice.
According to the docs, we can create a Collection and set its name as null. It will create an unmanaged (unsynchronized) local collection.
Unfortunately, it seems to not be possible to make local changes in synchronized collections.
You can create what I call a "local mirror" of a shared collection. Here's a gist with baisc functionality: https://gist.github.com/belisarius222/4715531
The idea is that you wire up a new local collection (new Meteor.Collection(null)) so that any change in the shared collection gets applied to the local collection too.

Drupal 7 db_set_active() in mymodule_init()?

I am trying to change which DB connection to used based on several conditions inside a custom module hook, aptly named mymodule_init()
hook_init() seemed a logical place to put this functionality because it's called so early in the bootstrap game, before any DB queries???
So I have several connections in a pool and which one is used is determined by the module. For the life of I can't get the system to persist the DB - seems to be resetting itself back to 'default' after this hook is executed. Searching the codebase has little effect as well only one or two calls to db_set_active() are made.
ANy ideas? What hook should I override to change the DB connection at runtime before any DB activity has be done???
Cheers,
Alex
Hardly is hook_init "early in the game" and certainly not the first to fire database queries. The bootstrap order is: load configuration, try to serve the page from cache, initialize the database, load variables, load session, page header. The first hook to fire is hook_boot either if the page cache has a hit or in page header -- by then at least the variable init phase have fired a query either to load the variables from the database (or to retrieve them from cache but you can't rely on cache and the default cache is database anyways). All is not lost, however. You can either put your code right in settings.php or write a small cache handler, something like this:
class HackyDatabaseCache extends DrupalDatabaseCache {
function __construct($bin) {
// your code finding the database here.
parent::__construct($bin);
}
}
add $conf['cache_backends'][] = 'path/to/hackydatabasecache.inc'; and $conf['cache_class_cache_page'] = 'HackyDatabaseCache'; to your settings.php. This will make sure your code fires before any queries. If you are using memcache or mongodb for caching, then extend that with the same code just change which class is extended.

Resources