Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an IHP terraform configuration for AWS #7

Merged
merged 4 commits into from
Jul 16, 2024

Conversation

mokshasoft
Copy link
Contributor

This is a work in progress, the deployment still doesn't work. The instance setup with a database and security groups work though. It is possible to ssh to the instance and run psql commands towards the database.

To deploy the infrastructure, cd to the IaC folder and create the file terraform.tfvars:

prefix = "blog-example"
key_name = "an SSH key-pair name"
db_password = "a password"

The from the IaC folder, run the following commands:

terraform init
terraform apply

The apply command will create a file, db_info.txt, with deployment details:

Instance URL: ec2-...-.compute.amazonaws.com
DB Endpoint: blog-example-postgres-db....rds.amazonaws.com
DB Username: postgres_user
DB Password: The password you choose

Add the instance URL to .ssh/config so you can run ssh and deploy-to-nixos.

Running deploy-to-nixos triggers the following error:

$ deploy-to-nixos ihp-app
building the system configuration...
error (ignored): error: end of string reached
error:
       … while calling the 'head' builtin

         at /nix/store/sc2fmza4wlzi16jjjmkg6rmmmf75jxmr-source/lib/attrsets.nix:1575:11:

         1574|         || pred here (elemAt values 1) (head values) then
         1575|           head values
             |           ^
         1576|         else

       … while evaluating the attribute 'value'

         at /nix/store/sc2fmza4wlzi16jjjmkg6rmmmf75jxmr-source/lib/modules.nix:809:9:

          808|     in warnDeprecation opt //
          809|       { value = builtins.addErrorContext "while evaluating the option `${showOption loc}':" value;
             |         ^
          810|         inherit (res.defsFinal') highestPrio;

       (stack trace truncated; use '--show-trace' to show the full trace)

       error: getting status of '/nix/store/f213d8z2gckhdk6zfx6hjs7zriish4mr-source/Application/Migration': No such file or directory
Failed to start migrate.service: Unit migrate.service not found.

I'm not skilled enough to debug nix things to I'm stuck at this. The flake.nix is basically the one from the ihp-boilerplate repo.

@mpscholten
Copy link
Member

The error is caused because the Application/Migration folder is missing (because there is no migration created yet). This has been reported before via digitallyinduced/ihp#1862 and digitallyinduced/ihp#1911

@mpscholten
Copy link
Member

As a workaround you can create the directory Application/Migration and commit it to git or create an empty migration (which will then create that directory automatically)

@mokshasoft
Copy link
Contributor Author

Now I've updated the patch so that it can be used for a deploy to AWS, and also cleaned it up a bit and parameterized some values so several deployments of different apps can be made to the same region. Why it didn't work on my original project I don't know yet, but strange since it was pretty straight forward.

@mpscholten
Copy link
Member

Thank you 👍

Can we also add some notes on this to the deployment documentation? https://github.com/digitallyinduced/ihp/blob/master/Guide/deployment.markdown

@mokshasoft
Copy link
Contributor Author

Yes, I'll add a bit of documentation to the guide and make the same commit to the boilerplate code.

@mpscholten mpscholten merged commit 0ce2739 into digitallyinduced:master Jul 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants