Bootstrap FreeKB - OpenShift - Create a Project using Terraform
OpenShift - Create a Project using Terraform

Updated:   |  OpenShift articles

This assumes you have setup and initialized Terraform for OpenShift. If not, check out my article OpenShift Getting Started with Terraform.

Let's say you have the following files on your Terraform server.

├── locals.tf
├── modules.tf
├── outputs.tf
├── provider.tf
├── terraform.tfstate
├── variables.tf
├── projects(directory, child module)
│   ├── data.tf
│   ├── outputs.tf
│   ├── resources.tf

 

Let's say provider.tf has the following.

terraform {
  required_providers {
    openshift = {
      source  = "llomgui/openshift"
    }
  }
}

provider "openshift" {
  load_config_file = "false"
  host = "https://api.openshift.example.com:6443"
  username = "john.doe"
  password = "itsasecret"
}

 

And let's say modules.tf has the following.

module "projects" {
  source = "./projects"
}

 

And let's say resources.tf in your projects module contains the following.

resource "openshift_project" "my-project" {
  metadata {
    annotations = {
      "openshift.io/description" = "example-description"
      "openshift.io/display-name" = "example-display-name"
    }

    name = "terraform-example-project"
  }

  lifecycle {
    ignore_changes = [metadata[0].annotations]
  }
}

 

You may need to reissue the terraform init command.

~]# terraform init
Initializing the backend...
Initializing modules...
Initializing provider plugins...
Terraform has been successfully initialized!

 

The terraform plan command should return something like this.

t]$ terraform plan

Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
  + create

Terraform will perform the following actions:

  # module.projects.openshift_project.my-project will be created
  + resource "openshift_project" "my-project" {
      + id = (known after apply)

      + metadata {
          + annotations      = {
              + "openshift.io/description"  = "example-description"
              + "openshift.io/display-name" = "example-display-name"
            }
          + generation       = (known after apply)
          + name             = "terraform-example-project"
          + resource_version = (known after apply)
          + self_link        = (known after apply)
          + uid              = (known after apply)
        }
    }

Plan: 1 to add, 0 to change, 0 to destroy.

 




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


Please enter 6aca24 in the box below so that we can be sure you are a human.