From 85daeaaa8463026820a76701200e0cf144eeb59e Mon Sep 17 00:00:00 2001 From: Mathias Bruckmaier Date: Fri, 22 Jul 2022 11:43:20 +0200 Subject: [PATCH 1/4] Updated template to use go v1.18.3, Terraform v1.2.3 and AWS provider v4.20.0 --- .terraform/plugin_path | 3 + Makefile | 24 +- README.md | 317 ++++-------------- buildcontainer/Dockerfile | 19 +- domain/plugins/conf/config.go | 3 +- .../gui/templates/templatefs_generate.go | 2 +- go.mod | 27 +- go.sum | 124 +++---- terraform/.terraform.lock.hcl | 22 ++ terraform/backend.tf | 10 +- terraform/main.tf | 25 +- terraform/modules/api_custom_domain/main.tf | 62 ++-- .../modules/api_custom_domain/variables.tf | 4 +- .../modules/cloudfront_distribution/main.tf | 61 ++-- .../cloudfront_distribution/outputs.tf | 2 +- .../modules/serverless_lambda_app/main.tf | 114 ++++--- .../modules/serverless_lambda_app/outputs.tf | 10 +- .../serverless_lambda_app/variables.tf | 6 +- terraform/outputs.tf | 12 +- terraform/provider.tf | 4 +- terraform/variables.tf | 1 + terraform/versions.tf | 10 + 22 files changed, 334 insertions(+), 528 deletions(-) create mode 100644 .terraform/plugin_path create mode 100644 terraform/.terraform.lock.hcl create mode 100644 terraform/versions.tf diff --git a/.terraform/plugin_path b/.terraform/plugin_path new file mode 100644 index 0000000..abdcee2 --- /dev/null +++ b/.terraform/plugin_path @@ -0,0 +1,3 @@ +[ + "/usr/local/lib/custom-terraform-plugins" +] \ No newline at end of file diff --git a/Makefile b/Makefile index b8ece9f..d2b7d7a 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -APP_NAME=acme-apptemplatego +APP_NAME=mbruck-gotemplate-testapp DOMAIN_SUFFIX=.service.d-velop.cloud BUILD_VERSION=rev.$(shell git rev-parse --short HEAD).date.$(shell date '+%d-%m-%Y-%H.%M.%S') @@ -35,22 +35,30 @@ tf-bucket: echo Create terraform state bucket \"$(BUCKET_NAME)\"...; \ aws s3api create-bucket --bucket $(BUCKET_NAME) --acl private --region eu-central-1 --create-bucket-configuration LocationConstraint=eu-central-1 &&\ aws s3api put-bucket-versioning --bucket $(BUCKET_NAME) --versioning-configuration Status=Enabled &&\ - aws s3api put-public-access-block --bucket $(BUCKET_NAME) --public-access-block-configuration BlockPublicAcls=true,IgnorePublicAcls=true,BlockPublicPolicy=true,RestrictPublicBuckets=true; \ + aws s3api put-public-access-block --bucket $(BUCKET_NAME) --public-access-block-configuration BlockPublicAcls=true,IgnorePublicAcls=true,BlockPublicPolicy=true,RestrictPublicBuckets=true &&\ + echo Creating and uploading initial terraform state file...; \ + cd ./terraform &&\ + terraform init &&\ + terraform state push "./.terraform/terraform.tfstate";\ + echo Initial terraform state file uploaded successfully.; \ fi tf-init: tf-bucket cd ./terraform && \ - terraform init -input=false -plugin-dir=/usr/local/lib/custom-terraform-plugins + terraform init + terraform providers mirror /usr/local/lib/custom-terraform-plugins && \ + terraform init -plugin-dir=/usr/local/lib/custom-terraform-plugins -input=false plan: tf-init build-lambda asset_hash $(eval PLAN=$(shell mktemp)) + cd ./terraform && \ terraform plan -input=false \ - -var 'signature_secret="$(SIGNATURE_SECRET)"' \ - -var 'build_version="$(BUILD_VERSION)"' \ - -var 'appname="$(APP_NAME)"' \ - -var 'domainsuffix="$(DOMAIN_SUFFIX)"' \ - -var 'asset_hash="$(ASSET_HASH)"' \ + -var 'signature_secret=$(SIGNATURE_SECRET)' \ + -var 'build_version=$(BUILD_VERSION)' \ + -var 'appname=$(APP_NAME)' \ + -var 'domainsuffix=$(DOMAIN_SUFFIX)' \ + -var 'asset_hash=$(ASSET_HASH)' \ -out=$(PLAN) apply: plan diff --git a/README.md b/README.md index f9128fd..f6c41bb 100644 --- a/README.md +++ b/README.md @@ -1,297 +1,92 @@ -# d.velop app template for Go +# mbruckgotestapp -This template contains everything you need to write an app for d.velop cloud. -To demonstrate all the aspects of app development a hypothetical but not trivial use case -of *an employee applying for vacation* is implemented. -## Getting Started +## Getting started -Just clone this repo and follow the [build instructions](#build) to get the sample app up and running. -After this adjust the code to fit the purpose of your own business problem/app. +To make it easy for you to get started with GitLab, here's a list of recommended next steps. -### Prerequisites +Already a pro? Just edit this README.md and make it your own. Want to make it easy? [Use the template at the bottom](#editing-this-readme)! -A linux docker container is used for the build and deployment process of the app. -So besides docker (use a recent version) the only thing you need on your local development system is a git client -and an editor or IDE for Go. - -Usually the IDE requires an locally installed [Go](https://golang.org/). Please use at least version 1.11 because this -project uses [Go Modules](https://github.com/golang/go/wiki/Modules). +## Add your files -### Build - -Execute the build with - -``` -docker-build build -``` - -This will build a self contained web application `dist/app.exe` which can be used to run and test your app -as a local process on your dev system and a deployment package for aws lambda `dist/lambda` which -should be used for the production deployment of your app in d.velop cloud. - -## Run and test your app locally - -Just start `dist/app.exe` to run and test your app on a local dev environment. -Please keep in mind, that some functions like authentication -which require the presence of additional apps (e.g. IdentityProviderApp), -won't work because these apps are not available on your local system. - -## Rename the app - -You should change the name of the app so that it reflects the business problem you would like -to solve. - -Each appname in d.velop cloud must be unique. To facilitate this every provider/company chooses -a unique provider prefix which serves as a namespace for the apps of this provider. -The prefix can be selected during the registration process in d.velop cloud. -If you choose a provider prefix which corresponds to your company name or an abbreviation of the company name -it's very likely that it is available when you later register your app in d.velop cloud. - -For example if your company is named *Super Duper Software Limited* and the domain of your app -is *employees applying for vacation* your app should be named -something like `superduperltd-vacationprocess`App. Note that the `App` suffix isn't used in the configuration files. - -Apps belonging to the core d.velop cloud platform don't have a provider prefix. - -Use the `rename` target to rename your app: - -``` -docker-build rename NAME=NEW_APP_NAME -``` - -Furthermore you might want to adjust the following values manually: - -1. Change the `DOMAIN_SUFFIX` to a domain you own like `yourcompany.com` -2. `go.mod` change the module name from `github.com/d-velop/dvelop-app-template-go` to something like `github.com//`. - Unfortunately this requires to change the import path in a lot of go files. - The 'Replace' function of your IDE should help. - - -**Please finish at least step 1 and step 2 before you [deploy](#deployment) your app because the names of a lot of -AWS resources are derived from the `APP_NAME` and `DOMAIN_SUFFIX`. Changing them afterwards requires a -redeployment of the AWS resources which takes some time** - -## Deployment - -**Please read [Rename the app](#rename-the-app) before you proceed with the deployment.** - -You need an AWS Account to deploy your app. At the time of writing some of the AWS services are -free to use for a limited amount of time and workload. -Check the [Free Tier](https://aws.amazon.com/free/) offering from AWS for the current conditions. - -Manually create an IAM user with -the appropriate rights to create the AWS resources defined by your terraform configuration. -You could start with a user who has the `arn:aws:iam::aws:policy/AdministratorAccess` policy to start quickly, -but you **should definitely restrict the rights of that IAM user to a minimum as soon as you go into production**. - -Configure the AWS credentials of the created IAM user by using one of the methods described in -[Configuring the AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-getting-started.html). -For example set the `AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY` environment variables. - -**Windows** - -``` -SET AWS_ACCESS_KEY_ID= -SET AWS_SECRET_ACCESS_KEY= -``` - -**Linux** +- [ ] [Create](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#create-a-file) or [upload](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#upload-a-file) files +- [ ] [Add files using the command line](https://docs.gitlab.com/ee/gitlab-basics/add-file.html#add-a-file-using-the-command-line) or push an existing Git repository with the following command: ``` -export AWS_ACCESS_KEY_ID= -export AWS_SECRET_ACCESS_KEY= +cd existing_repo +git remote add origin https://git.d-velop.de/mbruck/mbruckgotestapp.git +git branch -M main +git push -uf origin main ``` -Deploy the lambda function and all other AWS resources like AWS API Gateway. +## Integrate with your tools -``` -docker-build deploy -``` +- [ ] [Set up project integrations](https://git.d-velop.de/mbruck/mbruckgotestapp/-/settings/integrations) -The build container uses [Terraform](https://www.terraform.io/) to manage the AWS resources and to deploy -your lambda function. This tool implements a desired state mechanism which means the first execution will take some time -to provision all the required AWS resources. Consecutive executions will only deploy the difference between the desired state -(e.g. the new version of your lambda function) and the state which is already deployed (other AWS resources which won't change -between deployments) and will be much quicker. +## Collaborate with your team -### Test your endpoint +- [ ] [Invite team members and collaborators](https://docs.gitlab.com/ee/user/project/members/) +- [ ] [Create a new merge request](https://docs.gitlab.com/ee/user/project/merge_requests/creating_merge_requests.html) +- [ ] [Automatically close issues from merge requests](https://docs.gitlab.com/ee/user/project/issues/managing_issues.html#closing-issues-automatically) +- [ ] [Enable merge request approvals](https://docs.gitlab.com/ee/user/project/merge_requests/approvals/) +- [ ] [Automatically merge when pipeline succeeds](https://docs.gitlab.com/ee/user/project/merge_requests/merge_when_pipeline_succeeds.html) -The endpoint URLs are logged at the end of the deployment. Just invoke them in a browser to test your app. - -``` -Apply complete! Resources: 0 added, 0 changed, 0 destroyed. +## Test and Deploy -Outputs: +Use the built-in continuous integration in GitLab. -endpoint = [ - https://xxxxxxxxxx.execute-api.eu-central-1.amazonaws.com/prod/vacationprocess/, - https://xxxxxxxxxx.execute-api.eu-central-1.amazonaws.com/dev/vacationprocess/ -] +- [ ] [Get started with GitLab CI/CD](https://docs.gitlab.com/ee/ci/quick_start/index.html) +- [ ] [Analyze your code for known vulnerabilities with Static Application Security Testing(SAST)](https://docs.gitlab.com/ee/user/application_security/sast/) +- [ ] [Deploy to Kubernetes, Amazon EC2, or Amazon ECS using Auto Deploy](https://docs.gitlab.com/ee/topics/autodevops/requirements.html) +- [ ] [Use pull-based deployments for improved Kubernetes management](https://docs.gitlab.com/ee/user/clusters/agent/) +- [ ] [Set up protected environments](https://docs.gitlab.com/ee/ci/environments/protected_environments.html) -``` +*** -To watch the current deployment state you can invoke +# Editing this README -``` -docker-build show -``` +When you're ready to make this README your own, just edit this file and use the handy template below (or feel free to structure it however you want - this is just a starting point!). Thank you to [makeareadme.com](https://www.makeareadme.com/) for this template. -at any time without changing your deployment. +## Suggestions for a good README +Every project is different, so consider which of these sections apply to yours. The sections used in the template are suggestions for most open source projects. Also keep in mind that while a README can be too long and detailed, too long is better than too short. If you think your README is too long, consider utilizing another form of documentation rather than cutting out information. -### Deployment of a new app version +## Name +Choose a self-explaining name for your project. -Just follow the [deployment](#deployment) steps. A new deployment package for the lambda function will be build automatically. +## Description +Let people know what your project can do specifically. Provide context and add a link to any reference visitors might be unfamiliar with. A list of Features or a Background subsection can also be added here. If there are alternatives to your project, this is a good place to list differentiating factors. -### Additional AWS resources +## Badges +On some READMEs, you may see small images that convey metadata, such as whether or not all the tests are passing for the project. You can use Shields to add some to your README. Many services also have instructions for adding a badge. -The terraform deployment configuration contains 2 additonal modules which are disabled by default. -Just uncomment the corresponding lines in `/terraform/main.tf` to use them but **ensure that the DNS resolution -for your hosted zone works before you use these modules**. Read the comments in the terraform file. +## Visuals +Depending on what you are making, it can be a good idea to include screenshots or even a video (you'll frequently see GIFs rather than actual videos). Tools like ttygif can help, but check out Asciinema for a more sophisticated method. -#### asset_cdn -This module uses *aws cloudfront* as a CDN for your static assets. Furthermore it allows you to define -a custom domain for your assets instead of the s3 URL. Your deployment should work perfectly without this module. +## Installation +Within a particular ecosystem, there may be a common way of installing things, such as using Yarn, NuGet, or Homebrew. However, consider the possibility that whoever is reading your README is a novice and would like more guidance. Listing specific steps helps remove ambiguity and gets people to using your project as quickly as possible. If it only runs in a specific context like a particular programming language version or operating system or has dependencies that have to be installed manually, also add a Requirements subsection. -#### api_custom_domain -This module allows you to define a custom domain for your app endpoints. A custom domain name is required -as soon as you register your app in the d.velop cloud center because the base path of your app must -begin with the name of your app. So instead of the default endpoints +## Usage +Use examples liberally, and show the expected output if you can. It's helpful to have inline the smallest example of usage that you can demonstrate, while providing links to more sophisticated examples if they are too long to reasonably include in the README. -``` - https://xxxxxxxxxx.execute-api.eu-central-1.amazonaws.com/prod/vacationprocess/ - https://xxxxxxxxxx.execute-api.eu-central-1.amazonaws.com/dev/vacationprocess/ -``` -which base paths begin with `/prod` or `/dev` you need endpoints like +## Support +Tell people where they can go to for help. It can be any combination of an issue tracker, a chat room, an email address, etc. -``` - https://vacationprocess.xyzdomain./vactionprocess - https://dev.vacationprocess.xyzdomain./vactionprocess -``` -which are provided by this module. - -## Projectstructure - -The presented structure is by no means mandatory for d.velop cloud apps and is highly opinionated. -Feel free to change the structure if it doesn't fit your needs. -On the other hand it takes a significant amount of time to invent a logical and useful structure -for apps and we are pretty sure this structure is at least a good starting point. -So we would recommend that you try to use it and get comfortable with it so you don't -waste your time and start immediately to implement a solution for your business problem. - -### Go Directories - -#### `/cmd` - -Contains the main applications for this project. That is the self contained webapplication `/cmd/app` -which can be run on your local machine and the lambda function `/cmd/lambda` for AWS. - -Don't put a lot of code in the application directory. Put that code in the `/domain` directory. - -It's common to have a small `main` function which basically wires up the dependencies and apart from this -completely relies on the code from the `/domain` directory. - -#### `/domain` - -Contains the vast majority of the code for this app. - -The structure follows the principles of -[Clean Architecture](http://blog.cleancoder.com/uncle-bob/2012/08/13/the-clean-architecture.html) or -[Hexagonal Architecture](https://alistair.cockburn.us/coming-soon/) -and separates the core of the domain from external frameworks, the DB and the UI. - -The directory root contains the heart of the domain and has no dependencies to external 'things' like http or databases. - -##### `/domain/` - -Each use case of the domain has its own subdirectory that is named after the use case. So you should be able -to understand the business domain of an app you've never seen before by opening the domain folder and looking -at the directory names. - -The use cases don't have any dependencies to external 'things' either. - -##### `/domain/mock` - -Contains test mocks which are relevant to more than one use case. - -##### `/domain/plugins` - -Contains the dependencies to external 'things' like a database or the invocation channel e.g. http. -The idea is to treat these external 'things' as plugins to the domain in order to keep -the domain simple, understandable and separately testable. Last but not least you are able to change external -dependencies like the database later on without rewriting the whole app because the relevant code -is not scattered over the whole codebase. - -Again you might want to read -[Clean Architecture](http://blog.cleancoder.com/uncle-bob/2012/08/13/the-clean-architecture.html) -or [Hexagonal Architecture](https://alistair.cockburn.us/coming-soon/) - -### `/buildcontainer` - -Contains the `Dockerfile` for the buildcontainer. It is kept in a separate directory to keep -the buildcontext small so that the image can be build as fast as possible. - -### `/terraform` - -Contains the terraform files - -### `/web` - -Contains the webfrontend. - -The frontend tooling is kept to a bare minimum to keep the whole project as simple as possible. -Furthermore there are hundreds of possible combinations of frameworks and build tools which -can be used for the frontend. So each developer has his own preferences about the tooling. - -Use your favorite tools for the frontend and change the `web` folder accordingly. -Don't forget to change the `deploy-assets` task in the `makefile` and the go:generate commands in `/domain/plugins/gui/` - -It's likely that we'll provide web projects using different tools and frameworks -which can be used to replace the `web` folder in the future. - -## Go Modules - -This project uses [Go Modules](https://golang.org/doc/go1.11#modules). That means you need at least Go 1.11 if you want to compile -this project outside the build container. This means also that your project **must not be located in GOPATH/src** -(cf.[Preliminary module support](https://golang.org/cmd/go/#hdr-Preliminary_module_support))and the **depedencies -must not be checked into source control**. - -### IDE Support for Go Modules - -In some IDEs, like JetBrains GoLand, Go Modules support must be activated explicitly in order to get IntelliSense. -* Settings > Go > Go Module (vgo) - Enable Go Modules (vgo) integration - -## Build mechanism -A linux docker container is used to build and deploy the software. This has the advantage, that the build -doesn't rely on specific tools or tool versions that need to be installed on the local development machine or -build server. - -During the build the whole application directory is mmounted in the docker container. The build targets are -implemented in the `Makefile`. - -Two wrappers (`docker-build.bat` and `docker-build.sh`) are provided so you don't have to remember the -rather long docker command. -Furthermore these wrappers provide a little utility function to passthrough all environment variables listed -in the `environment` file from the docker host (that is your development machine or buildserver) -to the build container. +## Roadmap +If you have ideas for releases in the future, it is a good idea to list them in the README. ## Contributing +State if you are open to contributions and what your requirements are for accepting them. -Please read [CONTRIBUTING.md](CONTRIBUTING.md) for details on our code of conduct, and the process for submitting pull requests to us. +For people who want to make changes to your project, it's helpful to have some documentation on how to get started. Perhaps there is a script that they should run or some environment variables that they need to set. Make these steps explicit. These instructions could also be useful to your future self. -## License - -Please read [LICENSE](LICENSE) for licensing information. +You can also document commands to lint the code or run tests. These steps help to ensure high code quality and reduce the likelihood that the changes inadvertently break something. Having instructions for running tests is especially helpful if it requires external setup, such as starting a Selenium server for testing in a browser. -## Acknowledgments +## Authors and acknowledgment +Show your appreciation to those who have contributed to the project. -Thanks to the following projects for inspiration - -* [Standard Go Project Layout](https://github.com/golang-standards/project-layout) -* [How Do You Structure Your Go Apps](https://github.com/katzien/go-structure-examples) -* [GoDDD](https://github.com/marcusolsson/goddd) -* [Starting an Open Source Project](https://opensource.guide/starting-a-project/) -* [README template](https://gist.github.com/PurpleBooth/109311bb0361f32d87a2) -* [CONTRIBUTING template](https://github.com/nayafia/contributing-template/blob/master/CONTRIBUTING-template.md) +## License +For open source projects, say how it is licensed. +## Project status +If you have run out of energy or time for your project, put a note at the top of the README saying that development has slowed down or stopped completely. Someone may choose to fork your project or volunteer to step in as a maintainer or owner, allowing your project to keep going. You can also make an explicit request for maintainers. diff --git a/buildcontainer/Dockerfile b/buildcontainer/Dockerfile index b23a512..07934d3 100644 --- a/buildcontainer/Dockerfile +++ b/buildcontainer/Dockerfile @@ -9,8 +9,8 @@ RUN apt-get update && \ # go ENV GOPATH /go ENV PATH $GOPATH/bin:/usr/local/go/bin:$PATH -ENV GOLANG_VERSION 1.13.4 -ENV GOLANG_CHECKSUM 692d17071736f74be04a72a06dab9cac1cd759377bd85316e52b2227604c004c +ENV GOLANG_VERSION 1.18.3 +ENV GOLANG_CHECKSUM 956f8507b302ab0bb747613695cdae10af99bbd39a90cae522b7c0302cc27245 RUN curl -fsSL https://storage.googleapis.com/golang/go${GOLANG_VERSION}.linux-amd64.tar.gz -o golang.tar.gz && \ echo "${GOLANG_CHECKSUM} golang.tar.gz" | sha256sum -c - && \ tar -C /usr/local -xzf golang.tar.gz && \ @@ -19,11 +19,11 @@ RUN curl -fsSL https://storage.googleapis.com/golang/go${GOLANG_VERSION}.linux-a GOOS=windows GOARCH=amd64 go install -v std # go-junit-report https://github.com/jstemmer/go-junit-report -RUN go get -u github.com/jstemmer/go-junit-report +RUN go install github.com/jstemmer/go-junit-report@latest # terraform -ENV TERRAFORM_VERSION 0.11.13 -ENV TERRAFORM_CHECKSUM 5925cd4d81e7d8f42a0054df2aafd66e2ab7408dbed2bd748f0022cfe592f8d2 +ENV TERRAFORM_VERSION 1.2.3 +ENV TERRAFORM_CHECKSUM 728b6fbcb288ad1b7b6590585410a98d3b7e05efe4601ef776c37e15e9a83a96 RUN curl -fsSL https://releases.hashicorp.com/terraform/${TERRAFORM_VERSION}/terraform_${TERRAFORM_VERSION}_linux_amd64.zip -o terraform.zip && \ echo "${TERRAFORM_CHECKSUM} terraform.zip" | sha256sum -c - && \ unzip terraform.zip -d /usr/local/bin && chmod +x /usr/local/bin/terraform ; rm terraform.zip @@ -43,15 +43,15 @@ RUN curl -fsSL https://releases.hashicorp.com/terraform-provider-template/${TERR unzip terraform_template_plugin.zip -d /usr/local/lib/custom-terraform-plugins ; rm terraform_template_plugin.zip # terraform null provider plugin -ENV TERRAFORM_NULL_PLUGIN_VERSION 2.1.1 -ENV TERRAFORM_NULL_PLUGIN_CHECKSUM 5b29f6a87f4dae4dc295a43f499182221333dbe474fcf724b8ea98fd38cfb3e6 +ENV TERRAFORM_NULL_PLUGIN_VERSION 3.1.1 +ENV TERRAFORM_NULL_PLUGIN_CHECKSUM 976bbaf268cb497400fd5b3c774d218f3933271864345f18deebe4dcbfcd6afa RUN curl -fsSL https://releases.hashicorp.com/terraform-provider-null/${TERRAFORM_NULL_PLUGIN_VERSION}/terraform-provider-null_${TERRAFORM_NULL_PLUGIN_VERSION}_linux_amd64.zip -o terraform_null_plugin.zip && \ echo "${TERRAFORM_NULL_PLUGIN_CHECKSUM} terraform_null_plugin.zip" | sha256sum -c - && \ unzip terraform_null_plugin.zip -d /usr/local/lib/custom-terraform-plugins ; rm terraform_null_plugin.zip # terraform aws provider plugin -ENV TERRAFORM_AWS_PLUGIN_VERSION 2.23.0 -ENV TERRAFORM_AWS_PLUGIN_CHECKSUM 8076270dfd8d31edc8aa7092f68d3d97c03104b8e47f8e2399d8688b43476d5e +ENV TERRAFORM_AWS_PLUGIN_VERSION 4.19.0 +ENV TERRAFORM_AWS_PLUGIN_CHECKSUM 9bb3919bd6d94fb22025540f0c1db5eceec8927bd71b8fbdcd295609c999065f RUN curl -fsSL https://releases.hashicorp.com/terraform-provider-aws/${TERRAFORM_AWS_PLUGIN_VERSION}/terraform-provider-aws_${TERRAFORM_AWS_PLUGIN_VERSION}_linux_amd64.zip -o terraform_aws_plugin.zip && \ echo "${TERRAFORM_AWS_PLUGIN_CHECKSUM} terraform_aws_plugin.zip" | sha256sum -c - && \ unzip terraform_aws_plugin.zip -d /usr/local/lib/custom-terraform-plugins ; rm terraform_aws_plugin.zip @@ -63,4 +63,5 @@ RUN curl https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip -o awscliv2.zi rm awscliv2.zip && rm -rf ./aws WORKDIR /build + ENTRYPOINT [ "/usr/bin/make" ] diff --git a/domain/plugins/conf/config.go b/domain/plugins/conf/config.go index 9802b9b..6876a78 100644 --- a/domain/plugins/conf/config.go +++ b/domain/plugins/conf/config.go @@ -4,8 +4,9 @@ package conf import ( "context" "encoding/base64" - "github.com/d-velop/dvelop-sdk-go/log" "os" + + "github.com/d-velop/dvelop-sdk-go/log" ) const AppName = "acme-apptemplatego" diff --git a/domain/plugins/gui/templates/templatefs_generate.go b/domain/plugins/gui/templates/templatefs_generate.go index 215457c..2608f6e 100644 --- a/domain/plugins/gui/templates/templatefs_generate.go +++ b/domain/plugins/gui/templates/templatefs_generate.go @@ -1,4 +1,4 @@ -// +build ignore +//go:build exclude // Command to generate an in memory version of the Templatefilesystem // cf. https://github.com/shurcooL/vfsgen diff --git a/go.mod b/go.mod index 97dce5c..9ee34f5 100644 --- a/go.mod +++ b/go.mod @@ -1,16 +1,23 @@ module github.com/d-velop/dvelop-app-template-go require ( - github.com/d-velop/dvelop-sdk-go/contentnegotiation v0.0.0-20191113150508-0c1d447d5696 - github.com/d-velop/dvelop-sdk-go/idp v0.0.0-20191113150508-0c1d447d5696 - github.com/d-velop/dvelop-sdk-go/log v0.0.0-20191113150508-0c1d447d5696 - github.com/d-velop/dvelop-sdk-go/requestid v0.0.0-20191113150508-0c1d447d5696 - github.com/d-velop/dvelop-sdk-go/requestlog v0.0.0-20191113150508-0c1d447d5696 - github.com/d-velop/dvelop-sdk-go/tenant v0.0.0-20191113150508-0c1d447d5696 - github.com/justinas/alice v0.0.0-20171023064455-03f45bd4b7da + github.com/d-velop/dvelop-sdk-go/contentnegotiation v0.0.0-20220420084038-aa8114534460 + github.com/d-velop/dvelop-sdk-go/idp v0.0.0-20220420084038-aa8114534460 + github.com/d-velop/dvelop-sdk-go/lambda v0.0.0-20220420084038-aa8114534460 + github.com/d-velop/dvelop-sdk-go/log v0.0.0-20220420084038-aa8114534460 + github.com/d-velop/dvelop-sdk-go/requestid v0.0.0-20220420084038-aa8114534460 + github.com/d-velop/dvelop-sdk-go/requestlog v0.0.0-20220420084038-aa8114534460 + github.com/d-velop/dvelop-sdk-go/tenant v0.0.0-20220420084038-aa8114534460 + github.com/justinas/alice v1.2.0 github.com/satori/go.uuid v1.2.1-0.20181028125025-b2ce2384e17b - github.com/shurcooL/httpfs v0.0.0-20171119174359-809beceb2371 - github.com/shurcooL/vfsgen v0.0.0-20181020040650-a97a25d856ca // indirect + github.com/shurcooL/httpfs v0.0.0-20190707220628-8d4bc4ba7749 + github.com/shurcooL/vfsgen v0.0.0-20200824052919-0d455de96546 ) -go 1.13 +require ( + github.com/aws/aws-lambda-go v1.33.0 // indirect + github.com/patrickmn/go-cache v2.1.0+incompatible // indirect + golang.org/x/tools v0.1.11 // indirect +) + +go 1.18 diff --git a/go.sum b/go.sum index b864466..ddaea00 100644 --- a/go.sum +++ b/go.sum @@ -1,87 +1,47 @@ -github.com/aws/aws-lambda-go v1.8.0 h1:YMCzi9FP7MNVVj9AkGpYyaqh/mvFOjhqiDtnNlWtKTg= -github.com/aws/aws-lambda-go v1.8.0/go.mod h1:zUsUQhAUjYzR8AuduJPCfhBuKWUaDbQiPOG+ouzmE1A= -github.com/d-velop/dvelop-sdk-go v0.0.0-20191107075108-483e363b4ba6 h1:OKb3o9zxisqdQJCXTXPaX+QTegiIemeaysZykI+Oq/4= -github.com/d-velop/dvelop-sdk-go v0.0.0-20191107085044-56b79e6224e9 h1:UTVif1zGHnqoELYubTbQKPfzBE3Qrn4PFV46Cehc+sw= -github.com/d-velop/dvelop-sdk-go v0.0.0-20191108163019-c53e0293d7dc h1:Khe0P0CGFnpiGiY7pngoWTLZACz7Bemd5YQJRcObKBc= -github.com/d-velop/dvelop-sdk-go v0.0.0-20191113150508-0c1d447d5696 h1:Mp1N9eb9gdEuDTnyKNC2eeZvedG+OBjU204CkStAIZw= -github.com/d-velop/dvelop-sdk-go/contentnegotiation v0.0.0-20181220074725-b377df504a0e h1:2NSCL0VHLIilATJVBtNul6W351oTO6/8lXHb11A4nTA= -github.com/d-velop/dvelop-sdk-go/contentnegotiation v0.0.0-20181220074725-b377df504a0e/go.mod h1:eRISj8VauYGjgWCPtsvWqVyG/dbbbxjYkU/gCnTEbeg= -github.com/d-velop/dvelop-sdk-go/contentnegotiation v0.0.0-20191107075108-483e363b4ba6 h1:E0MrQmcheaMH23AOp3cQYzJ1LQL6Ctb33osKYpTzlKI= -github.com/d-velop/dvelop-sdk-go/contentnegotiation v0.0.0-20191107075108-483e363b4ba6/go.mod h1:siqr3lWF1fkZLwPyYGhcm+4XlWqsnEIb5I+Od0b4efY= -github.com/d-velop/dvelop-sdk-go/contentnegotiation v0.0.0-20191107085044-56b79e6224e9 h1:0fqyMwD440TELE7dUhwfIUef1vOT6eK5EHlLtCIJ9Qw= -github.com/d-velop/dvelop-sdk-go/contentnegotiation v0.0.0-20191107085044-56b79e6224e9/go.mod h1:siqr3lWF1fkZLwPyYGhcm+4XlWqsnEIb5I+Od0b4efY= -github.com/d-velop/dvelop-sdk-go/contentnegotiation v0.0.0-20191108163019-c53e0293d7dc h1:BMVYJpVbo4FpYF8MUn0g4lXsUtI5pSIkmlEwg28vf8Y= -github.com/d-velop/dvelop-sdk-go/contentnegotiation v0.0.0-20191108163019-c53e0293d7dc/go.mod h1:siqr3lWF1fkZLwPyYGhcm+4XlWqsnEIb5I+Od0b4efY= -github.com/d-velop/dvelop-sdk-go/contentnegotiation v0.0.0-20191113150508-0c1d447d5696 h1:KFRyT74ZaBc36co7Fk5QFQZW8PW1HIdVI86GY1IEkjA= -github.com/d-velop/dvelop-sdk-go/contentnegotiation v0.0.0-20191113150508-0c1d447d5696/go.mod h1:siqr3lWF1fkZLwPyYGhcm+4XlWqsnEIb5I+Od0b4efY= -github.com/d-velop/dvelop-sdk-go/idp v0.0.0-20190124101707-3866f3fdcaff h1:4kCBw/6sCti89Ieze9mfT1Vo0DcLP5VJYG3ZdYA+4ok= -github.com/d-velop/dvelop-sdk-go/idp v0.0.0-20190124101707-3866f3fdcaff/go.mod h1:5QIi4aF/LsVOQ3vwcnKX9OdICQhdeaGlBmP5Bg+3ZyE= -github.com/d-velop/dvelop-sdk-go/idp v0.0.0-20190131133641-6dc0569413a4 h1:NvdIS0aLcskfNcQfV++avL4cYl9pzIHWSnhCSrJjdmI= -github.com/d-velop/dvelop-sdk-go/idp v0.0.0-20190131133641-6dc0569413a4/go.mod h1:5QIi4aF/LsVOQ3vwcnKX9OdICQhdeaGlBmP5Bg+3ZyE= -github.com/d-velop/dvelop-sdk-go/idp v0.0.0-20191107075108-483e363b4ba6 h1:IWsFsNU7KNuJJy8s5GGqYWsHLK6ksSXUNj11EwxKc9M= -github.com/d-velop/dvelop-sdk-go/idp v0.0.0-20191107075108-483e363b4ba6/go.mod h1:hYIgGr4cfeFcwoiDLD42ObuELPlvBB1gB/io39efWvY= -github.com/d-velop/dvelop-sdk-go/idp v0.0.0-20191107085044-56b79e6224e9 h1:+6Cq5LqmFuskSLaRu8cagr8W8LpnBzQjp/NnCZROqro= -github.com/d-velop/dvelop-sdk-go/idp v0.0.0-20191107085044-56b79e6224e9/go.mod h1:hYIgGr4cfeFcwoiDLD42ObuELPlvBB1gB/io39efWvY= -github.com/d-velop/dvelop-sdk-go/idp v0.0.0-20191108163019-c53e0293d7dc h1:PoXGkXIDhqoGw9J4lHYYJCeJ7yMJWPWPxuqZ9D8WrrM= -github.com/d-velop/dvelop-sdk-go/idp v0.0.0-20191108163019-c53e0293d7dc/go.mod h1:tdtjosPO8VAqJcg+EsK82c4YR0Giq+iRGV4hEIS4Dsg= -github.com/d-velop/dvelop-sdk-go/idp v0.0.0-20191113150508-0c1d447d5696 h1:ulp3smVd20AGgLq/metXQw03qsbAHLUUeCaCS/pc0Ec= -github.com/d-velop/dvelop-sdk-go/idp v0.0.0-20191113150508-0c1d447d5696/go.mod h1:tdtjosPO8VAqJcg+EsK82c4YR0Giq+iRGV4hEIS4Dsg= -github.com/d-velop/dvelop-sdk-go/lambda v0.0.0-20181220074725-b377df504a0e h1:ZS3bfM6xlYiK3C9+mOK+6FiYC5DALy7TqXFQz3DcC3g= -github.com/d-velop/dvelop-sdk-go/lambda v0.0.0-20181220074725-b377df504a0e/go.mod h1:g83TtS3HBXx+yd6r40Lb2rWAV65Xx0vCBP4H+b2lnB0= -github.com/d-velop/dvelop-sdk-go/lambda v0.0.0-20191107075108-483e363b4ba6 h1:ayo7xN8SdDzKtFIM6N1WtPJ4KcZgN47cNwkosUgSDqY= -github.com/d-velop/dvelop-sdk-go/lambda v0.0.0-20191107075108-483e363b4ba6/go.mod h1:N+XEBdu8nZNEW09dMbWqAtUetluyXejX5Z6EUVfesfg= -github.com/d-velop/dvelop-sdk-go/lambda v0.0.0-20191107085044-56b79e6224e9 h1:PMzxfjGHsTMiUn0TS/p49fg4yNL8yiMJQKTnH8ShOx8= -github.com/d-velop/dvelop-sdk-go/lambda v0.0.0-20191107085044-56b79e6224e9/go.mod h1:N+XEBdu8nZNEW09dMbWqAtUetluyXejX5Z6EUVfesfg= -github.com/d-velop/dvelop-sdk-go/log v0.0.0-20181220074725-b377df504a0e h1:Cb+amkkDuVfVtvV1CcLUXX/cNCxrgOxf5n+ky1JQVMY= -github.com/d-velop/dvelop-sdk-go/log v0.0.0-20181220074725-b377df504a0e/go.mod h1:x9iWHuId9n6HYwaYm7o57nRX4GQt8/CHnUheHZlByi0= -github.com/d-velop/dvelop-sdk-go/log v0.0.0-20191107075108-483e363b4ba6 h1:bCT8EEULllq7JAW3fcWv9QZCdUZo+tv9ysArzOtlVIw= -github.com/d-velop/dvelop-sdk-go/log v0.0.0-20191107075108-483e363b4ba6/go.mod h1:SAb14GKvscMkBXYLVHrqywqlUzogrL1DoYfiA8QBWqw= -github.com/d-velop/dvelop-sdk-go/log v0.0.0-20191107085044-56b79e6224e9 h1:D5AiSfkUaGVKzKx1HBPdDe1uyXiphNpSbhgaP1oPwrg= -github.com/d-velop/dvelop-sdk-go/log v0.0.0-20191107085044-56b79e6224e9/go.mod h1:SAb14GKvscMkBXYLVHrqywqlUzogrL1DoYfiA8QBWqw= -github.com/d-velop/dvelop-sdk-go/log v0.0.0-20191108163019-c53e0293d7dc h1:kYt/JZrg+QybJxjKtmeymxalft1NteUOqb4X4v/D0ss= -github.com/d-velop/dvelop-sdk-go/log v0.0.0-20191108163019-c53e0293d7dc/go.mod h1:SAb14GKvscMkBXYLVHrqywqlUzogrL1DoYfiA8QBWqw= -github.com/d-velop/dvelop-sdk-go/log v0.0.0-20191113150508-0c1d447d5696 h1:mQ6bTJsia+GL38dg3IlbbwqxW9aCWbFGVQ0CJg8DP4o= -github.com/d-velop/dvelop-sdk-go/log v0.0.0-20191113150508-0c1d447d5696/go.mod h1:SAb14GKvscMkBXYLVHrqywqlUzogrL1DoYfiA8QBWqw= -github.com/d-velop/dvelop-sdk-go/requestid v0.0.0-20181220074725-b377df504a0e h1:eakpqJvDYOlgiutbg9ZLrSAW9cK4A6YnyjrrvHOmr6g= -github.com/d-velop/dvelop-sdk-go/requestid v0.0.0-20181220074725-b377df504a0e/go.mod h1:jiovSyiq+ZjYjOsz1VTT0XR72yw07xMRYDLyZXX1w9k= -github.com/d-velop/dvelop-sdk-go/requestid v0.0.0-20191107075108-483e363b4ba6 h1:Ve6DP9dEtT7lv1lm9oYq/Z6YWecgZOxz/EDCx19FUFg= -github.com/d-velop/dvelop-sdk-go/requestid v0.0.0-20191107075108-483e363b4ba6/go.mod h1:2VF207teJDk0FX8LXVqwiVPGua2RHJ0wPlIOHgaMSs0= -github.com/d-velop/dvelop-sdk-go/requestid v0.0.0-20191107085044-56b79e6224e9 h1:LF0FUXCv+P8BiJr+3RZI7J6mQWF0+9gOxI9+MDtYaHI= -github.com/d-velop/dvelop-sdk-go/requestid v0.0.0-20191107085044-56b79e6224e9/go.mod h1:2VF207teJDk0FX8LXVqwiVPGua2RHJ0wPlIOHgaMSs0= -github.com/d-velop/dvelop-sdk-go/requestid v0.0.0-20191108163019-c53e0293d7dc h1:BgbgLYx78im3gnI65+yKLRELx99fQ1Z1WpupaXHQQa8= -github.com/d-velop/dvelop-sdk-go/requestid v0.0.0-20191108163019-c53e0293d7dc/go.mod h1:2VF207teJDk0FX8LXVqwiVPGua2RHJ0wPlIOHgaMSs0= -github.com/d-velop/dvelop-sdk-go/requestid v0.0.0-20191113150508-0c1d447d5696 h1:gkzcdsV3jBPK9NqFE/atCeRMoX3u+pWKr9wCFcbwtGw= -github.com/d-velop/dvelop-sdk-go/requestid v0.0.0-20191113150508-0c1d447d5696/go.mod h1:2VF207teJDk0FX8LXVqwiVPGua2RHJ0wPlIOHgaMSs0= -github.com/d-velop/dvelop-sdk-go/requestlog v0.0.0-20181220074725-b377df504a0e h1:4kNDr24l8I0vgSuZwBIIEAQAdPKYbNb21D1F7yqUDT4= -github.com/d-velop/dvelop-sdk-go/requestlog v0.0.0-20181220074725-b377df504a0e/go.mod h1:TWy+RRJNBCTSnuP87WBE1K0H8ytuWH4ygpnL+GDTrvg= -github.com/d-velop/dvelop-sdk-go/requestlog v0.0.0-20191107075108-483e363b4ba6 h1:zuomOt3hlrATRBDyJzVrikVr3KzIRVc8ZZWz2PqRufM= -github.com/d-velop/dvelop-sdk-go/requestlog v0.0.0-20191107075108-483e363b4ba6/go.mod h1:YwzXZ7Nh3brVnmQ37nZm3u1w+7YEH6jcZ5cyuYtwLzE= -github.com/d-velop/dvelop-sdk-go/requestlog v0.0.0-20191107085044-56b79e6224e9 h1:+G2e1d1GNxpJZWIDifM5hNgiyi8vBMz7iqzGVR1TS30= -github.com/d-velop/dvelop-sdk-go/requestlog v0.0.0-20191107085044-56b79e6224e9/go.mod h1:YwzXZ7Nh3brVnmQ37nZm3u1w+7YEH6jcZ5cyuYtwLzE= -github.com/d-velop/dvelop-sdk-go/requestlog v0.0.0-20191108163019-c53e0293d7dc h1:zh/Q7/qbYBskJcYYAF60KzyyKzNuNfzFBgSBOxEhYnk= -github.com/d-velop/dvelop-sdk-go/requestlog v0.0.0-20191108163019-c53e0293d7dc/go.mod h1:YwzXZ7Nh3brVnmQ37nZm3u1w+7YEH6jcZ5cyuYtwLzE= -github.com/d-velop/dvelop-sdk-go/requestlog v0.0.0-20191113150508-0c1d447d5696 h1:j/biT7gWAibCO8kV34mfz31oDwqGQnyBkzlW1manlmA= -github.com/d-velop/dvelop-sdk-go/requestlog v0.0.0-20191113150508-0c1d447d5696/go.mod h1:YwzXZ7Nh3brVnmQ37nZm3u1w+7YEH6jcZ5cyuYtwLzE= -github.com/d-velop/dvelop-sdk-go/tenant v0.0.0-20181220074725-b377df504a0e h1:TdHte0IHKQrhyj9s1Odz2nM+WCxckB+YlAqZBzqJ89k= -github.com/d-velop/dvelop-sdk-go/tenant v0.0.0-20181220074725-b377df504a0e/go.mod h1:cG8QRBW1gufkeNNH2PPx5cp8Gdnr5eaqWJt931c4Ipo= -github.com/d-velop/dvelop-sdk-go/tenant v0.0.0-20190124101707-3866f3fdcaff h1:5ef2RIxlSz9du0p3lYLuK2t5CftzD16hk182WHHpQpY= -github.com/d-velop/dvelop-sdk-go/tenant v0.0.0-20190124101707-3866f3fdcaff/go.mod h1:cG8QRBW1gufkeNNH2PPx5cp8Gdnr5eaqWJt931c4Ipo= -github.com/d-velop/dvelop-sdk-go/tenant v0.0.0-20191107075108-483e363b4ba6 h1:/UGbQ5oo2Uj2RP/RyY/QyILh/fdGfYbgzo4aEsaYvTU= -github.com/d-velop/dvelop-sdk-go/tenant v0.0.0-20191107075108-483e363b4ba6/go.mod h1:KIBwkM3Td/vgbgLD5wWPXf0BM+Tv9gVOdvRP5dfWZ8w= -github.com/d-velop/dvelop-sdk-go/tenant v0.0.0-20191107085044-56b79e6224e9 h1:XmZCR/zyeUSqJIZ+Yim7NNt2C406OLvpJUxgS9HY34w= -github.com/d-velop/dvelop-sdk-go/tenant v0.0.0-20191107085044-56b79e6224e9/go.mod h1:KIBwkM3Td/vgbgLD5wWPXf0BM+Tv9gVOdvRP5dfWZ8w= -github.com/d-velop/dvelop-sdk-go/tenant v0.0.0-20191108163019-c53e0293d7dc h1:I9KJBvDVzmOoaub9HOzlf23/ubsHtaKoQHCJBfxDvI4= -github.com/d-velop/dvelop-sdk-go/tenant v0.0.0-20191108163019-c53e0293d7dc/go.mod h1:KIBwkM3Td/vgbgLD5wWPXf0BM+Tv9gVOdvRP5dfWZ8w= -github.com/d-velop/dvelop-sdk-go/tenant v0.0.0-20191113150508-0c1d447d5696 h1:anIsX+gPQ7f0IYVScG82Zw04I3kF3TD+WzCDgcj6INM= -github.com/d-velop/dvelop-sdk-go/tenant v0.0.0-20191113150508-0c1d447d5696/go.mod h1:KIBwkM3Td/vgbgLD5wWPXf0BM+Tv9gVOdvRP5dfWZ8w= +github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= +github.com/aws/aws-lambda-go v1.17.0/go.mod h1:FEwgPLE6+8wcGBTe5cJN3JWurd1Ztm9zN4jsXsjzKKw= +github.com/aws/aws-lambda-go v1.33.0 h1:n4kw3zie82vPpLLN58ahlYHBz9k8QeK2svQep+jGnB8= +github.com/aws/aws-lambda-go v1.33.0/go.mod h1:jwFe2KmMsHmffA1X2R09hH6lFzJQxzI8qK17ewzbQMM= +github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= +github.com/d-velop/dvelop-sdk-go/contentnegotiation v0.0.0-20220420084038-aa8114534460 h1:2TwRxnW98NNmn90wLUZg0KMTm/KMLV/lv0Ou9AG/emM= +github.com/d-velop/dvelop-sdk-go/contentnegotiation v0.0.0-20220420084038-aa8114534460/go.mod h1:siqr3lWF1fkZLwPyYGhcm+4XlWqsnEIb5I+Od0b4efY= +github.com/d-velop/dvelop-sdk-go/idp v0.0.0-20220420084038-aa8114534460 h1:N5gYV9dFvZMFGrtb0VfrwaU7lXTD3bGaBwPy6Go2MCw= +github.com/d-velop/dvelop-sdk-go/idp v0.0.0-20220420084038-aa8114534460/go.mod h1:tdtjosPO8VAqJcg+EsK82c4YR0Giq+iRGV4hEIS4Dsg= +github.com/d-velop/dvelop-sdk-go/lambda v0.0.0-20220420084038-aa8114534460 h1:o9Se3hM8OjEad/aCk1qfsO4qWNNDJNILcdB1/rwZpZs= +github.com/d-velop/dvelop-sdk-go/lambda v0.0.0-20220420084038-aa8114534460/go.mod h1:/GFOm3KjeaYhfbrVOTxcRByVrMVsRQtgDP8DQat9fvs= +github.com/d-velop/dvelop-sdk-go/log v0.0.0-20220420084038-aa8114534460 h1:m3H3x4KMxp3XCVSensR/6iYXHQ30GhYeKlD3IzRc3zo= +github.com/d-velop/dvelop-sdk-go/log v0.0.0-20220420084038-aa8114534460/go.mod h1:SAb14GKvscMkBXYLVHrqywqlUzogrL1DoYfiA8QBWqw= +github.com/d-velop/dvelop-sdk-go/requestid v0.0.0-20220420084038-aa8114534460 h1:7uAk7s47nC8aRj4PGKq5NiV9bPCr0b64j03xIvon2sg= +github.com/d-velop/dvelop-sdk-go/requestid v0.0.0-20220420084038-aa8114534460/go.mod h1:2VF207teJDk0FX8LXVqwiVPGua2RHJ0wPlIOHgaMSs0= +github.com/d-velop/dvelop-sdk-go/requestlog v0.0.0-20220420084038-aa8114534460 h1:ru0CSHtpdASpLNGRPoo8wWBv8ACOUaUR8ktGSwc6dBU= +github.com/d-velop/dvelop-sdk-go/requestlog v0.0.0-20220420084038-aa8114534460/go.mod h1:YwzXZ7Nh3brVnmQ37nZm3u1w+7YEH6jcZ5cyuYtwLzE= +github.com/d-velop/dvelop-sdk-go/tenant v0.0.0-20220420084038-aa8114534460 h1:XTDg3o973BJwF6h5+zsb5t5MCudCBPjGDhl2LgZr6Eo= +github.com/d-velop/dvelop-sdk-go/tenant v0.0.0-20220420084038-aa8114534460/go.mod h1:KIBwkM3Td/vgbgLD5wWPXf0BM+Tv9gVOdvRP5dfWZ8w= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/google/go-cmp v0.3.1 h1:Xye71clBPdm5HgqGwUkwhbynsUJZhDbS20FvLhQ2izg= github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= -github.com/justinas/alice v0.0.0-20171023064455-03f45bd4b7da h1:5y58+OCjoHCYB8182mpf/dEsq0vwTKPOo4zGfH0xW9A= -github.com/justinas/alice v0.0.0-20171023064455-03f45bd4b7da/go.mod h1:oLH0CmIaxCGXD67VKGR5AacGXZSMznlmeqM8RzPrcY8= +github.com/justinas/alice v1.2.0 h1:+MHSA/vccVCF4Uq37S42jwlkvI2Xzl7zTPCN5BnZNVo= +github.com/justinas/alice v1.2.0/go.mod h1:fN5HRH/reO/zrUflLfTN43t3vXvKzvZIENsNEe7i7qA= github.com/patrickmn/go-cache v2.1.0+incompatible h1:HRMgzkcYKYpi3C8ajMPV8OFXaaRUnok+kx1WdO15EQc= github.com/patrickmn/go-cache v2.1.0+incompatible/go.mod h1:3Qf8kWWT7OJRJbdiICTKqZju1ZixQ/KpMGzzAfe6+WQ= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/satori/go.uuid v1.2.1-0.20181028125025-b2ce2384e17b h1:gQZ0qzfKHQIybLANtM3mBXNUtOfsCFXeTsnBqCsx1KM= github.com/satori/go.uuid v1.2.1-0.20181028125025-b2ce2384e17b/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0= -github.com/shurcooL/httpfs v0.0.0-20171119174359-809beceb2371 h1:SWV2fHctRpRrp49VXJ6UZja7gU9QLHwRpIPBN89SKEo= -github.com/shurcooL/httpfs v0.0.0-20171119174359-809beceb2371/go.mod h1:ZY1cvUeJuFPAdZ/B6v7RHavJWZn2YPVFQ1OSXhCGOkg= -github.com/shurcooL/vfsgen v0.0.0-20181020040650-a97a25d856ca h1:3fECS8atRjByijiI8yYiuwLwQ2ZxXobW7ua/8GRB3pI= -github.com/shurcooL/vfsgen v0.0.0-20181020040650-a97a25d856ca/go.mod h1:TrYk7fJVaAttu97ZZKrO9UbRa8izdowaMIZcxYMbVaw= +github.com/shurcooL/httpfs v0.0.0-20190707220628-8d4bc4ba7749 h1:bUGsEnyNbVPw06Bs80sCeARAlK8lhwqGyi6UT8ymuGk= +github.com/shurcooL/httpfs v0.0.0-20190707220628-8d4bc4ba7749/go.mod h1:ZY1cvUeJuFPAdZ/B6v7RHavJWZn2YPVFQ1OSXhCGOkg= +github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc= +github.com/shurcooL/vfsgen v0.0.0-20200824052919-0d455de96546 h1:pXY9qYc/MP5zdvqWEUH6SjNiu7VhSjuVFTFiTcphaLU= +github.com/shurcooL/vfsgen v0.0.0-20200824052919-0d455de96546/go.mod h1:TrYk7fJVaAttu97ZZKrO9UbRa8izdowaMIZcxYMbVaw= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= +github.com/stretchr/testify v1.7.2 h1:4jaiDzPyXQvSd7D0EjG45355tLlV3VOECpq10pLC+8s= +github.com/urfave/cli/v2 v2.1.1/go.mod h1:SE9GqnLQmjVa0iPEY0f1w3ygNIYcIJ0OKPMoW2caLfQ= +golang.org/x/tools v0.1.11 h1:loJ25fNOEhSXfHrpoGj91eCUThwdNX6u24rO1xnNteY= +golang.org/x/tools v0.1.11/go.mod h1:SgwaegtQh8clINPpECJMqnxLv9I09HLqnW3RMqW0CA4= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= diff --git a/terraform/.terraform.lock.hcl b/terraform/.terraform.lock.hcl new file mode 100644 index 0000000..9a37c32 --- /dev/null +++ b/terraform/.terraform.lock.hcl @@ -0,0 +1,22 @@ +# This file is maintained automatically by "terraform init". +# Manual edits may be lost in future updates. + +provider "registry.terraform.io/hashicorp/aws" { + version = "4.23.0" + constraints = "~> 4.0" + hashes = [ + "h1:JDJLmKK61GLw8gHQtCzmvlwPNZIu46/M5uBg/TDlBa0=", + "zh:17adbedc9a80afc571a8de7b9bfccbe2359e2b3ce1fffd02b456d92248ec9294", + "zh:23d8956b031d78466de82a3d2bbe8c76cc58482c931af311580b8eaef4e6a38f", + "zh:343fe19e9a9f3021e26f4af68ff7f4828582070f986b6e5e5b23d89df5514643", + "zh:6b8ff83d884b161939b90a18a4da43dd464c4b984f54b5f537b2870ce6bd94bc", + "zh:7777d614d5e9d589ad5508eecf4c6d8f47d50fcbaf5d40fa7921064240a6b440", + "zh:82f4578861a6fd0cde9a04a1926920bd72d993d524e5b34d7738d4eff3634c44", + "zh:9b12af85486a96aedd8d7984b0ff811a4b42e3d88dad1a3fb4c0b580d04fa425", + "zh:a08fefc153bbe0586389e814979cf7185c50fcddbb2082725991ed02742e7d1e", + "zh:ae789c0e7cb777d98934387f8888090ccb2d8973ef10e5ece541e8b624e1fb00", + "zh:b4608aab78b4dbb32c629595797107fc5a84d1b8f0682f183793d13837f0ecf0", + "zh:ed2c791c2354764b565f9ba4be7fc845c619c1a32cefadd3154a5665b312ab00", + "zh:f94ac0072a8545eebabf417bc0acbdc77c31c006ad8760834ee8ee5cdb64e743", + ] +} diff --git a/terraform/backend.tf b/terraform/backend.tf index 216406c..b403318 100644 --- a/terraform/backend.tf +++ b/terraform/backend.tf @@ -6,7 +6,7 @@ terraform { # bucket names must be globally unique across all AWS customers # so we choose a combination of company prefix ('acme') # and purpose (terraform) and appname (apptemplatego) - bucket = "acme-apptemplatego-terraform" + bucket = "mbruck-gotemplate-testapp-terraform" key = "state" # variables can't be used @@ -17,19 +17,19 @@ terraform { data "terraform_remote_state" "app" { backend = "s3" - config { + config = { # bucket names must be globally unique across all AWS customers # so we choose a combination of company prefix ('acme') # and purpose (terraform) and appname (apptemplatego) - bucket = "acme-apptemplatego-terraform" + bucket = "mbruck-gotemplate-testapp-terraform" key = "state" - # variables can't be used region = "eu-central-1" } - defaults { + defaults = { source_code_hash = "0" build_version = "0" } } + diff --git a/terraform/main.tf b/terraform/main.tf index 74ce1e1..704aaf6 100644 --- a/terraform/main.tf +++ b/terraform/main.tf @@ -2,7 +2,7 @@ locals { assets_bucket_name = "${var.appname}-assets" lambda_file = "../dist/lambda.zip" - source_code_hash = "${base64sha256(file("${local.lambda_file}"))}" + source_code_hash = filebase64sha256(local.lambda_file) # Unfortunately there is a bug in terraform which leads to the destruction of existing resources if # the element order of lists and maps changes cf. https://github.com/hashicorp/terraform/issues/16210 @@ -16,18 +16,18 @@ locals { } // to avoid unnecessary lambda function deployments the build version env var is only changed if the lambda function code has been changed - build_version = "${local.source_code_hash != data.terraform_remote_state.app.source_code_hash ? var.build_version : data.terraform_remote_state.app.build_version}" + build_version = local.source_code_hash != data.terraform_remote_state.app.outputs.source_code_hash ? var.build_version : data.terraform_remote_state.app.outputs.build_version } module "serverless_lambda_app" { - source = "modules/serverless_lambda_app" - stages = "${local.stages}" - appname = "${var.appname}" - lambda_file = "${local.lambda_file}" - source_code_hash = "${local.source_code_hash}" + source = "./modules/serverless_lambda_app" + stages = local.stages + appname = var.appname + lambda_file = local.lambda_file + source_code_hash = local.source_code_hash lambda_handler = "lambda" lambda_runtime = "go1.x" - assets_bucket_name = "${local.assets_bucket_name}" + assets_bucket_name = local.assets_bucket_name # Which rights should the lambda function have. # Terraform user must have appropriate rights to attach these policies! @@ -37,14 +37,13 @@ module "serverless_lambda_app" { ] lambda_environment_vars = { - SIGNATURE_SECRET = "${var.signature_secret}" - BUILD_VERSION = "${local.build_version}" - + SIGNATURE_SECRET = var.signature_secret + BUILD_VERSION = local.build_version # change to ASSET_BASE_PATH = "https://${module.asset_cdn.dns_name}/${var.asset_hash}" if asset_cdn is enabled ASSET_BASE_PATH = "https://${local.assets_bucket_name}.s3.amazonaws.com/${var.asset_hash}" } - aws_region = "${var.aws_region}" + aws_region = var.aws_region } # Uncomment if you want to use cloudfront (a CDN) to deliver your assets OR custom domain names for your API endpoints. @@ -60,7 +59,6 @@ output "nameserver" { value = "${aws_route53_zone.hosted_zone.name_servers}" } */ - # Uncomment if you want to use cloudfront (a CDN) to deliver your assets. # IMPORTANT: # - This module requires a working dns resolution for your hosted zone because @@ -75,7 +73,6 @@ module "asset_cdn" { origin_domain_name = "${module.serverless_lambda_app.assets_bucket_domain_name}" } */ - # Uncomment if you want to use custom domain names for your API endpoints. # cf. https://docs.aws.amazon.com/apigateway/latest/developerguide/how-to-custom-domains.html # IMPORTANT: diff --git a/terraform/modules/api_custom_domain/main.tf b/terraform/modules/api_custom_domain/main.tf index d39139c..71bc4bf 100644 --- a/terraform/modules/api_custom_domain/main.tf +++ b/terraform/modules/api_custom_domain/main.tf @@ -1,16 +1,16 @@ # cf. https://www.terraform.io/docs/providers/aws/d/route53_zone.html data "aws_route53_zone" "hosted_zone" { - zone_id = "${var.hosted_zone_id}" + zone_id = var.hosted_zone_id } locals { // cf. https://github.com/terraform-providers/terraform-provider-aws/issues/241#issuecomment-438744460 - hosted_zone_name = "${replace(data.aws_route53_zone.hosted_zone.name, "/[.]$/", "")}" + hosted_zone_name = replace(data.aws_route53_zone.hosted_zone.name, "/[.]$/", "") } # cf. https://www.terraform.io/docs/providers/aws/r/acm_certificate.html resource "aws_acm_certificate" "cert" { - domain_name = "${local.hosted_zone_name}" + domain_name = local.hosted_zone_name subject_alternative_names = ["*.${local.hosted_zone_name}"] validation_method = "DNS" @@ -21,65 +21,61 @@ resource "aws_acm_certificate" "cert" { # cf. https://www.terraform.io/docs/providers/aws/r/acm_certificate_validation.html resource "aws_acm_certificate_validation" "cert" { - certificate_arn = "${aws_acm_certificate.cert.arn}" + certificate_arn = aws_acm_certificate.cert.arn - validation_record_fqdns = [ - "${aws_route53_record.cert_name_validation.fqdn}", - "${aws_route53_record.cert_alt_name_validation.fqdn}", - ] + validation_record_fqdns = [for record in aws_route53_record.cert_name_validation : record.fqdn] } # cf. https://www.terraform.io/docs/providers/aws/r/acm_certificate_validation.html resource "aws_route53_record" "cert_name_validation" { + + for_each = { + for dvo in aws_acm_certificate.cert.domain_validation_options : dvo.domain_name => { + name = dvo.resource_record_name + record = dvo.resource_record_value + type = dvo.resource_record_type + } + } + allow_overwrite = true - name = "${aws_acm_certificate.cert.domain_validation_options.0.resource_record_name}" - type = "${aws_acm_certificate.cert.domain_validation_options.0.resource_record_type}" - zone_id = "${var.hosted_zone_id}" - records = ["${aws_acm_certificate.cert.domain_validation_options.0.resource_record_value}"] - ttl = 60 -} - -# cf. https://www.terraform.io/docs/providers/aws/r/acm_certificate_validation.html -resource "aws_route53_record" "cert_alt_name_validation" { - allow_overwrite = true - name = "${aws_acm_certificate.cert.domain_validation_options.1.resource_record_name}" - type = "${aws_acm_certificate.cert.domain_validation_options.1.resource_record_type}" + name = each.value.name + type = each.value.type zone_id = "${var.hosted_zone_id}" - records = ["${aws_acm_certificate.cert.domain_validation_options.1.resource_record_value}"] + records = [each.value.record] ttl = 60 } # cf. https://www.terraform.io/docs/providers/aws/r/api_gateway_domain_name.html resource "aws_api_gateway_domain_name" "stage" { - count = "${length(var.stages)}" + count = length(var.stages) # By convention the 'prod' stage is mapped to the name of the provided hosted zone without the prefix 'prod' domain_name = "${var.stages[count.index] != "prod" ? format("%s.", var.stages[count.index]) : "" }${local.hosted_zone_name}" - regional_certificate_arn = "${aws_acm_certificate_validation.cert.certificate_arn}" + regional_certificate_arn = aws_acm_certificate_validation.cert.certificate_arn endpoint_configuration { - types = "${var.aws_api_gateway_rest_api_endpoint_configuration_types}" + types = var.aws_api_gateway_rest_api_endpoint_configuration_types } } # cf. https://www.terraform.io/docs/providers/aws/r/api_gateway_base_path_mapping.html resource "aws_api_gateway_base_path_mapping" "stage" { - count = "${length(var.stages)}" - api_id = "${var.aws_api_gateway_rest_api_id}" - stage_name = "${var.stages[count.index]}" - domain_name = "${element(aws_api_gateway_domain_name.stage.*.domain_name,count.index)}" + count = length(var.stages) + api_id = var.aws_api_gateway_rest_api_id + stage_name = var.stages[count.index] + domain_name = element(aws_api_gateway_domain_name.stage.*.domain_name,count.index) } # cf. https://www.terraform.io/docs/providers/aws/r/api_gateway_domain_name.html resource "aws_route53_record" "stage" { - count = "${length(var.stages)}" - zone_id = "${var.hosted_zone_id}" - name = "${element(aws_api_gateway_domain_name.stage.*.domain_name,count.index)}" + count = length(var.stages) + zone_id = var.hosted_zone_id + name = element(aws_api_gateway_domain_name.stage.*.domain_name,count.index) type = "A" alias { - name = "${element(aws_api_gateway_domain_name.stage.*.regional_domain_name,count.index)}" - zone_id = "${element(aws_api_gateway_domain_name.stage.*.regional_zone_id,count.index)}" + name = element(aws_api_gateway_domain_name.stage.*.regional_domain_name,count.index) + zone_id = element(aws_api_gateway_domain_name.stage.*.regional_zone_id,count.index) evaluate_target_health = false } } diff --git a/terraform/modules/api_custom_domain/variables.tf b/terraform/modules/api_custom_domain/variables.tf index 8a0159b..c3b116c 100644 --- a/terraform/modules/api_custom_domain/variables.tf +++ b/terraform/modules/api_custom_domain/variables.tf @@ -7,11 +7,11 @@ variable "aws_api_gateway_rest_api_id" { } variable "aws_api_gateway_rest_api_endpoint_configuration_types" { - type = "list" + type = list(string) description = "A list of endpoint types. cf. https://www.terraform.io/docs/providers/aws/r/api_gateway_domain_name.html#endpoint_configuration-1" } variable "stages" { - type = "list" + type = list(string) description = "Stages for which custom domain names should be created. By convention the 'prod' stage is mapped to the name of the provided hosted zone without the prefix 'prod'" } \ No newline at end of file diff --git a/terraform/modules/cloudfront_distribution/main.tf b/terraform/modules/cloudfront_distribution/main.tf index 325413d..ac57e53 100644 --- a/terraform/modules/cloudfront_distribution/main.tf +++ b/terraform/modules/cloudfront_distribution/main.tf @@ -2,26 +2,25 @@ # cf. https://docs.aws.amazon.com/acm/latest/userguide/acm-regions.html provider "aws" { alias = "virginia" - version = "~> 2.0" region = "us-east-1" } # cf. https://www.terraform.io/docs/providers/aws/d/route53_zone.html data "aws_route53_zone" "hosted_zone" { - zone_id = "${var.hosted_zone_id}" + zone_id = var.hosted_zone_id } locals { // cf. https://github.com/terraform-providers/terraform-provider-aws/issues/241#issuecomment-438744460 - hosted_zone_name = "${replace(data.aws_route53_zone.hosted_zone.name, "/[.]$/", "")}" + hosted_zone_name = replace(data.aws_route53_zone.hosted_zone.name, "/[.]$/", "") } # cf. https://www.terraform.io/docs/providers/aws/r/acm_certificate.html resource "aws_acm_certificate" "cert" { - domain_name = "${local.hosted_zone_name}" + domain_name = local.hosted_zone_name subject_alternative_names = ["*.${local.hosted_zone_name}"] validation_method = "DNS" - provider = "aws.virginia" + provider = aws.virginia lifecycle { create_before_destroy = true @@ -30,41 +29,37 @@ resource "aws_acm_certificate" "cert" { # cf. https://www.terraform.io/docs/providers/aws/r/acm_certificate_validation.html resource "aws_acm_certificate_validation" "cert" { - certificate_arn = "${aws_acm_certificate.cert.arn}" + certificate_arn = aws_acm_certificate.cert.arn - validation_record_fqdns = [ - "${aws_route53_record.cert_name_validation.fqdn}", - "${aws_route53_record.cert_alt_name_validation.fqdn}", - ] + validation_record_fqdns = [for record in aws_route53_record.cert_name_validation : record.fqdn] - provider = "aws.virginia" + provider = aws.virginia } # cf. https://www.terraform.io/docs/providers/aws/r/acm_certificate_validation.html resource "aws_route53_record" "cert_name_validation" { + + for_each = { + for dvo in aws_acm_certificate.cert.domain_validation_options : dvo.domain_name => { + name = dvo.resource_record_name + record = dvo.resource_record_value + type = dvo.resource_record_type + } + } + allow_overwrite = true - name = "${aws_acm_certificate.cert.domain_validation_options.0.resource_record_name}" - type = "${aws_acm_certificate.cert.domain_validation_options.0.resource_record_type}" - zone_id = "${var.hosted_zone_id}" - records = ["${aws_acm_certificate.cert.domain_validation_options.0.resource_record_value}"] - ttl = 60 -} - -# cf. https://www.terraform.io/docs/providers/aws/r/acm_certificate_validation.html -resource "aws_route53_record" "cert_alt_name_validation" { - allow_overwrite = true - name = "${aws_acm_certificate.cert.domain_validation_options.1.resource_record_name}" - type = "${aws_acm_certificate.cert.domain_validation_options.1.resource_record_type}" - zone_id = "${var.hosted_zone_id}" - records = ["${aws_acm_certificate.cert.domain_validation_options.1.resource_record_value}"] + name = each.value.name + type = each.value.type + zone_id = var.hosted_zone_id + records = [each.value.record] ttl = 60 } # cf. https://www.terraform.io/docs/providers/aws/r/cloudfront_distribution.html resource "aws_cloudfront_distribution" "dist" { origin { - origin_id = "${sha256(var.origin_domain_name)}" - domain_name = "${var.origin_domain_name}" + origin_id = sha256(var.origin_domain_name) + domain_name = var.origin_domain_name } enabled = true @@ -78,7 +73,7 @@ resource "aws_cloudfront_distribution" "dist" { allowed_methods = ["GET", "HEAD"] cached_methods = ["GET", "HEAD"] compress = true - target_origin_id = "${sha256(var.origin_domain_name)}" + target_origin_id = sha256(var.origin_domain_name) forwarded_values { query_string = true @@ -104,7 +99,7 @@ resource "aws_cloudfront_distribution" "dist" { viewer_certificate { minimum_protocol_version = "TLSv1.2_2018" ssl_support_method = "sni-only" - acm_certificate_arn = "${aws_acm_certificate_validation.cert.certificate_arn}" + acm_certificate_arn = aws_acm_certificate_validation.cert.certificate_arn } restrictions { @@ -113,20 +108,20 @@ resource "aws_cloudfront_distribution" "dist" { } } - tags { + tags = { Name = "dist for ${var.origin_domain_name}" Created_By = "Terraform - do not modify in AWS Management Console" } } resource "aws_route53_record" "dist" { - zone_id = "${var.hosted_zone_id}" + zone_id = var.hosted_zone_id name = "${var.custom_subdomain_name}.${local.hosted_zone_name}" type = "A" alias { - name = "${aws_cloudfront_distribution.dist.domain_name}" - zone_id = "${aws_cloudfront_distribution.dist.hosted_zone_id}" + name = aws_cloudfront_distribution.dist.domain_name + zone_id = aws_cloudfront_distribution.dist.hosted_zone_id evaluate_target_health = false } } diff --git a/terraform/modules/cloudfront_distribution/outputs.tf b/terraform/modules/cloudfront_distribution/outputs.tf index 9fc571b..6223d9b 100644 --- a/terraform/modules/cloudfront_distribution/outputs.tf +++ b/terraform/modules/cloudfront_distribution/outputs.tf @@ -1,3 +1,3 @@ output "dns_name" { - value = "${aws_route53_record.dist.name}" + value = aws_route53_record.dist.name } \ No newline at end of file diff --git a/terraform/modules/serverless_lambda_app/main.tf b/terraform/modules/serverless_lambda_app/main.tf index eed63e2..d943775 100644 --- a/terraform/modules/serverless_lambda_app/main.tf +++ b/terraform/modules/serverless_lambda_app/main.tf @@ -1,42 +1,52 @@ #cf. https://www.terraform.io/docs/providers/aws/r/s3_bucket.html resource "aws_s3_bucket" "assets" { - bucket = "${var.assets_bucket_name}" - region = "${var.aws_region}" + bucket = var.assets_bucket_name - # required if webfonts are delivered cf. https://docs.aws.amazon.com/AmazonS3/latest/dev/cors.html and https://zinoui.com/blog/cross-domain-fonts - cors_rule { - allowed_methods = ["GET"] - allowed_origins = ["*"] + tags = { + Created_By = "Terraform - do not modify in AWS Management Console" } +} - policy = < Date: Fri, 22 Jul 2022 11:50:50 +0200 Subject: [PATCH 2/4] Reverted app name to acme-apptemplatego --- Makefile | 2 +- terraform/backend.tf | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index d2b7d7a..d72d3ce 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -APP_NAME=mbruck-gotemplate-testapp +APP_NAME=acme-apptemplatego DOMAIN_SUFFIX=.service.d-velop.cloud BUILD_VERSION=rev.$(shell git rev-parse --short HEAD).date.$(shell date '+%d-%m-%Y-%H.%M.%S') diff --git a/terraform/backend.tf b/terraform/backend.tf index b403318..1d00341 100644 --- a/terraform/backend.tf +++ b/terraform/backend.tf @@ -6,7 +6,7 @@ terraform { # bucket names must be globally unique across all AWS customers # so we choose a combination of company prefix ('acme') # and purpose (terraform) and appname (apptemplatego) - bucket = "mbruck-gotemplate-testapp-terraform" + bucket = "acme-apptemplatego-terraform" key = "state" # variables can't be used From 493833f9890490dc4b48f95f432e7becbb688864 Mon Sep 17 00:00:00 2001 From: Mathias Bruckmaier Date: Fri, 22 Jul 2022 11:56:26 +0200 Subject: [PATCH 3/4] Reverted Readme to original --- README.md | 316 ++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 260 insertions(+), 56 deletions(-) diff --git a/README.md b/README.md index f6c41bb..2cd8dd5 100644 --- a/README.md +++ b/README.md @@ -1,92 +1,296 @@ -# mbruckgotestapp +# d.velop app template for Go +This template contains everything you need to write an app for d.velop cloud. +To demonstrate all the aspects of app development a hypothetical but not trivial use case +of *an employee applying for vacation* is implemented. -## Getting started +## Getting Started -To make it easy for you to get started with GitLab, here's a list of recommended next steps. +Just clone this repo and follow the [build instructions](#build) to get the sample app up and running. +After this adjust the code to fit the purpose of your own business problem/app. -Already a pro? Just edit this README.md and make it your own. Want to make it easy? [Use the template at the bottom](#editing-this-readme)! +### Prerequisites -## Add your files +A linux docker container is used for the build and deployment process of the app. +So besides docker (use a recent version) the only thing you need on your local development system is a git client +and an editor or IDE for Go. + +Usually the IDE requires an locally installed [Go](https://golang.org/). Please use at least version 1.11 because this +project uses [Go Modules](https://github.com/golang/go/wiki/Modules). -- [ ] [Create](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#create-a-file) or [upload](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#upload-a-file) files -- [ ] [Add files using the command line](https://docs.gitlab.com/ee/gitlab-basics/add-file.html#add-a-file-using-the-command-line) or push an existing Git repository with the following command: +### Build + +Execute the build with ``` -cd existing_repo -git remote add origin https://git.d-velop.de/mbruck/mbruckgotestapp.git -git branch -M main -git push -uf origin main +docker-build build ``` -## Integrate with your tools +This will build a self contained web application `dist/app.exe` which can be used to run and test your app +as a local process on your dev system and a deployment package for aws lambda `dist/lambda` which +should be used for the production deployment of your app in d.velop cloud. -- [ ] [Set up project integrations](https://git.d-velop.de/mbruck/mbruckgotestapp/-/settings/integrations) +## Run and test your app locally -## Collaborate with your team +Just start `dist/app.exe` to run and test your app on a local dev environment. +Please keep in mind, that some functions like authentication +which require the presence of additional apps (e.g. IdentityProviderApp), +won't work because these apps are not available on your local system. -- [ ] [Invite team members and collaborators](https://docs.gitlab.com/ee/user/project/members/) -- [ ] [Create a new merge request](https://docs.gitlab.com/ee/user/project/merge_requests/creating_merge_requests.html) -- [ ] [Automatically close issues from merge requests](https://docs.gitlab.com/ee/user/project/issues/managing_issues.html#closing-issues-automatically) -- [ ] [Enable merge request approvals](https://docs.gitlab.com/ee/user/project/merge_requests/approvals/) -- [ ] [Automatically merge when pipeline succeeds](https://docs.gitlab.com/ee/user/project/merge_requests/merge_when_pipeline_succeeds.html) +## Rename the app -## Test and Deploy +You should change the name of the app so that it reflects the business problem you would like +to solve. -Use the built-in continuous integration in GitLab. +Each appname in d.velop cloud must be unique. To facilitate this every provider/company chooses +a unique provider prefix which serves as a namespace for the apps of this provider. +The prefix can be selected during the registration process in d.velop cloud. +If you choose a provider prefix which corresponds to your company name or an abbreviation of the company name +it's very likely that it is available when you later register your app in d.velop cloud. -- [ ] [Get started with GitLab CI/CD](https://docs.gitlab.com/ee/ci/quick_start/index.html) -- [ ] [Analyze your code for known vulnerabilities with Static Application Security Testing(SAST)](https://docs.gitlab.com/ee/user/application_security/sast/) -- [ ] [Deploy to Kubernetes, Amazon EC2, or Amazon ECS using Auto Deploy](https://docs.gitlab.com/ee/topics/autodevops/requirements.html) -- [ ] [Use pull-based deployments for improved Kubernetes management](https://docs.gitlab.com/ee/user/clusters/agent/) -- [ ] [Set up protected environments](https://docs.gitlab.com/ee/ci/environments/protected_environments.html) +For example if your company is named *Super Duper Software Limited* and the domain of your app +is *employees applying for vacation* your app should be named +something like `superduperltd-vacationprocess`App. Note that the `App` suffix isn't used in the configuration files. -*** +Apps belonging to the core d.velop cloud platform don't have a provider prefix. -# Editing this README +Use the `rename` target to rename your app: -When you're ready to make this README your own, just edit this file and use the handy template below (or feel free to structure it however you want - this is just a starting point!). Thank you to [makeareadme.com](https://www.makeareadme.com/) for this template. +``` +docker-build rename NAME=NEW_APP_NAME +``` -## Suggestions for a good README -Every project is different, so consider which of these sections apply to yours. The sections used in the template are suggestions for most open source projects. Also keep in mind that while a README can be too long and detailed, too long is better than too short. If you think your README is too long, consider utilizing another form of documentation rather than cutting out information. +Furthermore you might want to adjust the following values manually: -## Name -Choose a self-explaining name for your project. +1. Change the `DOMAIN_SUFFIX` to a domain you own like `yourcompany.com` +2. `go.mod` change the module name from `github.com/d-velop/dvelop-app-template-go` to something like `github.com//`. + Unfortunately this requires to change the import path in a lot of go files. + The 'Replace' function of your IDE should help. -## Description -Let people know what your project can do specifically. Provide context and add a link to any reference visitors might be unfamiliar with. A list of Features or a Background subsection can also be added here. If there are alternatives to your project, this is a good place to list differentiating factors. -## Badges -On some READMEs, you may see small images that convey metadata, such as whether or not all the tests are passing for the project. You can use Shields to add some to your README. Many services also have instructions for adding a badge. +**Please finish at least step 1 and step 2 before you [deploy](#deployment) your app because the names of a lot of +AWS resources are derived from the `APP_NAME` and `DOMAIN_SUFFIX`. Changing them afterwards requires a +redeployment of the AWS resources which takes some time** -## Visuals -Depending on what you are making, it can be a good idea to include screenshots or even a video (you'll frequently see GIFs rather than actual videos). Tools like ttygif can help, but check out Asciinema for a more sophisticated method. +## Deployment -## Installation -Within a particular ecosystem, there may be a common way of installing things, such as using Yarn, NuGet, or Homebrew. However, consider the possibility that whoever is reading your README is a novice and would like more guidance. Listing specific steps helps remove ambiguity and gets people to using your project as quickly as possible. If it only runs in a specific context like a particular programming language version or operating system or has dependencies that have to be installed manually, also add a Requirements subsection. +**Please read [Rename the app](#rename-the-app) before you proceed with the deployment.** -## Usage -Use examples liberally, and show the expected output if you can. It's helpful to have inline the smallest example of usage that you can demonstrate, while providing links to more sophisticated examples if they are too long to reasonably include in the README. +You need an AWS Account to deploy your app. At the time of writing some of the AWS services are +free to use for a limited amount of time and workload. +Check the [Free Tier](https://aws.amazon.com/free/) offering from AWS for the current conditions. -## Support -Tell people where they can go to for help. It can be any combination of an issue tracker, a chat room, an email address, etc. +Manually create an IAM user with +the appropriate rights to create the AWS resources defined by your terraform configuration. +You could start with a user who has the `arn:aws:iam::aws:policy/AdministratorAccess` policy to start quickly, +but you **should definitely restrict the rights of that IAM user to a minimum as soon as you go into production**. -## Roadmap -If you have ideas for releases in the future, it is a good idea to list them in the README. +Configure the AWS credentials of the created IAM user by using one of the methods described in +[Configuring the AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-getting-started.html). +For example set the `AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY` environment variables. -## Contributing -State if you are open to contributions and what your requirements are for accepting them. +**Windows** + +``` +SET AWS_ACCESS_KEY_ID= +SET AWS_SECRET_ACCESS_KEY= +``` + +**Linux** + +``` +export AWS_ACCESS_KEY_ID= +export AWS_SECRET_ACCESS_KEY= +``` + +Deploy the lambda function and all other AWS resources like AWS API Gateway. + +``` +docker-build deploy +``` + +The build container uses [Terraform](https://www.terraform.io/) to manage the AWS resources and to deploy +your lambda function. This tool implements a desired state mechanism which means the first execution will take some time +to provision all the required AWS resources. Consecutive executions will only deploy the difference between the desired state +(e.g. the new version of your lambda function) and the state which is already deployed (other AWS resources which won't change +between deployments) and will be much quicker. + +### Test your endpoint + +The endpoint URLs are logged at the end of the deployment. Just invoke them in a browser to test your app. + +``` +Apply complete! Resources: 0 added, 0 changed, 0 destroyed. + +Outputs: + +endpoint = [ + https://xxxxxxxxxx.execute-api.eu-central-1.amazonaws.com/prod/vacationprocess/, + https://xxxxxxxxxx.execute-api.eu-central-1.amazonaws.com/dev/vacationprocess/ +] + +``` + +To watch the current deployment state you can invoke + +``` +docker-build show +``` + +at any time without changing your deployment. + +### Deployment of a new app version + +Just follow the [deployment](#deployment) steps. A new deployment package for the lambda function will be build automatically. + +### Additional AWS resources + +The terraform deployment configuration contains 2 additonal modules which are disabled by default. +Just uncomment the corresponding lines in `/terraform/main.tf` to use them but **ensure that the DNS resolution +for your hosted zone works before you use these modules**. Read the comments in the terraform file. + +#### asset_cdn +This module uses *aws cloudfront* as a CDN for your static assets. Furthermore it allows you to define +a custom domain for your assets instead of the s3 URL. Your deployment should work perfectly without this module. + +#### api_custom_domain +This module allows you to define a custom domain for your app endpoints. A custom domain name is required +as soon as you register your app in the d.velop cloud center because the base path of your app must +begin with the name of your app. So instead of the default endpoints + +``` + https://xxxxxxxxxx.execute-api.eu-central-1.amazonaws.com/prod/vacationprocess/ + https://xxxxxxxxxx.execute-api.eu-central-1.amazonaws.com/dev/vacationprocess/ +``` +which base paths begin with `/prod` or `/dev` you need endpoints like + +``` + https://vacationprocess.xyzdomain./vactionprocess + https://dev.vacationprocess.xyzdomain./vactionprocess +``` +which are provided by this module. + +## Projectstructure + +The presented structure is by no means mandatory for d.velop cloud apps and is highly opinionated. +Feel free to change the structure if it doesn't fit your needs. +On the other hand it takes a significant amount of time to invent a logical and useful structure +for apps and we are pretty sure this structure is at least a good starting point. +So we would recommend that you try to use it and get comfortable with it so you don't +waste your time and start immediately to implement a solution for your business problem. + +### Go Directories + +#### `/cmd` + +Contains the main applications for this project. That is the self contained webapplication `/cmd/app` +which can be run on your local machine and the lambda function `/cmd/lambda` for AWS. + +Don't put a lot of code in the application directory. Put that code in the `/domain` directory. + +It's common to have a small `main` function which basically wires up the dependencies and apart from this +completely relies on the code from the `/domain` directory. + +#### `/domain` + +Contains the vast majority of the code for this app. + +The structure follows the principles of +[Clean Architecture](http://blog.cleancoder.com/uncle-bob/2012/08/13/the-clean-architecture.html) or +[Hexagonal Architecture](https://alistair.cockburn.us/coming-soon/) +and separates the core of the domain from external frameworks, the DB and the UI. + +The directory root contains the heart of the domain and has no dependencies to external 'things' like http or databases. + +##### `/domain/` + +Each use case of the domain has its own subdirectory that is named after the use case. So you should be able +to understand the business domain of an app you've never seen before by opening the domain folder and looking +at the directory names. + +The use cases don't have any dependencies to external 'things' either. + +##### `/domain/mock` + +Contains test mocks which are relevant to more than one use case. + +##### `/domain/plugins` + +Contains the dependencies to external 'things' like a database or the invocation channel e.g. http. +The idea is to treat these external 'things' as plugins to the domain in order to keep +the domain simple, understandable and separately testable. Last but not least you are able to change external +dependencies like the database later on without rewriting the whole app because the relevant code +is not scattered over the whole codebase. + +Again you might want to read +[Clean Architecture](http://blog.cleancoder.com/uncle-bob/2012/08/13/the-clean-architecture.html) +or [Hexagonal Architecture](https://alistair.cockburn.us/coming-soon/) -For people who want to make changes to your project, it's helpful to have some documentation on how to get started. Perhaps there is a script that they should run or some environment variables that they need to set. Make these steps explicit. These instructions could also be useful to your future self. +### `/buildcontainer` -You can also document commands to lint the code or run tests. These steps help to ensure high code quality and reduce the likelihood that the changes inadvertently break something. Having instructions for running tests is especially helpful if it requires external setup, such as starting a Selenium server for testing in a browser. +Contains the `Dockerfile` for the buildcontainer. It is kept in a separate directory to keep +the buildcontext small so that the image can be build as fast as possible. -## Authors and acknowledgment -Show your appreciation to those who have contributed to the project. +### `/terraform` + +Contains the terraform files + +### `/web` + +Contains the webfrontend. + +The frontend tooling is kept to a bare minimum to keep the whole project as simple as possible. +Furthermore there are hundreds of possible combinations of frameworks and build tools which +can be used for the frontend. So each developer has his own preferences about the tooling. + +Use your favorite tools for the frontend and change the `web` folder accordingly. +Don't forget to change the `deploy-assets` task in the `makefile` and the go:generate commands in `/domain/plugins/gui/` + +It's likely that we'll provide web projects using different tools and frameworks +which can be used to replace the `web` folder in the future. + +## Go Modules + +This project uses [Go Modules](https://golang.org/doc/go1.11#modules). That means you need at least Go 1.11 if you want to compile +this project outside the build container. This means also that your project **must not be located in GOPATH/src** +(cf.[Preliminary module support](https://golang.org/cmd/go/#hdr-Preliminary_module_support))and the **depedencies +must not be checked into source control**. + +### IDE Support for Go Modules + +In some IDEs, like JetBrains GoLand, Go Modules support must be activated explicitly in order to get IntelliSense. +* Settings > Go > Go Module (vgo) - Enable Go Modules (vgo) integration + +## Build mechanism +A linux docker container is used to build and deploy the software. This has the advantage, that the build +doesn't rely on specific tools or tool versions that need to be installed on the local development machine or +build server. + +During the build the whole application directory is mmounted in the docker container. The build targets are +implemented in the `Makefile`. + +Two wrappers (`docker-build.bat` and `docker-build.sh`) are provided so you don't have to remember the +rather long docker command. +Furthermore these wrappers provide a little utility function to passthrough all environment variables listed +in the `environment` file from the docker host (that is your development machine or buildserver) +to the build container. + +## Contributing + +Please read [CONTRIBUTING.md](CONTRIBUTING.md) for details on our code of conduct, and the process for submitting pull requests to us. ## License -For open source projects, say how it is licensed. -## Project status -If you have run out of energy or time for your project, put a note at the top of the README saying that development has slowed down or stopped completely. Someone may choose to fork your project or volunteer to step in as a maintainer or owner, allowing your project to keep going. You can also make an explicit request for maintainers. +Please read [LICENSE](LICENSE) for licensing information. + +## Acknowledgments + +Thanks to the following projects for inspiration + +* [Standard Go Project Layout](https://github.com/golang-standards/project-layout) +* [How Do You Structure Your Go Apps](https://github.com/katzien/go-structure-examples) +* [GoDDD](https://github.com/marcusolsson/goddd) +* [Starting an Open Source Project](https://opensource.guide/starting-a-project/) +* [README template](https://gist.github.com/PurpleBooth/109311bb0361f32d87a2) +* [CONTRIBUTING template](https://github.com/nayafia/contributing-template/blob/master/CONTRIBUTING-template.md) From 688ed991c4d2ebb6f3c9c756b49d1638e43c35ef Mon Sep 17 00:00:00 2001 From: Mathias Bruckmaier Date: Fri, 22 Jul 2022 11:59:03 +0200 Subject: [PATCH 4/4] Reverted app name in backend config to acme-apptemplatego --- terraform/backend.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/terraform/backend.tf b/terraform/backend.tf index 1d00341..9265034 100644 --- a/terraform/backend.tf +++ b/terraform/backend.tf @@ -21,7 +21,7 @@ data "terraform_remote_state" "app" { # bucket names must be globally unique across all AWS customers # so we choose a combination of company prefix ('acme') # and purpose (terraform) and appname (apptemplatego) - bucket = "mbruck-gotemplate-testapp-terraform" + bucket = "acme-apptemplatego-terraform" key = "state" # variables can't be used region = "eu-central-1"