Skip to content

Commit

Permalink
merged to main
Browse files Browse the repository at this point in the history
  • Loading branch information
AmitChotaliya committed Apr 10, 2021
2 parents 98e899b + b0e6fcd commit b637bfb
Show file tree
Hide file tree
Showing 16 changed files with 1,327 additions and 2 deletions.
52 changes: 52 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
.DS_Store
terraform-provider-hashicups
bin

# Created by https://www.toptal.com/developers/gitignore/api/go,terraform
# Edit at https://www.toptal.com/developers/gitignore?templates=go,terraform

### Go ###
# Binaries for programs and plugins
*.exe
*.exe~
Expand All @@ -13,3 +21,47 @@

# Dependency directories (remove the comment below to include it)
# vendor/

### Go Patch ###
/vendor/
/Godeps/

### Terraform ###
# Local .terraform directories
**/.terraform/*

# .tfstate files
*.tfstate
*.tfstate.*

# Crash log files
crash.log

# Ignore any .tfvars files that are generated automatically for each Terraform run. Most
# .tfvars files are managed as part of configuration and so should be included in
# version control.
#
# example.tfvars

# Ignore override files as they are usually used to override resources locally and so
# are not checked in
override.tf
override.tf.json
*_override.tf
*_override.tf.json

# Include override files you do wish to add to version control using negated pattern
# !example_override.tf

# Include tfplan files to ignore the plan output of command: terraform plan -out=tfplan
# example: *tfplan*

# End of https://www.toptal.com/developers/gitignore/api/go,terraform

# Ignore CLI configuration files
.terraformrc
terraform.rc
terraform
examples/.terraform.lock.hcl
examples/.terraform.lock.hcl-e
.idea
38 changes: 38 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
TEST?=$$(go list ./... | grep -v 'vendor')
HOSTNAME=trendmicro.com
NAMESPACE=cloudone
NAME=conformity
BINARY=terraform-provider-${NAME}
VERSION=0.3
OS_ARCH=darwin_amd64

default: install

build:
go build -o ${BINARY}

release:
GOOS=darwin GOARCH=amd64 go build -o ./bin/${BINARY}_${VERSION}_darwin_amd64
GOOS=freebsd GOARCH=386 go build -o ./bin/${BINARY}_${VERSION}_freebsd_386
GOOS=freebsd GOARCH=amd64 go build -o ./bin/${BINARY}_${VERSION}_freebsd_amd64
GOOS=freebsd GOARCH=arm go build -o ./bin/${BINARY}_${VERSION}_freebsd_arm
GOOS=linux GOARCH=386 go build -o ./bin/${BINARY}_${VERSION}_linux_386
GOOS=linux GOARCH=amd64 go build -o ./bin/${BINARY}_${VERSION}_linux_amd64
GOOS=linux GOARCH=arm go build -o ./bin/${BINARY}_${VERSION}_linux_arm
GOOS=openbsd GOARCH=386 go build -o ./bin/${BINARY}_${VERSION}_openbsd_386
GOOS=openbsd GOARCH=amd64 go build -o ./bin/${BINARY}_${VERSION}_openbsd_amd64
GOOS=solaris GOARCH=amd64 go build -o ./bin/${BINARY}_${VERSION}_solaris_amd64
GOOS=windows GOARCH=386 go build -o ./bin/${BINARY}_${VERSION}_windows_386
GOOS=windows GOARCH=amd64 go build -o ./bin/${BINARY}_${VERSION}_windows_amd64

install: build
mkdir -p ~/.terraform.d/plugins/${HOSTNAME}/${NAMESPACE}/${NAME}/${VERSION}/${OS_ARCH}
mv ${BINARY} ~/.terraform.d/plugins/${HOSTNAME}/${NAMESPACE}/${NAME}/${VERSION}/${OS_ARCH}
sed -i -e '/hashes/,/]/d' examples/.terraform.lock.hcl

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

testacc:
TF_ACC=1 go test $(TEST) -v $(TESTARGS) -timeout 120m
23 changes: 21 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,21 @@
# conformity-tf-provider
Terraform provider for conformity
# Terraform Provider Hashicups

Run the following command to build the provider

```shell
go build -o terraform-provider-hashicups
```

## Test sample configuration

First, build and install the provider.

```shell
make install
```

Then, run the following command to initialize the workspace and apply the sample configuration.

```shell
terraform init && terraform apply
```
101 changes: 101 additions & 0 deletions conformity/groups/data_source_group.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
package groups

import (
"context"
"log"
"strconv"
"terraform-provider-conformity/conformity/models"
"time"

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

func DataSourceGroups() *schema.Resource {
return &schema.Resource{
ReadContext: dataSourceGroupsRead,
Schema: map[string]*schema.Schema{
"groups": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"id": {
Type: schema.TypeString,
Computed: true,
},
"type": {
Type: schema.TypeString,
Computed: true,
},
"attributes_tags": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"attributes_name": {
Type: schema.TypeString,
Computed: true,
},
"attributes_created_date": {
Type: schema.TypeFloat,
Computed: true,
},
"attributes_last_modified_date": {
Type: schema.TypeFloat,
Computed: true,
},
"relationships_organisation_data_type": {
Type: schema.TypeString,
Optional: true,
},
"relationships_organisation_data_id": {
Type: schema.TypeString,
Optional: true,
},
"relationships_accounts_data": {
Type: schema.TypeList,
Optional: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"type": {
Type: schema.TypeString,
Required: true,
},
"id": {
Type: schema.TypeString,
Required: true,
},
},
},
},
},
},
},
},
}
}

func dataSourceGroupsRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
log.Println("[DEBUG] Something happened twice!")
provider := m.(models.ProviderClient)
client := provider.Client
var diags diag.Diagnostics
gs := GetGroupService(client)
groups, err := gs.DoGetGroups(client.BaseUrl.String())
log.Printf("Raw output2: %v\n", groups)
if err != nil {
return diag.FromErr(err)
}

if err := d.Set("groups", groups); err != nil {
return diag.FromErr(err)
}

// always run
d.SetId(strconv.FormatInt(time.Now().Unix(), 10))

return diags
}
Loading

0 comments on commit b637bfb

Please sign in to comment.