Skip to content
This repository has been archived by the owner on Feb 22, 2023. It is now read-only.

Commit

Permalink
Merge pull request #36 from jhernand/add_ccs_cluster_example
Browse files Browse the repository at this point in the history
Add CCS cluster example
  • Loading branch information
jhernand authored Nov 30, 2021
2 parents 09808d1 + 548fbba commit 27c206c
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 0 deletions.
18 changes: 18 additions & 0 deletions examples/create_ccs_cluster/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# _CCS_ cluster creation example

This example shows how to create a _CCS_ cluster. _CCS_ stands for _costumer
cloud subscription_ and is a cluster that is created in the cloud
infrastructure (AWS account or GCP project, for example) provided by the user.

In order to create a _CCS_ cluster it is necessary to have user named
`osdCcsAdmin` with the `AdministratorAccess`. The example uses the `aws`
provider to create that user and attach the role. To do so it uses the
credentials of the current user, typically taken from the `~/.aws/credentials`
file. See the documentation of the `aws` provider for details.

Once the `osdCcsAdmin` user is created the example uses the `aws` provider
again to generate an access key and secret for that user. That key and secret
are then be used to create the cluster.

To run it use adjust the description of the provider and the cluster in the
`main.tf` and then run the `terraform apply` command.
61 changes: 61 additions & 0 deletions examples/create_ccs_cluster/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#
# Copyright (c) 2021 Red Hat, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = ">= 3.67"
}
ocm = {
version = ">= 0.1"
source = "openshift-online/ocm"
}
}
}

provider "aws" {
region = "us-east-1"
}

provider "ocm" {
}

data "aws_caller_identity" "current" {
}

resource "aws_iam_user" "admin" {
name = "osdCcsAdmin"
}

resource "aws_iam_user_policy_attachment" "admin_access" {
user = aws_iam_user.admin.name
policy_arn = "arn:aws:iam::aws:policy/AdministratorAccess"
}

resource "aws_iam_access_key" "admin_key" {
user = aws_iam_user.admin.name
}

resource "ocm_cluster" "my_cluster" {
name = "my-cluster"
cloud_provider = "aws"
cloud_region = "us-east-1"
ccs_enabled = true
aws_account_id = data.aws_caller_identity.current.account_id
aws_access_key_id = aws_iam_access_key.admin_key.id
aws_secret_access_key = aws_iam_access_key.admin_key.secret
}
File renamed without changes.

0 comments on commit 27c206c

Please sign in to comment.