Eximchain / terraform-aws-dappbot

Terraform infrastructure to run ABI Clerk
Other
0 stars 1 forks source link

terraform-aws-dappbot

Terraform infrastructure to run DappBot

Deployment

Before terraform applying this module, the dappsmith-builder image needs to have been built into an Amazon ECR repository. The image probably already exists, but if you need to build it yourself, scroll down for Packer Build instructions.

Terraform Apply

Before trying to run terraform apply, you need to:

Packer Build

If you need to build the image yourself, first make sure that you set the following NPM auth variables in your terminal (e.g. export NPM_EMAIL=test@example.com):

You can find these value under the "NPM service account" in the Eximchain 1Password. Also double-check that the aws_account_id, aws_region, repository, and image_tag variables are all set to appropriate values within the variables key of packer/dappsmith-builder.json. Once that is complete, you can build:

$ cd packer
$ packer build dappsmith-builder.json
$ cd ../terraform
$ ... double check everything from section above ...
$ terraform apply

Dev Testing

You can run test calls against the API from the sampleCalls directory.

First change the DappName in create/read.json, and don't commit your changes.

Create a user

After the Terraform configuration has been applied, use the script to create a user:

USER_POOL_ID=<User Pool ID output from Terraform configuration>
EMAIL=<An email address you have access to>
NUM_DAPPS=<The dapp limit to apply to this user>

python3 test-auth.py --username $EMAIL create --user-pool-id $USER_POOL_ID --num-dapps $NUM_DAPPS

By default the --num-dapps argument applies to all tiers. You can use an additional optional argument to override --num-dapps for a specific tier. For example, to allow 5 standard, 2 professional, and 0 enterprise dapps you could use the following command instead:

python3 test-auth.py --username $EMAIL create --user-pool-id $USER_POOL_ID --num-dapps $NUM_DAPPS --standard-limit 5 --professional-limit 2 --enterprise-limit 0

Note that --num-dapps must be specified even if all tiers have overrides specified.

Change user password

Once you get your temporary password, browse to the login_url that was output by Terraform. Log in with your temporary password and set a permanent password. Once your password is set, this user can be used for testing.

Authenticate as user

Once the user's password is fully set, run the following to authenticate:

EMAIL=<The email for your test user>
CLIENT_ID=<Client ID output from Terraform configuration>
PASSWORD=<The password for your test user>

python3 test-auth.py --username $EMAIL login --client-id $CLIENT_ID --password $PASSWORD

API Test

Set the AUTH_TOKEN and then make calls to the API

API_TOKEN=<API Token from Authentication Step>
curl -XPOST -H "Authorization: $AUTH_TOKEN" -d @create.json https://api-test.eximchain-dev.com/test/create
curl -XPOST -H "Authorization: $AUTH_TOKEN" -d @read.json https://api-test-2.eximchain-dev.com/test/read
curl -XPOST -H "Authorization: $AUTH_TOKEN" -d @read.json https://api-test-2.eximchain-dev.com/test/delete

Clean up user

You can clean up your test user with the following command:

USER_POOL_ID=<User Pool ID output from Terraform configuration>
EMAIL=<The email for your test user>
python3 test-auth.py --username $EMAIL delete --user-pool-id $USER_POOL_ID