This repository has been archived by the owner on Feb 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from jhernand/initial_prototype
Initial prototype
- Loading branch information
Showing
21 changed files
with
2,551 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# | ||
# 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. | ||
# | ||
|
||
name: Check pull request | ||
|
||
on: | ||
pull_request: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
|
||
test: | ||
name: Test | ||
strategy: | ||
matrix: | ||
platform: | ||
- ubuntu-latest | ||
- macos-latest | ||
- windows-latest | ||
runs-on: ${{ matrix.platform }} | ||
steps: | ||
- name: Checkout the source | ||
uses: actions/checkout@v2 | ||
|
||
- name: Setup Go | ||
uses: actions/setup-go@v2 | ||
with: | ||
go-version: 1.17 | ||
|
||
- name: Setup Ginkgo | ||
run: go install github.com/onsi/ginkgo/[email protected] | ||
|
||
- name: Setup Terraform | ||
uses: hashicorp/setup-terraform@v1 | ||
with: | ||
terraform_wrapper: false | ||
|
||
- name: Run the tests | ||
run: make tests |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
*.log | ||
.terraform.d/ | ||
.terraform.lock.hcl | ||
.terraform/ | ||
terraform.tfstate |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
= Changes | ||
|
||
This document describes the relevant changes between releases of the Terraform | ||
provider for OCM. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
# | ||
# 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. | ||
# | ||
|
||
# Disable CGO so that we always generate static binaries: | ||
export CGO_ENABLED=0 | ||
|
||
# Version of the provider: | ||
version:=0.1.0 | ||
|
||
.PHONY: build | ||
build: | ||
platform=$$(terraform version -json | jq -r .platform); \ | ||
ext=""; \ | ||
if [[ "$${platform}" =~ ^windows_.*$$ ]]; then \ | ||
ext=".exe"; \ | ||
fi; \ | ||
dir=".terraform.d/plugins/localhost/redhat/ocm/$(version)/$${platform}"; \ | ||
file="terraform-provider-ocm$${ext}"; \ | ||
mkdir -p "$${dir}"; \ | ||
go build -o "$${dir}/$${file}" | ||
|
||
.PHONY: test tests | ||
test tests: build | ||
ginkgo -r tests | ||
|
||
.PHONY: fmt_go | ||
fmt_go: | ||
gofmt -s -l -w $$(find . -name '*.go') | ||
|
||
.PHONY: fmt_tf | ||
fmt_tf: | ||
terraform fmt -recursive examples | ||
|
||
.PHONY: fmt | ||
fmt: fmt_go fmt_tf | ||
|
||
.PHONY: clean | ||
clean: | ||
rm -rf .terraform.d |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
= Terraform provider for OCM | ||
|
||
== Build | ||
|
||
To build the provider use the `make` command. | ||
|
||
== Use | ||
|
||
Currently the provider isn't available in any public registry, so you will need | ||
to build it: | ||
|
||
.... | ||
$ make build | ||
.... | ||
|
||
This will create a local Terraform plugin registry in the directory | ||
`.terraform.d/plugins` of the project. Assuming that you have the project | ||
checked out in `/files/projects/terraform-provider-ocm/repository` you will | ||
need to add something like this to your Terraform CLI configuration file: | ||
|
||
.... | ||
provider_installation { | ||
filesystem_mirror { | ||
path = "/files/projects/terraform-provider-ocm/repository/.terraform.d/plugins" | ||
include = ["localhost/*/*"] | ||
} | ||
} | ||
.... | ||
|
||
If you don't want to change your global CLI configuation file you can put this | ||
in any file you like and then use the `TF_CLI_CONFIG_FILE` environment variable | ||
to point to it. For example, put the configuration in | ||
`/files/projects/terraform-provider-ocm/terraform.rc` and then set the | ||
environment variable pointing to it: | ||
|
||
.... | ||
$ cat >/files/projects/terraform-provider-ocm/terraform.rc <<. | ||
provider_installation { | ||
filesystem_mirror { | ||
path = "/files/projects/terraform-provider-ocm/repository/.terraform.d/plugins" | ||
include = ["localhost/*/*"] | ||
} | ||
} | ||
. | ||
$ export TF_CLI_CONFIG_FILE=/files/projects/terraform-provider-ocm/terraform.rc | ||
.... | ||
|
||
Once your configuration is ready you can go to the directory containing the | ||
Terraform `.tf` files and run the `terraform init` and `terraform apply` | ||
commands: | ||
|
||
.... | ||
$ terraform init | ||
$ terraform apply | ||
.... | ||
|
||
To see the debug log of the provider set the `TF_LOG` environment variable to | ||
`DEBUG` before running the `terraform apply` command: | ||
|
||
.... | ||
$ export TF_LOG=DEBUG | ||
$ terraform apply | ||
.... | ||
|
||
== Examples | ||
|
||
The `examples` directory contains some examples, together with _Makefiles_ to | ||
simplify their use. For example, to run the `create_cluster` example: | ||
|
||
.... | ||
$ make build | ||
$ cd examples/create_cluster | ||
$ make | ||
.... | ||
|
||
Note that this examples expect that you have the `ocm` command line utility | ||
installed, and use it to get a valid access token (with `ocm token`) and put it | ||
in the `OCM_TOKEN` environment variable where the provider gets the token by | ||
default. | ||
|
||
Use the `make clean` command to remove the `.terraform` and `terraform.tfstate` | ||
files so that the next time you run the example it starts from scratch. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# | ||
# 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. | ||
# | ||
|
||
.PHONY: apply | ||
apply: init | ||
OCM_TOKEN=$$(ocm token) \ | ||
terraform apply | ||
|
||
.PHONY: destroy | ||
destroy: init | ||
OCM_TOKEN=$$(ocm token) \ | ||
terraform destroy | ||
|
||
.PHONY: init | ||
init: | ||
terraform init | ||
|
||
.PHONY: | ||
clean: | ||
rm -rf .terraform .terraform.lock.hcl terraform.tfstate |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
= Cluster creation example | ||
|
||
This example shows how to create a cluster. To run it use adjust the description | ||
of the cluster in the `main.tf` file and then use the `make` command. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# | ||
# 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 { | ||
ocm = { | ||
version = "0.1" | ||
source = "localhost/redhat/ocm" | ||
} | ||
} | ||
} | ||
|
||
provider "ocm" { | ||
url = "https://api.stage.openshift.com" | ||
} | ||
|
||
resource "ocm_cluster" "my_cluster" { | ||
name = "my-cluster" | ||
cloud_provider = "aws" | ||
cloud_region = "us-west-1" | ||
properties = { | ||
fake_cluster = "true" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# | ||
# 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. | ||
# | ||
|
||
.PHONY: apply | ||
apply: init | ||
OCM_TOKEN=$$(ocm token) \ | ||
terraform apply | ||
|
||
.PHONY: init | ||
init: | ||
terraform init | ||
|
||
.PHONY: | ||
clean: | ||
rm -rf .terraform .terraform.lock.hcl terraform.tfstate |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
= Cloud provider list example | ||
|
||
This example shows how to use the cloud providers data source to get a list of | ||
the identifiers of the supported cloud providers. To run it use the `make` | ||
command. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# | ||
# 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 { | ||
ocm = { | ||
version = "0.1" | ||
source = "localhost/redhat/ocm" | ||
} | ||
} | ||
} | ||
|
||
provider "ocm" { | ||
url = "https://api.stage.openshift.com" | ||
} | ||
|
||
data "ocm_cloud_providers" "all" { | ||
} | ||
|
||
output "cloud_provider_ids" { | ||
description = "Cloud providers" | ||
value = data.ocm_cloud_providers.all.ids | ||
} |
Oops, something went wrong.