Skip to content

Commit

Permalink
inital codes
Browse files Browse the repository at this point in the history
  • Loading branch information
niuzhenguo committed May 4, 2023
0 parents commit f5c6677
Show file tree
Hide file tree
Showing 6 changed files with 217 additions and 0 deletions.
39 changes: 39 additions & 0 deletions GNUmakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
TEST?=$$(go list ./... |grep -v 'vendor')
TEST_PARALLELISM?=4
GOFMT_FILES?=$$(find . -name '*.go' |grep -v vendor)
PKG_NAME=cors

default: build

build:
go install $(FLAGS)

test:
go test -i $(TEST) || exit 1
echo $(TEST) | \
xargs -t -n4 go test $(TESTARGS) -timeout=30s -parallel=$(TEST_PARALLELISM)

testacc:
TF_ACC=1 go test $(TEST) -v $(TESTARGS) -timeout 360m -parallel $(TEST_PARALLELISM)

vet:
@echo "go vet ."
@go vet $$(go list ./... | grep -v vendor/) ; if [ $$? -eq 1 ]; then \
echo ""; \
echo "Vet found suspicious constructs. Please check the reported constructs"; \
echo "and fix them if necessary before submitting the code for review."; \
exit 1; \
fi

fmt:
gofmt -w $(GOFMT_FILES)

test-compile:
@if [ "$(TEST)" = "./..." ]; then \
echo "ERROR: Set TEST to a specific package. For example,"; \
echo " make test-compile TEST=./$(PKG_NAME)"; \
exit 1; \
fi
go test -c $(TEST) $(TESTARGS)

.PHONY: build test testacc vet fmt test-compile
78 changes: 78 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
Terraform HuaweiCloud Provider
==============================

<!-- markdownlint-disable-next-line MD034 -->
* Website: https://www.terraform.io
* [![Documentation](https://img.shields.io/badge/documentation-blue)](https://registry.terraform.io/providers/huaweicloud/huaweicloud/latest/docs)
* [![Gitter chat](https://badges.gitter.im/hashicorp-terraform/Lobby.png)](https://gitter.im/hashicorp-terraform/Lobby)
* Mailing list: [Google Groups](http://groups.google.com/group/terraform-tool)

<!-- markdownlint-disable-next-line MD033 -->
<a href="https://www.huaweicloud.com/"><img width="450px" height="102px" src="https://console-static.huaweicloud.com/static/authui/20210202115135/public/custom/images/logo-en.svg"></a>

Requirements
------------

* [Terraform](https://www.terraform.io/downloads.html) 0.12.x
* [Go](https://golang.org/doc/install) 1.18 (to build the provider plugin)

Building The Provider
---------------------

Clone repository to: `$GOPATH/src/github.com/huaweicloud/terraform-provider-huaweicloud`

```sh
$ mkdir -p $GOPATH/src/github.com/huaweicloud; cd $GOPATH/src/github.com/huaweicloud
$ git clone https://github.com/huaweicloud/terraform-provider-huaweicloud
```

Enter the provider directory and build the provider

```sh
$ cd $GOPATH/src/github.com/huaweicloud/terraform-provider-huaweicloud
$ make build
```

Using the provider
------------------

Please see the documentation at [provider usage](docs/index.md).

Or you can browse the documentation within this repo [here](https://github.com/huaweicloud/terraform-provider-huaweicloud/tree/master/docs).

Developing the Provider
-----------------------

If you wish to work on the provider, you'll first need [Go](http://www.golang.org) installed
on your machine (version 1.14+ is *required*).
You'll also need to correctly setup a [GOPATH](http://golang.org/doc/code.html#GOPATH),
as well as adding `$GOPATH/bin` to your `$PATH`.

To compile the provider, run `make build`.
This will build the provider and put the provider binary in the `$GOPATH/bin` directory.

```sh
$ make build
...
$ $GOPATH/bin/terraform-provider-huaweicloud
...
```

In order to test the provider, you can simply run `make test`.

```sh
$ make test
```

In order to run the full suite of Acceptance tests, run `make testacc`.

*Note:* Acceptance tests create real resources, and often cost money to run.

```sh
$ make testacc
```

License
-------

Terraform-Provider-Huaweicloud is under the Mozilla Public License 2.0. See the [LICENSE](LICENSE) file for details.
9 changes: 9 additions & 0 deletions cors/config/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package config

type Config struct {
Region string
DomainID string
DomainID string
DomainID string
MaxRetries int
}
71 changes: 71 additions & 0 deletions cors/provider.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package cors

import (
"context"

"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"

"github.com/chnsz/terraform-provider-cors/cors/config/config"
//"github.com/chnsz/terraform-provider-cors/cors/services/cbr"
)

// Provider returns a schema.Provider for CORS.
func Provider() *schema.Provider {
provider := &schema.Provider{
Schema: map[string]*schema.Schema{
"region": {
Type: schema.TypeString,
Required: true,
DefaultFunc: schema.EnvDefaultFunc("CORS_REGION", nil),
},

"domain_id": {
Type: schema.TypeString,
Required: true,
DefaultFunc: schema.EnvDefaultFunc("CORS_DOMAIN_ID", nil),
},

"project_id": {
Type: schema.TypeString,
Required: true,
DefaultFunc: schema.EnvDefaultFunc("CORS_PROJECT_ID", nil),
},

"app_code": {
Type: schema.TypeString,
Required: true,
DefaultFunc: schema.EnvDefaultFunc("CORS_APP_CODE", nil),
},

"max_retries": {
Type: schema.TypeInt,
Optional: true,
DefaultFunc: schema.EnvDefaultFunc("CORS_MAX_RETRIES", 5),
},
},

DataSourcesMap: map[string]*schema.Resource{
//"huaweicloud_cbr_vaults": cbr.DataSourceCbrVaults(),
},

ResourcesMap: map[string]*schema.Resource{
//"huaweicloud_cbr_vault": cbr.ResourceCbrVault(),
},
ConfigureContextFunc = configProvider
}

return provider
}

func configProvider(_ context.Context, d *schema.ResourceData) (interface{}, diag.Diagnostics) {
config := config.Config{
Region: d.Get("region").(string),
DomainID: d.Get("domain_id").(string),
ProjectID: d.Get("project_id").(string),
AppCode: d.Get("app_code").(string),
MaxRetries: d.Get("max_retries").(int),
}

return &config, nil
}
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module github.com/chnsz/terraform-provider-cors

go 1.19
17 changes: 17 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package main

import (
"log"

"github.com/hashicorp/terraform-plugin-sdk/v2/plugin"
"github.com/chnsz/terraform-provider-cors/cors"
)

func main() {
// Remove any date and time prefix in log package function output to
// prevent duplicate timestamp and incorrect log level setting
log.SetFlags(log.Flags() &^ (log.Ldate | log.Ltime))

plugin.Serve(&plugin.ServeOpts{
ProviderFunc: cors.Provider})
}

0 comments on commit f5c6677

Please sign in to comment.