I'm getting following Error while doing terraform apply - terraform-provider-aws

[root#terraform ~]# terraform plan -out terraform.tfstate
╷
│ Error: Error acquiring the state lock
│
│ Error message: 2 problems:
│
│ - Unsupported state file format: The state file could not be parsed as JSON:
│ syntax error at byte offset 1.
│ - Unsupported state file format: The state file does not have a "version"
│ attribute, which is required to identify the format version.
│
│ Terraform acquires a state lock to protect the state from being written
│ by multiple users at the same time. Please resolve the issue above and try
│ again. For most commands, you can disable locking with the "-lock=false"
│ flag, but this is not recommended.

#Ajay Kumar hi, problem is you are trying to pass .tfstate file as input and terraform is not able to parse same. terraform apply command expect .out file or .json file as input. Whereas .tfstate file is one where desired state of your infra is maintained (this is auto created by terraform itself). In this case what you can do is
Create one .tfvars file with all your configuration parameters (this will be served as input to terraform apply command)
touch input.tfvars
Next pass this input.tfvars file as input to your terraform apply command using -var-file flag and -out flag to generate .out file
terraform plan -var-file=input.tfvars -out inputplan.out
Next, you can use terraform apply command for above generated .out file
$ terraform apply "inputplan.out"
Refer this article for more information
https://medium.com/#hegdetapan2609/how-to-install-packages-on-multiple-similar-instances-at-same-time-using-terraform-182582af5260

Related

Terraform for Cloudfront: InvalidHeadersForS3Origin, but I'm not passing [*] to any S3 origin

Running terraform 1.0.8 on Windows, trying to configure AWS Cloudfront. I'm using state managed in S3.
My config has several origins and many behaviors all for one distribution. When I run terraform apply, I get the following error:
│ Error: error updating CloudFront Distribution (E2KIMIP81FA3TQ): InvalidHeadersForS3Origin: Your request contains forwarded Header Name * that is not allowed by S3.
│ status code: 400, request id: ac0ad34e-7208-46a2-9334-e55465391028
│
│ with aws_cloudfront_distribution.web-distribution,
│ on cloudfront.tf line 129, in resource "aws_cloudfront_distribution" "web-distribution":
│ 129: resource "aws_cloudfront_distribution" "web-distribution" {
But I've reviewed my .tf file many times and although I have some origins in S3, and some behaviors passing [] for the headers, there are no cases where I'm passing [] to an S3 origin. All of my behaviors passing wildcard headers are pointing to a Wordpress origin.
What could I be missing here?
Fixed!
I inserted headers = [ ] in behaviors where there was no headers node.

Run Firebase Callable HTTP Cloud Function locally

I've a deployed a callable function, say foo, using
firebase deploy --only functions:foo
and I'm calling it in Flutter using:
var result = await FirebaseFunctions.instance.httpsCallable('foo')();
var data = result.data;
All good. But I'd like to run this function in the Firebase Emulator. When I run
firebase emulators:start --only functions
I can see the emulator up and running, and I'm connecting my Flutter app to the emulator using:
FirebaseFunctions.instance.useFunctionsEmulator('localhost', 4000);
However, I don't know how to invoke the callable foo in Flutter using the Firebase Emulator. I saw this related thread but it doesn't really answer my question.
EDIT:
Here's the console output:
✔ functions[us-central1-foo]: http function initialized (http://localhost:5001/my_project/us-central1/foo).
┌─────────────────────────────────────────────────────────────┐
│ ✔ All emulators ready! It is now safe to connect your app. │
│ i View Emulator UI at http://localhost:4000 │
└─────────────────────────────────────────────────────────────┘
┌───────────┬────────────────┬─────────────────────────────────┐
│ Emulator │ Host:Port │ View in Emulator UI │
├───────────┼────────────────┼─────────────────────────────────┤
│ Functions │ localhost:5001 │ http://localhost:4000/functions │
├───────────┼────────────────┼─────────────────────────────────┤
│ Firestore │ localhost:8080 │ http://localhost:4000/firestore │
└───────────┴────────────────┴─────────────────────────────────┘
Emulator Hub running at localhost:4400
Other reserved ports: 4500
I tried
useFunctionsEmulator('localhost', 4000);
useFunctionsEmulator('localhost', 5001);
but both of them throw the following error on calling httpsCallable('foo') but without the emulators, this function does work.
[ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception: [firebase_functions/unavailable] UNAVAILABLE
I suspect your host and port values might be incorrect.
When you start up your emulator, the logs will display all the ports that are being used for your various emulators. There's also the firebase.json file that has the port configurations for the emulators.
Also, localhost is not automatically identified by the clients. For Android you might have to configure networkSecurityConfig in your manifest by creating a network security config xml. For iOS, I think there should be something that needs to be added in the plist file - has to be checked confirmed.
Once your clients are able to access localhost (implicitly or explicitly), you can connect to your emulated functions. For example, I have explicitly state the host value in my code (this is not expected to change across restarts).
Here is the code that I use in Kotlin:
functions = FirebaseFunctions.getInstance()
/*
* Emulator
* */
if (emulatorMode) { //Local Testing
functions.useEmulator("10.0.2.2", 5001)
} else { //Live
functions = Firebase.functions
}
// Call the function and extract the operation from the result
return functions
.getHttpsCallable(function)
.call(inputData)
.continueWith { task ->...
It doesn't seem like a port or setup issue to me. Your console seems to show the expected output.
Try this:
Inside Flutter, where you want to call the function, add:
http.get(Uri.parse('http://localhost:5001/my_project/us-central1/foo'))
You're going to have to set an env variable, that asks your application to check what environment it is in. If dev, then it should use url above, if prod it can use the prod url
this._cloudFunctions = FirebaseFunctions.instance;
_cloudFunctions.useFunctionsEmulator(origin: "http://<System's IP>:5001");
Systems ip we can get by typing ipconfig in command prompt.
Make sure you connect your ip and run emulators start.
For Flutter
As per the Firebase Flutter Docs-
There is a useFunctionsEmulator module as part of your Firebase Functions instance.
You can initialize it as follows:
FirebaseFunctions.instance.useFunctionsEmulator('localhost', 5001);
For Web
If you cd into the functions directory you can run npm start which will, by default, build and run the emulators locally in the shell. I've found this to be the only solution for testing callable functions locally.
The firebase team has provided a connectFunctionsEmulator submodule in the V9 modular SDK which is designed specifically to interact with your app locally.
You can checkout the official docs for this Here.
Running npm run serve will serve the emulator that you are expecting but I have been running into issues testing callable functions via url.

Result set larger than one row when Corda node use postgresql and schema

I'm currently trying to have 2 node (one notary , one normal node) using the same Postgresql DB for storing data (instead of the embedded H2), but with a different schema for each (node schema, notary schema) .
Ah , I'm using the non-enterprise version btw, version 4.3 .
The notary node is the first one to start, it creates the needed tables in the notary schema , all seems fine there .
But when the 'normal' node boot, it crash saying :
[ERROR] 10:17:50+0000 [main] changelog.ChangeSet. - Change Set migration/node-core.changelog-postgres-blob.xml::modify checkpoint_value column type::R3.Corda failed. Error: Migration failed for change set mig │
│ Reason: │
│ master.changelog.json : liquibase.precondition.core.SqlPrecondition#7c682e26 : Result set larger than one row │
│ {changeSet=migration/node-core.changelog-postgres-blob.xml::modify checkpoint_value column type::R3.Corda, databaseChangeLog=master.changelog.json} │
│ [ERROR] 10:17:50+0000 [main] internal.NodeStartupLogging. - Exception during node registration: Could not create the DataSource: Migration failed for change set migration/node-core.changelog-postgres-blob.xml: │
│ Reason: │
│ master.changelog.json : liquibase.precondition.core.SqlPrecondition#7c682e26 : Result set larger than one row │
│ [errorCode=14m37zv, moreInformationAt=https://errors.corda.net/OS/4.3/14m37zv] │
[ERROR] 10:17:50+0000 [main] internal.NodeStartupLogging. - Exception during node startup: net.corda.core.utilities.Try$Failure cannot be cast to net.corda.core.utilities.Try$Success [errorCode=rmnkpl, moreInf │
The node.conf I have for the notary is the following :
dataSourceProperties: {
dataSourceClassName="org.postgresql.ds.PGSimpleDataSource"
dataSource.url="jdbc:postgresql://psql-path:5432/postgres?currentSchema=notary"
dataSource.user="dbUser"
dataSource.password="xxxxxx"
}
And the one for the 'normal' node is :
dataSourceProperties: {
dataSourceClassName="org.postgresql.ds.PGSimpleDataSource"
dataSource.url="jdbc:postgresql://psql-path:5432/postgres?currentSchema=node"
dataSource.user="dbUser"
dataSource.password="xxxxxx"
}
So as you can see, the only difference is the ?currentSchema value .
Am I missing something ?
EDIT :
in the doc , they are saying :
If your PostgresSQL database is hosting multiple schema instances (using the JDBC URL currentSchema=my_schema) for different Corda nodes, you will need to create a hibernate_sequence sequence object manually for each subsequent schema added after the first instance. Corda doesn’t provision Hibernate with a schema namespace setting and a sequence object may be not created. Run the DDL statement and replace my_schema with your schema namespace:
I have done that and when connecting to the db , I can see taht for both schema I have tables created . Though for the notary I have 32 tables and only 26 for the 'normal' node .
Classic case of documentation overlooking , the solution is :
If your PostgresSQL database is hosting multiple schema instances (using the JDBC URL currentSchema=my_schema) for different Corda nodes, you will need to create a hibernate_sequence sequence object manually for each subsequent schema added after the first instance. Corda doesn’t provision Hibernate with a schema namespace setting and a sequence object may be not created. Run the DDL statement and replace my_schema with your schema namespace:
I was trying to use different schemes for different nodes. But i failed. Because there are some automatically-created tables without scheme. So i decided to use different database instances on the same db server.
I think this method might relieve your pain a little bit.

debugging firebase on local windows

I'm trying to debug firebase function on my local windows
as described in https://medium.com/#mwebler/debugging-firebase-functions-with-vs-code-3afab528bb36
I do
set FIREBASE_CONFIG={ databaseURL: 'https://invoice-manager-251609.firebaseio.com', storageBucket: 'invoice-manager-251609.appspot.com', projectId: 'invoice-manager-251609'}
functions start
and get
┌────────┬────────┬─────────┬─────────────────────────────────────────────────────────────────┐
│ Status │ Name │ Trigger │ Resource │
├────────┼────────┼─────────┼─────────────────────────────────────────────────────────────────┤
│ FAILED │ upload │ HTTP │ http://localhost:8010/invoice-manager-251609/us-central1/upload │
├────────┼────────┼─────────┼─────────────────────────────────────────────────────────────────┤
│ FAILED │ tst │ HTTP │ http://localhost:8010/invoice-manager-251609/us-central1/tst │
├────────┼────────┼─────────┼─────────────────────────────────────────────────────────────────┤
│ FAILED │ tst1 │ HTTP │ http://localhost:8010/invoice-manager-251609/us-central1/tst1 │
└────────┴────────┴─────────┴─────────────────────────────────────────────────────────────────┘
if I do
firebase emulators:start
I get
undefinedWarning, estimating Firebase Config based on GCLOUD_PROJECT.
Initializing firebase-admin may fail[2019-10-06T11:44:51.932Z]
#firebase/database: FIREBASE FATAL ERROR: Cannot parse Firebase url.
Please use https://.firebaseio.com
I also tried:
functions debug tst1
and get:
ERROR: Function worker crashed with exit code: 9
undefined(node:21096) [DEP0062] DeprecationWarning: `node --debug
and
node --debug-brkare invalid. Please usenode --inspectornode --inspect-brk` instead.
I tried with node-10 and node-8
I also tried this:
https://medium.com/#david_mccoy/build-and-debug-firebase-functions-in-vscode-73efb76166cf
and this
https://rominirani.com/google-cloud-functions-tutorial-debugging-local-functions-357c24829198
I get the same errors
whats going on?
how do I debugging firebase on local windows?
The guides in the question are correct, but
when running in Emulator, u have to set the db url manually
admin.initializeApp({
databaseURL: "https://<YOUR FIREBASE>.firebaseio.com"
});
here is the full cmd list:
functions start
functions deploy --trigger-http --timeout 600s funcName
functions inspect funcName
After that u can use chrome://inspect/ to connect to the process with the chrome debugger.
If you have issues, u can use:
functions logs read
NOTE: after functions start I still get the table with FAILED status - I ignore it

how to show all package dependency tree

Since 0.9.3 I'm having some problems with meteor package dependencies, for example some third party packages don't declare all of their dependencies (like underscore, which would normally be included but not when used by another package).
Is there a simple way to show the tree of dependencies, much like npm does?
meteor list
will show what's in your project
.meteor/versions will show all packages
but I'm trying to find out what is including (or not) other packages.
currently I'm getting errors like the following, but haven't included Minimongoid afaik and grepping finds no reference to it.
W20141001-19:19:46.137(-7)? (STDERR) /Users/dc/.meteor/packages/meteor-tool/.1.0.33.he3qxx++os.osx.x86_64+web.browser+web.cordova/meteor-tool-os.osx.x86_64/dev_bundle/lib/node_modules/fibers/future.js:173
W20141001-19:19:46.137(-7)? (STDERR) throw(ex);
W20141001-19:19:46.138(-7)? (STDERR) ^
W20141001-19:19:46.141(-7)? (STDERR) ReferenceError: Minimongoid is not defined
W20141001-19:19:46.141(-7)? (STDERR) at collections/user.coffee:1:20
W20141001-19:19:46.141(-7)? (STDERR) at /Users/dc/dev/shumi/package-dev/app/.meteor/local/build/programs/server/app/collections/user.coffee.js:24:3
W20141001-19:19:46.142(-7)? (STDERR) at /Users/dc/dev/shumi/package-dev/app/.meteor/local/build/programs/server/boot.js:168:10
W20141001-19:19:46.142(-7)? (STDERR) at Array.forEach (native)
W20141001-19:19:46.142(-7)? (STDERR) at Function._.each._.forEach (/Users/dc/.meteor/packages/meteor-tool/.1.0.33.he3qxx++os.osx.x86_64+web.browser+web.cordova/meteor-tool-os.osx.x86_64/dev_bundle/lib/node_modules/underscore/underscore.js:79:11)
W20141001-19:19:46.142(-7)? (STDERR) at /Users/dc/dev/shumi/package-dev/app/.meteor/local/build/programs/server/boot.js:82:5
While we're waiting for the official tools to have this functionality, here's the uglyslow vershion:
for p in `meteor list | grep '^[a-z]' | awk '{ print $1"#"$2 }'`; do echo "$p"; meteor show "$p" | grep -E '^ [a-z]'; echo; done
This will show the dependencies of all added packages. It parses the output of meteor list and meteor show package#version and will break when anything there changes.
As of Meteor v1.5.2 (released 2017-09-05) you can now see the full dependency tree like this:
meteor list --tree
Here's what the output looks like:
$ meteor list --tree
accounts-password#1.4.0
├─┬ accounts-base#1.3.4
│ ├─┬ callback-hook#1.0.10
│ │ └── underscore#1.0.10
│ ├── check#1.2.5 (top level)
│ ├─┬ ddp#1.3.1
│ │ ├─┬ ddp-client#2.1.3
│ │ │ ├── callback-hook#1.0.10 (expanded above)
│ │ │ ├── check#1.2.5 (top level)
│ │ │ ├─┬ ddp-common#1.2.9
The pull request was contributed by sdarnel and can be found here for those interested:
https://github.com/meteor/meteor/pull/8936
Here's what I did...
I ran meteor list, and copied the output to notepad, to refer back to later.
Then, I went down the entire list, entering: meteor show <package> looking in the output for: Implies: whatever... that's the part that tells you what the particular package is including. Basically, the part of the output that says "Implies: something", those are the dependencies of the package you ran meteor show <package> for.
Then... if you take the packages in "Implies: foopackage", and run "meteor show foopackage" that will tell you that dependency's dependencies.
Basically, this is a crude solution to this problem which there is no official solution/feature/command for.
Good luck.
P.S. in my case, I wanted to see what was including iron:router, and through the above process, I determined it was useraccounts:semantic-ui that was including useraccounts:core, which in turn was including iron:router (which isn't in meteor list!)
See the following page for more info: https://github.com/meteor/meteor/issues/2853
I wrote some code here to build up a package tree, and make pictures like this:
It worked on the raw source code of the meteor distribution, so it'd need some tweaking to work on an actual app (and I cant help with that at the moment), but it'd be a start...

Resources