A Kubernetes Terraform Controller

Owner
Open Application Model
Make shipping applications more enjoyable
Open Application Model
Comments
  • Import hcl instead of inlining

    Import hcl instead of inlining

    Hello,

    I see there is a examples/tf-native folder with *.tf files. Is it possible to use external *.tf files instead of using spec.hcl yaml blocks?

    Thanks!

    Jun

  • [FEATURE] - Run Jobs in central namespace

    [FEATURE] - Run Jobs in central namespace

    Currently all jobs are run in the namespace the configuration CRD is created in, which given how the provider secret implementation works (copying the secret into the desiganated namespace) exposes central credentials. This PR adds a conntroller flag (--controller-namespace) which runs all jobs in a specific namespace and ensuring any secrets are never exposed beyond that boundary.

    • Also add the ability to run the jobs under a serviceaccount, extending the Provider CRD. When run via the --job-namespace the platform administrator can provision a service account with Pod identity (EKS IRSA) and remove the need for static secrets.
  • Add EC support to Terraform controller

    Add EC support to Terraform controller

    This change adds support for the EC module in terraform-controller. Without this change the EC provider for Elastic Cloud cannot be used via the terraform-controller because it does not know how to find secrets.

  • Feat: Support retrieving modules in private git repo through SSH

    Feat: Support retrieving modules in private git repo through SSH

    This is a PR to Support SSH for retrieving terraform modules in private git repo for this issue: https://github.com/kubevela/terraform-controller/issues/292 There is a corresponding PR in kubevela repo: https://github.com/kubevela/kubevela/pull/5059

    This change require a secret which hold the SSH private key and known hosts for the git repo: known_hosts can be generated using ssh-keyscan <git-url>

    apiVersion: v1
    kind: Secret
    metadata:
      name: git-ssh
      namespace: vela-system
    type: kubernetes.io/ssh-auth
    stringData:
      ssh-privatekey: |
       <SSH Private Key> # the ssh private key used for authenticating git
      known_hosts: |
       <SSH known_hosts>  # use `ssh-keyscan github.com`  to generate known_hosts
    
  • Support custom Terraform backends

    Support custom Terraform backends

    This pr is supposed to implement the proposal which is the concluation of the issuse #288 .

    Currently, the changes only add some fields to the spec.backend to enable the end-users to custom the Terraform backend configuration.

    Signed-off-by: loheagn [email protected]

  • Map type object are not getting read by terraform controller

    Map type object are not getting read by terraform controller

    The map type object are not getting read into into terraform variable .It always complains that the variable being read into always comes empty. The file doesn't define case for handling map type object. https://github.com/oam-dev/terraform-controller/blob/master/controllers/configuration/convert.go

  • Error fetching providers from terraform-registry

    Error fetching providers from terraform-registry

    I use terraform-controller to deploy helm releases.

    Everything goes fine in my dev env, but sometimes terraform init will stuck in fetching providers from terraform registry due to network issue

    I see all volumes mounted in apply-job is emptyDir and mounted as a directory, a 'pre-init' images with all providers downloaded can not work as expected

    Maybe there should be something like "-plugin-dir" from terraform init command

    image

  • remove owner reference for job

    remove owner reference for job

    when the configuration is outside of the namespace of the job in this case the controllerNamespace, the owner reference causes de job to be garbage collected and continuosly be recreated

  • chart templates applying is not friendly for local development

    chart templates applying is not friendly for local development

    As we are using .Release.Namespace in the chart, it's not friendly for local development. @lewis-od Any suggestions?

    ➜  /Users/zhouzhengxi/Programming/golang/src/github.com/oam-dev/terraform-controller/chart/templates git:(aws-example) ✗ k apply -f .
    role.rbac.authorization.k8s.io/read-provider-creds created
    clusterrole.rbac.authorization.k8s.io/tf-api-role configured
    clusterrole.rbac.authorization.k8s.io/tf-controller-clusterrole created
    role.rbac.authorization.k8s.io/tf-controller-role created
    error parsing terraform_controller.yaml: error converting YAML to JSON: yaml: invalid map key: map[interface {}]interface {}{".Release.Namespace":interface {}(nil)}
    error parsing tf_api_role_binding.yaml: error converting YAML to JSON: yaml: invalid map key: map[interface {}]interface {}{".Release.Namespace":interface {}(nil)}
    error parsing tf_controller_clusterrolebinding.yml: error converting YAML to JSON: yaml: invalid map key: map[interface {}]interface {}{".Release.Namespace":interface {}(nil)}
    error parsing tf_controller_role_binding.yaml: error converting YAML to JSON: yaml: invalid map key: map[interface {}]interface {}{".Release.Namespace":interface {}(nil)}
    error parsing tf_controller_service_account.yml: error converting YAML to JSON: yaml: invalid map key: map[interface {}]interface {}{".Release.Namespace":interface {}(nil)}
    error parsing tf_executor_role.yml: error converting YAML to JSON: yaml: invalid map key: map[interface {}]interface {}{".Release.Namespace":interface {}(nil)}
    error parsing tf_executor_rolebinding.yml: error converting YAML to JSON: yaml: invalid map key: map[interface {}]interface {}{".Release.Namespace":interface {}(nil)}
    error parsing tf_executor_service_account.yml: error converting YAML to JSON: yaml: invalid map key: map[interface {}]interface {}{".Release.Namespace":interface {}(nil)}
    
  • Fix: legacy backend state reading and GC

    Fix: legacy backend state reading and GC

    For now if restart controller with --controller-namespace. The configuration state will become GeneratingTerraformOutputs and stuck. This is because controller can't got the legacy backend.

    Fix that Configuration.Spec.Backend will be overwritten if set --controller-namespace. Instead, now controller only overwrite Configuration.Spec.Backend when no backend specified.

    How is this tested

    Add both unittest and e2e test

    Signed-off-by: Qiaozp [email protected]

  • Configuration won't get deleted when its namespace is being deleted.

    Configuration won't get deleted when its namespace is being deleted.

    A Configuration won't get deleted when its namespace is being deleted. Please look into the details of this issue, please refer to https://cloud-native.slack.com/archives/C01BLQ3HTJA/p1656829163511879.

    Here are the steps to reproduce the issue.

    • Apply the Configuration
    apiVersion: terraform.core.oam.dev/v1beta2
    kind: Configuration
    metadata:
      name: random-e2e
      namespace: n1
    spec:
      hcl: |
        resource "random_id" "server" {
          byte_length = 8
        }
        
        output "random_id" {
          value = random_id.server.hex
        }
    
      inlineCredentials: true
    
      writeConnectionSecretToRef:
        name: random-conn
        namespace: default
    
    • When the Configuration becomes ready, delete namespace n1.

    The deletion of the Configuration got stuck and there are issues in the log of Terraform Controller.

    apiVersion: terraform.core.oam.dev/v1beta2
    kind: Configuration
    metadata:
      name: random-e2e
      namespace: n1
    spec:
      hcl: |
        resource "random_id" "server" {
          byte_length = 8
        }
        
        output "random_id" {
          value = random_id.server.hex
        }
    
      inlineCredentials: true
    
      writeConnectionSecretToRef:
        name: random-conn
        namespace: default
    
  • Support customized .terraformrc and credentials.tfrc.json

    Support customized .terraformrc and credentials.tfrc.json

    Sometimes users want to use customized .terraformrc and credentials.tfrc.json files. Here's one use case:

    • Use self-hosted JFrog Artifactory to proxy and cache AWS provider resource. These two files are used to point to the self-hosted services and provide credentials.

    We should support mount volumes for each file when apply jobs.

    Configuration like:

    apiVersion: terraform.core.oam.dev/v1beta2
    kind: Configuration
    metadata:
      name: custom-rc
    spec:
      cliConfiguationSecretRef:
        name: cli-conf
        namespace: default
      remote: <module>
      ...
    

    And the Secret like:

    apiVersion: v1
    kind: Secret
    metadata:
      name: cli-conf
      namespace: default
    data:
      terraformrc: |
       ...
      credentials.tfrc.json: |
       ...
    
  • Add CodeQL workflow for GitHub code scanning

    Add CodeQL workflow for GitHub code scanning

    Hi kubevela/terraform-controller!

    This is a one-off automatically generated pull request from LGTM.com :robot:. You might have heard that we’ve integrated LGTM’s underlying CodeQL analysis engine natively into GitHub. The result is GitHub code scanning!

    With LGTM fully integrated into code scanning, we are focused on improving CodeQL within the native GitHub code scanning experience. In order to take advantage of current and future improvements to our analysis capabilities, we suggest you enable code scanning on your repository. Please take a look at our blog post for more information.

    This pull request enables code scanning by adding an auto-generated codeql.yml workflow file for GitHub Actions to your repository — take a look! We tested it before opening this pull request, so all should be working :heavy_check_mark:. In fact, you might already have seen some alerts appear on this pull request!

    Where needed and if possible, we’ve adjusted the configuration to the needs of your particular repository. But of course, you should feel free to tweak it further! Check this page for detailed documentation.

    Questions? Check out the FAQ below!

    FAQ

    Click here to expand the FAQ section

    How often will the code scanning analysis run?

    By default, code scanning will trigger a scan with the CodeQL engine on the following events:

    • On every pull request — to flag up potential security problems for you to investigate before merging a PR.
    • On every push to your default branch and other protected branches — this keeps the analysis results on your repository’s Security tab up to date.
    • Once a week at a fixed time — to make sure you benefit from the latest updated security analysis even when no code was committed or PRs were opened.

    What will this cost?

    Nothing! The CodeQL engine will run inside GitHub Actions, making use of your unlimited free compute minutes for public repositories.

    What types of problems does CodeQL find?

    The CodeQL engine that powers GitHub code scanning is the exact same engine that powers LGTM.com. The exact set of rules has been tweaked slightly, but you should see almost exactly the same types of alerts as you were used to on LGTM.com: we’ve enabled the security-and-quality query suite for you.

    How do I upgrade my CodeQL engine?

    No need! New versions of the CodeQL analysis are constantly deployed on GitHub.com; your repository will automatically benefit from the most recently released version.

    The analysis doesn’t seem to be working

    If you get an error in GitHub Actions that indicates that CodeQL wasn’t able to analyze your code, please follow the instructions here to debug the analysis.

    How do I disable LGTM.com?

    If you have LGTM’s automatic pull request analysis enabled, then you can follow these steps to disable the LGTM pull request analysis. You don’t actually need to remove your repository from LGTM.com; it will automatically be removed in the next few months as part of the deprecation of LGTM.com (more info here).

    Which source code hosting platforms does code scanning support?

    GitHub code scanning is deeply integrated within GitHub itself. If you’d like to scan source code that is hosted elsewhere, we suggest that you create a mirror of that code on GitHub.

    How do I know this PR is legitimate?

    This PR is filed by the official LGTM.com GitHub App, in line with the deprecation timeline that was announced on the official GitHub Blog. The proposed GitHub Action workflow uses the official open source GitHub CodeQL Action. If you have any other questions or concerns, please join the discussion here in the official GitHub community!

    I have another question / how do I get in touch?

    Please join the discussion here to ask further questions and send us suggestions!

  • Support `prevent_destroy` feature for cloud resources

    Support `prevent_destroy` feature for cloud resources

    A few users kept asking whether we can support preventing cloud resources from being deleted. We asked them to use the delete protection feature if the cloud provides the option like https://registry.terraform.io/providers/aliyun/alicloud/latest/docs/resources/ess_scaling_group#group_deletion_protection.

    Now Terraform officially provides prevent_destroy in lifecycle with a resource since v1.3 https://developer.hashicorp.com/terraform/tutorials/state/resource-lifecycle#prevent-resource-deletion. We might also need to support it.

  • [Feature request] Skip destroy if no resource is actually created

    [Feature request] Skip destroy if no resource is actually created

    Feature Request

    Now we will dispatch destroy job if Configuration is deleted. However, sometimes no resources is created due to the wrong Configuration. In this case, we should detect the resource creation phase and skip the destroy phase depends on the situation.

    1. What https://github.com/kubevela/kubevela/pull/3929 do

    In deletion part, kubevela#3929 will set configuration.spec.forceDelete to true. Anything else is dealt with terraform-controller.

    Origin Post

    Hey, I know this is merged, but I realized when you have something wrong the deletion don't complete. For example, Imagine you go to the Cloud provider portal and delete the resource, terraform will fail to delete saying the resource doesn't exist, like this:

    Error: Error: Subnet: (Name "subnet-1" / Virtual Network Name "vnet-1" / Resource Group "example1") was not found
    

    The same happen if I accidentally make a mistake in a HCL and apply some components in an application, but try to delete after realize I did a mistake, the delete never happen.

    I just did it on my test environment and can't delete the application even using force.

    image

    I receive a:

    Deleting Application "vm-1"
    force deleted the resources created by application
    successfully cleanup the resources created by application, but fail to delete the application
    Error: timed out waiting for the condition
    

    Originally posted by @alisson276 in https://github.com/kubevela/kubevela/issues/3929#issuecomment-1143801240

  • Support private git repository through credentials passed to the providerconfig similar to crossplane

    Support private git repository through credentials passed to the providerconfig similar to crossplane

    the providerConfig for crossplane's provider-terraform supports git-credentials file for authentication to pull the terraform module from private git repo. ref: https://github.com/crossplane-contrib/provider-terraform#private-git-repository-support

    kubevela's terraform provider should support private git using similar mechanism since it is already doing so for cloud credentials e.g. AWS through the provider

A Controller written in kubernetes sample-controller style which watches a custom resource named Bookstore

bookstore-sample-controller A Controller written in kubernetes sample-controller style which watches a custom resource named Bookstore. A resource cre

Jan 20, 2022
Terraform Controller manages the life cycles of a terraform resource, allowing developers to self-serve dependencies in a controlled manner.
Terraform Controller manages the life cycles of a terraform resource, allowing developers to self-serve dependencies in a controlled manner.

TERRAFORM CONTROLLER Terraform Controller manages the life cycles of a terraform resource, allowing developers to self-serve dependencies in a control

Dec 15, 2022
A Kubernetes Terraform Controller
A Kubernetes Terraform Controller

Terraform Controller Terraform Controller is a Kubernetes Controller for Terraform, which can address the requirement of Using Terraform HCL as IaC mo

Jan 2, 2023
Terraform-equinix-migration-tool - Tool to migrate code from Equinix Metal terraform provider to Equinix terraform provider

Equinix Terraform Provider Migration Tool This tool targets a terraform working

Feb 15, 2022
Terraform-in-Terraform: Execute Modules directly from the Terraform Registry

Terraform-In-Terraform Provider This provider allows running Terraform in Terraform. This might seem insane but there are some edge cases where it com

Dec 25, 2022
network-node-manager is a kubernetes controller that controls the network configuration of a node to resolve network issues of kubernetes.
network-node-manager is a kubernetes controller that controls the network configuration of a node to resolve network issues of kubernetes.

Network Node Manager network-node-manager is a kubernetes controller that controls the network configuration of a node to resolve network issues of ku

Dec 18, 2022
Carrier is a Kubernetes controller for running and scaling game servers on Kubernetes.
Carrier is a Kubernetes controller for running and scaling game servers on Kubernetes.

Carrier is a Kubernetes controller for running and scaling game servers on Kubernetes. This project is inspired by agones. Introduction Genera

Nov 25, 2022
A Terraform controller for Flux

tf-controller A Terraform controller for Flux Quick start Here's a simple exampl

Dec 29, 2022
Annotated and kubez-autoscaler-controller will maintain the HPA automatically for kubernetes resources.

Kubez-autoscaler Overview kubez-autoscaler 通过为 deployment / statefulset 添加 annotations 的方式,自动维护对应 HorizontalPodAutoscaler 的生命周期. Prerequisites 在 kuber

Jan 2, 2023
the simplest testing framework for Kubernetes controller.

KET(Kind E2e Test framework) KET is the simplest testing framework for Kubernetes controller. KET is available as open source software, and we look fo

Dec 10, 2022
Kubernetes workload controller for container image deployment

kube-image-deployer kube-image-deployer는 Docker Registry의 Image:Tag를 감시하는 Kubernetes Controller입니다. Keel과 유사하지만 단일 태그만 감시하며 더 간결하게 동작합니다. Container, I

Mar 8, 2022
An Ingress controller for Kubernetes using NGINX as a reverse proxy and load balancer

NGINX Ingress Controller Overview ingress-nginx is an Ingress controller for Kubernetes using NGINX as a reverse proxy and load balancer. Learn more a

Nov 15, 2021
A kubernetes controller that watches the Deployments and “caches” the images
A kubernetes controller that watches the Deployments and “caches” the images

image-cloner This is just an exercise. It's a kubernetes controller that watches

Dec 20, 2021
Kubernetes Admission controller for golang

KCAdm Kubernetes Admission controller Test locally First create the required cer

Dec 23, 2021
Sesame: an Ingress controller for Kubernetes that works by deploying the Envoy proxy as a reverse proxy and load balancer

Sesame Overview Sesame is an Ingress controller for Kubernetes that works by dep

Dec 28, 2021
Kubernetes controller for backing up public container images to our own registry repository

image-clone-controller Kubernetes controller which watches applications (Deployment and DaemonSet) and "caches" the images (public container images) b

Aug 28, 2022
Kubernetes Admission Controller Demo: Validating Webhook for Namespace lifecycle events

Kubernetes Admission Controller Based on How to build a Kubernetes Webhook | Admission controllers Local Kuberbetes cluster # create kubernetes cluste

Feb 27, 2022
K8s-delete-protection - Kubernetes admission controller to avoid deleteing master nodes

k8s-delete-protection Admission Controller If you want to make your Kubernetes c

Nov 2, 2022
Kngrok - Kubernetes controller for ngrok tunnel

kngrok ken-grok What is kngrok? kngrok is a Kubernetes controller to operate ngr

Feb 15, 2022