diff --git a/.github/workflows/deploy.yaml b/.github/workflows/deploy.yaml index 6bff0e2..520f0db 100644 --- a/.github/workflows/deploy.yaml +++ b/.github/workflows/deploy.yaml @@ -59,6 +59,12 @@ jobs: region: [ 'europe-central2' ] steps: - uses: actions/checkout@v3 + - uses: google-github-actions/auth@v0 + id: google_auth + with: + workload_identity_provider: ${{ secrets.GOOGLE_WORKLOAD_IDENTITY_PROVIDER }} + service_account: ${{ secrets.GOOGLE_SERVICE_ACCOUNT }} + # Deploy function - run: echo "slug=$(echo ${GITHUB_SHA} | cut -c1-7)" >> $GITHUB_ENV - uses: actions/github-script@v6 id: environment @@ -77,18 +83,24 @@ jobs: DOTNET_ENVIRONMENT: ${{ steps.environment.outputs.result }} IMAGE: gcr.io/${{ secrets.GOOGLE_PROJECT_ID }}/${{ matrix.project.service }}:${{env.slug}} Database__ConnectionString: ${{ secrets.DATABASE__CONNECTIONSTRING }} - Database__DatabaseName: ${{steps.environment.outputs.result}} + Database__DatabaseName: ${{ steps.environment.outputs.result }} Sentry__Dsn: ${{ secrets.SENTRY__DSN }} with: in-file: ${{ matrix.project.name }}/service.yaml out-file: ${{ matrix.project.name }}/service.deploy.yaml - run: cat ${{ matrix.project.name }}/service.deploy.yaml - - uses: google-github-actions/auth@v0 - id: google_auth - with: - workload_identity_provider: ${{ secrets.GOOGLE_WORKLOAD_IDENTITY_PROVIDER }} - service_account: ${{ secrets.GOOGLE_SERVICE_ACCOUNT }} - uses: google-github-actions/deploy-cloudrun@v0 + id: cloudrun with: metadata: ${{ matrix.project.name }}/service.deploy.yaml region: ${{ matrix.region }} + # Deploy infra (terraform) + - uses: hashicorp/setup-terraform@v2 + - run: | + test -d ${{ matrix.project.name }}/terraform || exit 0 + cd ${{ matrix.project.name }}/terraform + terraform init + terraform plan \ + -var "environment=${{ env.environment_lowercase }}" \ + -var "cloudrun_url=${{ steps.cloudrun.outputs.url }}" + terraform apply diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 43c372d..466eb97 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -6,7 +6,7 @@ jobs: ######################################################### # Code quality and unit tests ######################################################### - test_quality: + test_quality_dotnet: runs-on: ubuntu-latest strategy: matrix: @@ -18,8 +18,26 @@ jobs: with: dotnet-version: ${{ matrix.dotnet-version }} - run: dotnet format --verify-no-changes + + + test_quality_terraform: + runs-on: ubuntu-latest + strategy: + matrix: + project: + - name: 'App.Function.Banktransaction.Import' + service: 'function-banktransaction-import' + dotnet-version: '6.0' + steps: + - uses: actions/checkout@v3 + - uses: hashicorp/setup-terraform@v2 + - run: | + test -d ${{ matrix.project.name }}/terraform || exit 0 + cd ${{ matrix.project.name }}/terraform + terraform init + terraform validate - test_integration: + test_unit: runs-on: ubuntu-latest strategy: matrix: diff --git a/.gitignore b/.gitignore index 58343ae..b2cfd74 100644 --- a/.gitignore +++ b/.gitignore @@ -2,5 +2,7 @@ bin/ obj/ /packages/ riderModule.iml +terraform.tfstate +.terraform/ /_ReSharper.Caches/ /.idea diff --git a/App.Function.Banktransaction.Import/queue.yaml b/App.Function.Banktransaction.Import/queue.yaml deleted file mode 100644 index 5a4fb1f..0000000 --- a/App.Function.Banktransaction.Import/queue.yaml +++ /dev/null @@ -1,8 +0,0 @@ -queue: - - name: queue-banktransaction-import - max_concurrent_requests: 100 - retry_parameters: - target: queue-banktransaction-import - min_backoff_seconds: 10 - max_backoff_seconds: 3600 - task_retry_limit: 7 \ No newline at end of file diff --git a/App.Function.Banktransaction.Import/terraform/.terraform.lock.hcl b/App.Function.Banktransaction.Import/terraform/.terraform.lock.hcl new file mode 100644 index 0000000..f4176d0 --- /dev/null +++ b/App.Function.Banktransaction.Import/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/google" { + version = "4.40.0" + constraints = "~> 4.40.0" + hashes = [ + "h1:dBRMh+QRcivqOC8+mWC32/uN5TAi7ecEo2E+MTCIeiE=", + "zh:30cf1230864a162f6811e1ba892da662ae5de7c393cac548397463e7ad6471be", + "zh:33ba8d9fc8288de4eedd3d37e44229ab7466b71aa8e50170ed310a551f6c9189", + "zh:53748600ebb4707f039a05d75475148a13914aeae7416947db6d2d80b3991a14", + "zh:75331e3af45929f7eb696e8e18a84e48cef87df5f66d4924b63487e807003836", + "zh:76531a0bf9736a022c5b5bfb14a51f727cff28857f81b9ca0437dc3bf1d7f643", + "zh:879ee4fd1f07557e981ebe22e0961ceca37ddda69d18a203e702574dc30f47dd", + "zh:ae497e030c6926f897950f1cf714847c4459159dc33afedb9055eadb82159165", + "zh:da2c517396d109e319f279a14139b43e959ba7694da2a55db90f41aa3e446bbd", + "zh:ebd03dc3f5b1287feaf0cb619701f13646824bd5af7e93e3b55e821f96f9c6c3", + "zh:f05dcdc5701882c4a2cce34fe8ebe8069af4d35daf4f2dda3492fa2314109adb", + "zh:f569b65999264a9416862bca5cd2a6177d94ccb0424f3a4ef424428912b9cb3c", + "zh:f6232e0db8716daa6526ed9c10873b3e892c2602c0521b4079a24203e56d366d", + ] +} diff --git a/App.Function.Banktransaction.Import/terraform/main.tf b/App.Function.Banktransaction.Import/terraform/main.tf new file mode 100644 index 0000000..d7e0665 --- /dev/null +++ b/App.Function.Banktransaction.Import/terraform/main.tf @@ -0,0 +1,31 @@ +variable "environment" { + type = string +} + +variable "cloudrun_url" { + type = string +} + +terraform { + required_providers { + google = { + source = "hashicorp/google" + version = "~> 4.40.0" + } + } +} + +provider "google" {} + +resource "google_pubsub_topic" "bankstransaction-import" { + name = "bankstransaction-import-${var.environment}" +} + +resource "google_pubsub_subscription" "bankstransaction-import" { + name = "function-bankstransaction-import-${var.environment}" + topic = google_pubsub_topic.bankstransaction-import.name + + push_config { + push_endpoint = var.cloudrun_url + } +} \ No newline at end of file