Skip to content

Commit 04fb42f

Browse files
authored
Merge pull request #27 from meshcloud/feature/github-connector
Feature/GitHub connector
2 parents 71be478 + 439aeaf commit 04fb42f

File tree

5 files changed

+28
-39
lines changed

5 files changed

+28
-39
lines changed

modules/aks/github-connector/backplane/output.tf

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,38 +2,13 @@ output "config_tf" {
22
description = "Generates a config.tf that can be dropped into meshStack's BuildingBlockDefinition as an encrypted file input to configure this building block."
33
sensitive = true
44
value = <<-EOF
5-
terraform {
6-
backend "azurerm" {
7-
use_azuread_auth = true
8-
tenant_id = "${data.azurerm_subscription.current.tenant_id}"
9-
subscription_id = "${data.azurerm_subscription.current.subscription_id}"
10-
resource_group_name = "${var.tfstates_resource_group_name}"
11-
storage_account_name = "${var.tfstates_storage_account_name}"
12-
container_name = "${var.tfstates_storage_container_name}"
13-
key = "bb-github-connector.tfstate"
14-
15-
client_id = "${azuread_service_principal.bb_github_connector.client_id}"
16-
client_secret = "${azuread_service_principal_password.bb_github_connector.value}"
17-
}
18-
}
19-
20-
provider "kubernetes" {
5+
provider "kubernetes" {
216
host = "${data.azurerm_kubernetes_cluster.aks.kube_admin_config[0].host}"
227
cluster_ca_certificate = base64decode("${data.azurerm_kubernetes_cluster.aks.kube_admin_config[0].cluster_ca_certificate}")
238
client_certificate = base64decode("${data.azurerm_kubernetes_cluster.aks.kube_admin_config[0].client_certificate}")
249
client_key = base64decode("${data.azurerm_kubernetes_cluster.aks.kube_admin_config[0].client_key}")
2510
}
2611
27-
provider "github" {
28-
owner = "likvid-bank"
29-
30-
app_auth {
31-
id = "654209"
32-
installation_id = "44437049"
33-
pem_file = file("./likvid-bank-devops-toolchain-team.private-key.pem")
34-
}
35-
}
36-
3712
locals {
3813
aks_kubeconfig_stub = {
3914
apiVersion = "v1"

modules/aks/github-connector/buildingblock/README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,9 @@ No modules.
4949

5050
| Name | Type |
5151
|------|------|
52-
| [github_actions_secret.container_registry](https://registry.terraform.io/providers/integrations/github/6.5.0/docs/resources/actions_secret) | resource |
53-
| [github_actions_secret.kubeconfig](https://registry.terraform.io/providers/integrations/github/6.5.0/docs/resources/actions_secret) | resource |
52+
| [github_actions_environment_secret.container_registry](https://registry.terraform.io/providers/integrations/github/6.5.0/docs/resources/actions_environment_secret) | resource |
53+
| [github_actions_environment_secret.kubeconfig](https://registry.terraform.io/providers/integrations/github/6.5.0/docs/resources/actions_environment_secret) | resource |
54+
| [github_repository_environment.env](https://registry.terraform.io/providers/integrations/github/6.5.0/docs/resources/repository_environment) | resource |
5455
| [github_repository_file.dockerfile](https://registry.terraform.io/providers/integrations/github/6.5.0/docs/resources/repository_file) | resource |
5556
| [github_repository_file.workflow](https://registry.terraform.io/providers/integrations/github/6.5.0/docs/resources/repository_file) | resource |
5657
| [kubernetes_role.github_actions](https://registry.terraform.io/providers/hashicorp/kubernetes/2.35.1/docs/resources/role) | resource |

modules/aks/github-connector/buildingblock/github.tf

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,27 +23,42 @@ locals {
2323
kubeconfig = merge(local.aks_kubeconfig_stub, local.kubeconfig_user)
2424
}
2525

26-
resource "github_actions_secret" "kubeconfig" {
27-
repository = var.github_repo
26+
resource "github_repository_environment" "env" {
27+
environment = var.namespace
28+
repository = var.github_repo
29+
}
30+
31+
resource "github_actions_environment_secret" "kubeconfig" {
32+
environment = var.namespace
33+
repository = github_repository_environment.env.repository
2834
secret_name = "KUBECONFIG"
2935
plaintext_value = yamlencode(local.kubeconfig)
36+
37+
depends_on = [
38+
github_repository_environment.env
39+
]
3040
}
3141

3242

33-
resource "github_actions_secret" "container_registry" {
43+
resource "github_actions_environment_secret" "container_registry" {
3444
for_each = {
3545
host = local.acr.host
3646
username = local.acr.username
3747
password = local.acr.password
3848
}
3949

40-
repository = var.github_repo
50+
environment = var.namespace
51+
repository = github_repository_environment.env.repository
4152
secret_name = "aks_container_registry_${each.key}"
4253
plaintext_value = each.value
54+
55+
depends_on = [
56+
github_repository_environment.env
57+
]
4358
}
4459

4560
resource "github_repository_file" "dockerfile" {
46-
repository = var.github_repo
61+
repository = github_repository_environment.env.repository
4762

4863
file = "Dockerfile"
4964
content = file("${path.module}/repo_content/Dockerfile")
@@ -57,9 +72,9 @@ resource "github_repository_file" "dockerfile" {
5772
}
5873

5974
resource "github_repository_file" "workflow" {
60-
repository = var.github_repo
75+
repository = github_repository_environment.env.repository
6176

62-
file = ".github/workflows/build-deploy.yml"
77+
file = ".github/workflows/${var.namespace}-deploy.yml"
6378
content = templatefile(
6479
"${path.module}/repo_content/workflow.yml",
6580
{

modules/aks/github-connector/buildingblock/provider.tf

Lines changed: 0 additions & 3 deletions
This file was deleted.

modules/aks/github-connector/buildingblock/repo_content/workflow.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: build and deploy
1+
name: ${namespace}
22

33
on:
44
push:
@@ -8,6 +8,7 @@ on:
88
jobs:
99
deploy:
1010
runs-on: ubuntu-latest
11+
environment: ${namespace}
1112
steps:
1213
- uses: actions/checkout@v4
1314

0 commit comments

Comments
 (0)