Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions bank42/argocd-application.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# ArgoCD Application Resource
# This manages the bank-app application in ArgoCD

resource "kubectl_manifest" "argocd_application" {
yaml_body = <<-YAML
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
name: ${var.app_name}
namespace: argocd
spec:
project: default

# Source - GitHub repository
source:
repoURL: ${var.repo_url}
targetRevision: ${var.target_revision}
path: ${var.manifest_path}

# Destination - EKS cluster
destination:
server: https://kubernetes.default.svc
namespace: ${var.destination_namespace}

# Sync policy - Automatic with self-heal
syncPolicy:
automated:
prune: true # Delete resources that are no longer in Git
selfHeal: true # Auto-sync when cluster state drifts from Git
allowEmpty: false
syncOptions:
- CreateNamespace=true
retry:
limit: 5
backoff:
duration: 5s
factor: 2
maxDuration: 3m
YAML
}
Empty file added bank42/backend.tf
Empty file.
24 changes: 24 additions & 0 deletions bank42/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
output "argocd_application_name" {
description = "Name of the ArgoCD application"
value = var.app_name
}

output "argocd_ui_url" {
description = "URL to access ArgoCD UI (via port-forward)"
value = "http://localhost:8080"
}

output "github_repo" {
description = "GitHub repository being synced"
value = var.repo_url
}

output "manifest_path" {
description = "Path in repository being synced"
value = var.manifest_path
}

output "deployment_namespace" {
description = "Kubernetes namespace where app is deployed"
value = var.destination_namespace
}
23 changes: 23 additions & 0 deletions bank42/provider.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
terraform {
required_version = ">= 1.0"

required_providers {
kubernetes = {
source = "hashicorp/kubernetes"
version = "~> 2.23"
}
kubectl = {
source = "gavinbunney/kubectl"
version = "~> 1.14"
}
}
}

# Configure Kubernetes provider to use the EKS cluster
provider "kubernetes" {
config_path = "~/.kube/config"
}

provider "kubectl" {
config_path = "~/.kube/config"
}
177 changes: 177 additions & 0 deletions bank42/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
# Bank 42 - Task 3.2.2: GitOps Configuration with ArgoCD

This folder contains Terraform configuration for managing ArgoCD applications that sync Kubernetes manifests from GitHub.

## Overview

**Task**: Configure GitOps tool (ArgoCD) to sync from the kubernetes-manifests repository

**Components**:
- ArgoCD is installed in the `dev-test-eks` EKS cluster
- ArgoCD Application syncs manifests from: `https://github.com/pod4-devops/bank-kubernetes-manifest`
- Manifest path: `bank-57-automation`
- Automatic sync with prune and self-heal enabled

## Prerequisites

1. AWS CLI configured with `devops-test-user` profile
2. kubectl configured to connect to `dev-test-eks` cluster
3. ArgoCD already installed in the cluster (in `argocd` namespace)
4. Access to the GitHub repository

## Files

- **`provider.tf`** - Kubernetes and kubectl provider configuration
- **`argocd-application.tf`** - ArgoCD Application resource definition
- **`variables.tf`** - Input variables for configuration
- **`backend.tf`** - S3 backend for Terraform state
- **`outputs.tf`** - Output values after deployment

## Setup Instructions

### 1. Set AWS Profile

```bash
export AWS_PROFILE=devops-test-user
```

### 2. Initialize Terraform

```bash
cd ~/TerraformProjects/bank-infra/bank42
terraform init
```

### 3. Review the Plan

```bash
terraform plan
```

### 4. Apply Configuration

```bash
terraform apply
```

This will create the ArgoCD Application resource that syncs your manifests.

## Accessing ArgoCD UI

### 1. Port Forward to ArgoCD Server

```bash
kubectl port-forward service/argocd-server -n argocd 8080:443
```

### 2. Get Admin Password

```bash
kubectl -n argocd get secret argocd-initial-admin-secret -o jsonpath="{.data.password}" | base64 -d
```

### 3. Open Browser

Navigate to: `http://localhost:8080`

**Login credentials**:
- Username: `admin`
- Password: (from step 2)

## How GitOps Works

1. **Developer pushes code** to the GitHub repository
2. **ArgoCD detects changes** (every 3 minutes by default)
3. **ArgoCD syncs automatically** with the cluster
4. **Self-heal enabled** - if someone manually changes the cluster, ArgoCD reverts it back to Git state
5. **Prune enabled** - if you delete something from Git, ArgoCD deletes it from the cluster

## Application Details

- **Application Name**: `bank-app`
- **Source Repository**: `https://github.com/pod4-devops/bank-kubernetes-manifest`
- **Target Branch**: `HEAD` (main/master)
- **Manifest Path**: `bank-57-automation`
- **Destination Namespace**: `default`
- **Sync Policy**: Automatic (prune + self-heal)

## Manifests Being Deployed

The `bank-57-automation` folder contains:
- `backendapi.yaml` - Backend API deployment
- `frontend.yaml` - Frontend deployment
- `bankend-service.yaml` - Backend service
- `frontend-service.yaml` - Frontend service
- `backend-ingress.yaml` - Ingress configuration
- `configmap.yaml` - Configuration
- `secret.yaml` - Secrets
- `alertmanager-config.yaml` - Monitoring
- `prometheus-rules.yaml` - Prometheus rules

## Verification

### Check ArgoCD Application Status

```bash
kubectl get application -n argocd
```

### Check Deployed Resources

```bash
kubectl get all -n default
```

### View ArgoCD Logs

```bash
kubectl logs -n argocd deployment/argocd-server
```

## Troubleshooting

### Application Not Syncing

1. Check ArgoCD application status:
```bash
kubectl describe application bank-app -n argocd
```

2. Check if ArgoCD can access GitHub:
```bash
kubectl logs -n argocd deployment/argocd-repo-server
```

### Authentication Issues

If you get "server has asked for client to provide credentials":

```bash
# Make sure you're using the right AWS profile
export AWS_PROFILE=devops-test-user

# Update kubeconfig
aws eks update-kubeconfig --name dev-test-eks --region us-east-1
```

## Cleanup

To remove the ArgoCD application (but keep ArgoCD itself):

```bash
terraform destroy
```

## Notes

- ArgoCD was installed using Helm (not Terraform) - see installation commands in team documentation
- This Terraform configuration only manages the ArgoCD Application resource
- State is stored in S3: `s3://digitalwitchngbucketcloud1/digitalwitchng/bank42/terraform.tfstate`

## Next Steps

After completing this task, you can:
1. Add more applications to ArgoCD
2. Configure notifications for sync events
3. Set up RBAC for team members
4. Integrate with CI/CD pipeline for automated deployments
41 changes: 41 additions & 0 deletions bank42/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
variable "app_name" {
description = "Name of the ArgoCD application"
type = string
default = "bank-app"
}

variable "repo_url" {
description = "GitHub repository URL containing Kubernetes manifests"
type = string
default = "https://github.com/pod4-devops/bank-kubernetes-manifest"
}

variable "target_revision" {
description = "Git branch, tag, or commit to sync from"
type = string
default = "HEAD"
}

variable "manifest_path" {
description = "Path within the repository containing the manifests"
type = string
default = "bank-57-automation"
}

variable "destination_namespace" {
description = "Kubernetes namespace where the application will be deployed"
type = string
default = "default"
}

variable "cluster_name" {
description = "EKS cluster name"
type = string
default = "dev-test-eks"
}

variable "aws_region" {
description = "AWS region where the EKS cluster is located"
type = string
default = "us-east-1"
}
9 changes: 9 additions & 0 deletions bank46/terraform/irsa/data.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Get information about the EKS cluster
data "aws_eks_cluster" "selected" {
name = var.cluster_name
}

# Get the OIDC provider URL from the cluster
data "aws_eks_cluster_auth" "selected" {
name = var.cluster_name
}
32 changes: 32 additions & 0 deletions bank46/terraform/irsa/iam-policy.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# IAM Policy for Secrets Manager and SSM Parameter Store access
resource "aws_iam_policy" "secret_access" {
name = "Bank46-SecretAccess-Policy"
description = "Policy for Bank46 project to access Secrets Manager and Parameter Store"

policy = jsonencode({
Version = "2012-10-17"
Statement = [
{
Effect = "Allow"
Action = [
"secretsmanager:GetSecretValue",
"secretsmanager:DescribeSecret",
"ssm:GetParameters",
"ssm:GetParameter",
"ssm:DescribeParameters"
]
Resource = "*"
}
]
})

tags = {
Project = "Bank46"
Environment = var.environment
ManagedBy = "Terraform"
}
}

output "policy_arn" {
value = aws_iam_policy.secret_access.arn
}
Loading