Skip to content

Commit 30f352a

Browse files
author
Shreyas Sreenivas
authored
Merge pull request #1 from vmware-tanzu/master
Migrating the code from internal project
2 parents e38c00a + e7ade6c commit 30f352a

File tree

97 files changed

+7163
-18
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

97 files changed

+7163
-18
lines changed

.gitignore

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
bin/*
2+
_output/*
3+
.DS_Store
4+
.vscode
5+
.idea/*
6+
vendor/*
7+
cover.out

.golangci.yaml

+84
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
# https://github.com/golangci/golangci-lint#config-file
2+
3+
linters:
4+
# please, do not use `enable-all`: it's deprecated and will be removed soon.
5+
# inverted configuration with `enable-all` and `disable` is not scalable during updates of golangci-lint
6+
disable-all: true
7+
enable:
8+
- asciicheck
9+
- bodyclose
10+
- deadcode
11+
- depguard
12+
- dogsled
13+
- dupl
14+
- errcheck
15+
- exportloopref
16+
- funlen
17+
- goconst
18+
- gocognit
19+
- gocritic
20+
- gocyclo
21+
- godot
22+
- gofmt
23+
- goimports
24+
- goprintffuncname
25+
- gosec
26+
- gosimple
27+
- govet
28+
- ineffassign
29+
- misspell
30+
- nakedret
31+
- nestif
32+
- prealloc
33+
- rowserrcheck
34+
- staticcheck
35+
- structcheck
36+
- stylecheck
37+
- typecheck
38+
- unconvert
39+
- unparam
40+
- unused
41+
- varcheck
42+
- whitespace
43+
- wsl
44+
45+
# don't enable:
46+
# - exhaustive
47+
# - gochecknoglobals
48+
# - godox
49+
# - gomnd
50+
# - goerr113
51+
# - gofumpt
52+
# - interfacer
53+
# - lll
54+
# - maligned
55+
# - nlreturn
56+
# - noctx
57+
# - nolintlint
58+
# - scopelint
59+
# - testpackage
60+
# - revive
61+
62+
run:
63+
# include test files or not, default is true
64+
tests: true
65+
deadline: 5m
66+
67+
linters-settings:
68+
funlen:
69+
lines: 150
70+
statements: 100
71+
gci:
72+
local-prefixes: gitlab.eng.vmware.com/olympus
73+
74+
issues:
75+
exclude-rules:
76+
- path: _test\.go
77+
linters:
78+
- dogsled
79+
- funlen
80+
- gocognit
81+
- path: internal/authctx
82+
linters:
83+
- gosec
84+
- nestif

Dockerfile

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#Copyright © 2021 VMware, Inc. All Rights Reserved.
2+
#SPDX-License-Identifier: MPL-2.0
3+
4+
FROM 498533941640.dkr.ecr.us-west-2.amazonaws.com/base-images/golang-build-1.16 as build
5+
WORKDIR /go/src/gitlab.eng.vmware/olympus/terraform-provider-tanzu
6+
7+
COPY .golangci.yaml go.mod go.sum ./
8+
COPY cmd cmd
9+
COPY internal internal
10+
11+
VOLUME /test-results
12+
13+
ENTRYPOINT go test -coverprofile=/test-results/coverage.out ./internal/... ./cmd/... && \
14+
go tool cover -func=/test-results/coverage.out > /test-results/function-wise-coverage.txt && \
15+
cat /test-results/function-wise-coverage.txt | awk 'END{print $NF}' > /test-results/totalcoverage.txt && \
16+
go tool cover -html=/test-results/coverage.out -o=/test-results/coverage.html && \
17+
GO111MODULE=on CGO_ENABLED=0 golangci-lint run -c ./.golangci.yaml ./cmd/... ./internal/...

Jenkinsfile

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
@Library('jenkins-shared-libs@master') _
2+
3+
olympus_ci(
4+
// testImage is a Docker image that will be built and run as a test. It
5+
// is not pushed anywhere as part of the build
6+
testImage: "Dockerfile",
7+
)

Makefile

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Copyright © 2021 VMware, Inc. All Rights Reserved.
2+
# SPDX-License-Identifier: MPL-2.0
3+
4+
default: build
5+
6+
build:
7+
go build -o bin/terraform-provider-tmc ./cmd/main.go
8+
mkdir -p ~/.terraform.d/plugins/vmware/tanzu/tmc/0.1.1/darwin_amd64/
9+
cp bin/terraform-provider-tmc ~/.terraform.d/plugins/vmware/tanzu/tmc/0.1.1/darwin_amd64/
10+
11+
test: | gofmt vet lint
12+
go mod tidy
13+
go test ./internal/... ./cmd/... -cover
14+
15+
# Run go fmt against code
16+
gofmt:
17+
@echo Checking code is gofmted
18+
go fmt ./...
19+
20+
# Run go vet against code
21+
vet:
22+
go vet ./...
23+
24+
# Linter
25+
lint: gofmt
26+
golangci-lint run -c ./.golangci.yaml ./cmd/... ./internal/...

README.md

+28-18
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,39 @@
1+
# terraform-provider-tanzu
12

2-
# terraform-provider-tanzu-mission-control
3+
A custom provider for terraform CLI tool to manage TANZU resources.
34

4-
## Overview
5+
// usage/playgo (link to examples)
6+
# Use Cases of TMC Terraform Provider
7+
[use-cases]: https://gitlab.eng.vmware.com/olympus/terraform-provider-tanzu/examples
58

6-
## Try it out
9+
# Manual Installation
710

8-
### Prerequisites
11+
## Cloning the Project
912

10-
* Prereq 1
11-
* Prereq 2
12-
* Prereq 3
13+
First, you will want to clone the repository to
14+
`gitlab.eng.vmware.com/olympus/terraform-provider-tanzu`:
1315

14-
### Build & Run
16+
```sh
17+
mkdir -p $GOPATH/src/gitlab.eng.vmware.com/olympus/terraform-provider-tanzu
18+
cd $GOPATH/src/gitlab.eng.vmware.com/olympus/terraform-provider-tanzu
19+
git clone git@gitlab.eng.vmware.com:olympus/terraform-provider-tanzu.git
20+
```
1521

16-
1. Step 1
17-
2. Step 2
18-
3. Step 3
22+
## Building and Installing the Provider
1923

20-
## Documentation
24+
Recommended golang version is go1.14 onwards.
25+
After the clone has been completed, you can enter the provider directory and build the provider.
2126

22-
## Contributing
27+
```sh
28+
cd gitlab.eng.vmware.com/olympus/terraform-provider-tanzu
29+
make
30+
```
2331

24-
The terraform-provider-tanzu-mission-control project team welcomes contributions from the community. Before you start working with terraform-provider-tanzu-mission-control, please
25-
read our [Developer Certificate of Origin](https://cla.vmware.com/dco). All contributions to this repository must be
26-
signed as described on that page. Your signature certifies that you wrote the patch or have the right to pass it on
27-
as an open-source patch. For more detailed information, refer to [CONTRIBUTING.md](CONTRIBUTING.md).
32+
After the build is complete, copy the provider executable `terraform-provider-tanzu` into location specified in your provider installation configuration. Make sure to delete provider lock files that might exist in your working directory due to prior provider usage. Run `terraform init`.
33+
For developing, consider using [dev overrides configuration][dev-overrides]. Please note that `terraform init` should not be used with dev overrides.
2834

29-
## License
35+
[dev-overrides]: https://www.terraform.io/docs/cli/config/config-file.html#development-overrides-for-provider-developers
36+
37+
## Utilising TMC provider
38+
39+
Please refer to `examples` folder to perform CRUD operations with TMC provider for various resources

cmd/main.go

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/*
2+
Copyright © 2021 VMware, Inc. All Rights Reserved.
3+
SPDX-License-Identifier: MPL-2.0
4+
*/
5+
6+
package main
7+
8+
import (
9+
"github.com/hashicorp/terraform-plugin-sdk/v2/plugin"
10+
11+
"gitlab.eng.vmware.com/olympus/terraform-provider-tanzu/internal/provider"
12+
)
13+
14+
func main() {
15+
plugin.Serve(&plugin.ServeOpts{
16+
ProviderFunc: provider.Provider,
17+
})
18+
}
+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
terraform {
2+
required_providers {
3+
tmc = {
4+
source = "vmware/tanzu/tmc"
5+
}
6+
}
7+
}
8+
9+
// Read TMC cluster : fetch cluster details
10+
data "tmc_cluster" "ready_only_attach_cluster_view" {
11+
management_cluster_name = "attached" // Default: attached
12+
provisioner_name = "attached" // Default: attached
13+
name = "terraform-test" // Required
14+
}
15+
16+
// Create TMC attach cluster entry
17+
resource "tmc_cluster" "attach_cluster_without_apply" {
18+
management_cluster_name = "attached" // Default: attached
19+
provisioner_name = "attached" // Default: attached
20+
name = "terraform-attach" // Required
21+
22+
meta {
23+
description = "create attach cluster from terraform"
24+
labels = { "key" : "value" }
25+
}
26+
27+
spec {
28+
cluster_group = "default" // Default: default
29+
}
30+
31+
wait_until_ready = false
32+
}
33+
34+
output "attach_output" {
35+
value = tmc_cluster.attach_cluster_without_apply
36+
}
+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
terraform {
2+
required_providers {
3+
tmc = {
4+
source = "vmware/tanzu/tmc"
5+
}
6+
}
7+
}
8+
9+
// Create cluster group
10+
resource "tmc_cluster_group" "create_cluster_group" {
11+
name = "tf-cluster-group"
12+
meta {
13+
description = "Create cluster group through terraform"
14+
labels = {
15+
"key1" : "value1",
16+
"key2" : "value2"
17+
}
18+
}
19+
}
20+
21+
// Create cluster group with minimal information
22+
resource "tmc_cluster_group" "create_cluster_group_min_info" {
23+
name = "tf-cluster-group-min-info"
24+
}
25+
26+
// Read TMC cluster group
27+
data "tmc_cluster_group" "read_cluster_group" {
28+
name = "default"
29+
}
30+
31+
// Output cluster group resource
32+
output "cluster_group" {
33+
value = tmc_cluster_group.create_cluster_group
34+
}
35+
36+
output "cluster_group_min_info" {
37+
value = tmc_cluster_group.create_cluster_group_min_info
38+
}
39+
40+
output "display_cluster_group" {
41+
value = data.tmc_cluster_group.read_cluster_group
42+
}

examples/namespace/namespace.tf

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
terraform {
2+
required_providers {
3+
tmc = {
4+
source = "vmware/tanzu/tmc"
5+
}
6+
}
7+
}
8+
// Create namespace with attached set as default value.
9+
resource "tmc_namespace" "create_namespace" {
10+
name = "tf-namespace" // Required
11+
cluster_name = "testcluster" // Required
12+
provisioner_name = "attached" // Default: attached
13+
management_cluster_name = "attached" // Default: attached
14+
15+
meta {
16+
description = "Create namespace through terraform"
17+
labels = { "key" : "value" }
18+
}
19+
20+
spec {
21+
workspace_name = "default" // Default: default
22+
attach = false // Default: false
23+
}
24+
}
25+
26+
// Create namespace with attached set as 'true'
27+
resource "tmc_namespace" "create_namespace_attached" {
28+
name = "tf-namespace" // Required
29+
cluster_name = "testcluster" // Required
30+
provisioner_name = "attached" // Default: attached
31+
management_cluster_name = "attached" // Default: attached
32+
33+
meta {
34+
description = "Create namespace through terraform"
35+
labels = { "key" : "value" }
36+
}
37+
38+
spec {
39+
workspace_name = "default" // Default: default
40+
attach = true
41+
}
42+
}
43+
// Read TMC namespace : fetch namespace details
44+
data "tmc_namespace" "read_namespace" {
45+
name = "tf-namespace" // Required
46+
cluster_name = "testcluster" // Required
47+
management_cluster_name = "attached" // Default: attached
48+
provisioner_name = "attached" // Default: attached
49+
}
50+
51+
// Output namespace resource
52+
output "namespace" {
53+
value = tmc_namespace.create_namespace
54+
}
55+
// Get namespace resource
56+
output "display_namespace" {
57+
value = data.tmc_namespace.read_namespace
58+
}

0 commit comments

Comments
 (0)