Skip to content

Instantly share code, notes, and snippets.

View sergsoares's full-sized avatar

Sergio Soares sergsoares

View GitHub Profile
@sergsoares
sergsoares / manifest.yml
Created July 14, 2022 18:23
Create a Cluster Role but only use RoleBinding to give access for only 2 specific namespaces (otherwise all namespaces like ClusterRoleBinding)
apiVersion: v1
kind: ServiceAccount
metadata:
name: myapp
namespace: mynamespace
---
kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1
metadata:
namespace: mynamespace
@sergsoares
sergsoares / main.tf
Created July 13, 2022 15:35
Generate dynamically policies based on input and attach for already created roles and users
locals {
policies_arns = {
for item in aws_iam_policy.policy :
item.name => item.arn
}
users_attachment = distinct(
flatten([
for item in var.policies : [
for user in item.users_to_attach : {
@sergsoares
sergsoares / main.tf
Created July 13, 2022 15:31
Demonstração de ideia para criação de policies dinâmicas com attach em múltiplos users e roles.
# terraform.tfvars
policies = [
{
policy_name = "policy-alpha",
roles_to_attach = []
users_to_attach = ["user1", "user2"]
content = {}
},
{
@sergsoares
sergsoares / main.tf
Created July 11, 2022 19:25
Snippet for use variables as a map
# variables.tf
variable "myapp_conf" {
type = map
}
# terraform.tfvars
myapp_conf = {
REPLICAS = 0
LIMIT_CPU = "50m"
LIMIT_MEMORY = "96Mi"
@sergsoares
sergsoares / main.go
Last active May 15, 2022 15:28
Example in pure go of read a ENV VAR and leaving default value if not exists (In that case already convert from string to integer)
import (
"os"
"strconv"
)
func main() {
tc := 1
if temp := os.Getenv("THREADS"); temp != "" {
number, err := strconv.Atoi(temp)
if err != nil {
@sergsoares
sergsoares / main.tf
Created May 11, 2022 17:30
Example of kubernetes_ingress with Kubernetes provider for terraform
resource "kubernetes_ingress" "node0_ingress" {
metadata {
name = local.node0
namespace = local.namespace
annotations = {
"kubernetes.io/ingress.class" = "nginx"
"nginx.ingress.kubernetes.io/backend-protocol" = "HTTP"
"nginx.ingress.kubernetes.io/enable-cors" = "true"
}
}
@sergsoares
sergsoares / deployment.tf
Created May 11, 2022 17:24
Example of deployment with Kubernetes provider for terraform (kubectl_manifest)
resource "kubectl_manifest" "node0_deployment" {
apply_only = true
wait_for_rollout = false
yaml_body = <<YAML
apiVersion: apps/v1
kind: Deployment
metadata:
name: ${local.node0}
namespace: ${local.namespace}
@sergsoares
sergsoares / manifest.yml
Created May 11, 2022 17:23
Deployment Structure
apiVersion: apps/v1
kind: Deployment
metadata:
name: node0
namespace: namespace
labels:
app: node0
spec:
replicas: 3
selector:
@sergsoares
sergsoares / script.sh
Created May 10, 2022 16:49
Ubuntu server - Minimal Desktop possible with lxde
sudo apt-get install lxde xorg lxdm --no-install-recommends
@sergsoares
sergsoares / main.tf
Created May 9, 2022 14:32
Terraform example for process a list of names, adding a domain and join all in a single string.
# File: main.tf
locals {
# Static variables
domain = "domain.com"
name_list = [
"name1",
"name2",
"name3"
]