Skip to content

Commit aaf4411

Browse files
authored
Copy terraform-validator code over and remove dependency to terraform-validator (#811)
1 parent f9f9761 commit aaf4411

File tree

768 files changed

+151062
-558
lines changed

Some content is hidden

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

768 files changed

+151062
-558
lines changed

Makefile

+14-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,16 @@
11
test:
2-
GO111MODULE=on go test ./...
2+
GO111MODULE=on go test -short ./...
33

4-
.PHONY: test
4+
test-integration:
5+
go version
6+
terraform --version
7+
go test -run=CLI ./...
8+
9+
test-go-licenses:
10+
cd .. && go version && go install github.com/google/go-licenses@latest
11+
$$(go env GOPATH)/bin/go-licenses check ./...
12+
13+
run-docker:
14+
docker run -it -v `pwd`:/terraform-validator -v ${GOOGLE_APPLICATION_CREDENTIALS}:/terraform-validator/credentials.json --entrypoint=/bin/bash --env TEST_PROJECT=${PROJECT_ID} --env TEST_CREDENTIALS=./credentials.json terraform-validator;
15+
16+
.PHONY: test test-integration test-go-licenses

caiasset/asset.go

+89-7
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,95 @@
11
package caiasset
22

33
import (
4-
"github.com/GoogleCloudPlatform/terraform-validator/converters/google"
4+
"fmt"
5+
"strings"
6+
"time"
57
)
68

7-
// Asset represents a CAI Asset.
8-
// In the long run, this will be defined in this package; for now,
9-
// re-export the Asset type from terraform-validator.
10-
type Asset = google.Asset
9+
// Asset is the CAI representation of a resource.
10+
type Asset struct {
11+
// The name, in a peculiar format: `\\<api>.googleapis.com/<self_link>`
12+
Name string `json:"name"`
13+
// The type name in `google.<api>.<resourcename>` format.
14+
Type string `json:"asset_type"`
15+
Resource *AssetResource `json:"resource,omitempty"`
16+
IAMPolicy *IAMPolicy `json:"iam_policy,omitempty"`
17+
OrgPolicy []*OrgPolicy `json:"org_policy,omitempty"`
18+
Ancestors []string `json:"ancestors"`
19+
}
1120

12-
// AssetResource represents a CAI AssetResource.
13-
type AssetResource = google.AssetResource
21+
// IAMPolicy is the representation of a Cloud IAM policy set on a cloud resource.
22+
type IAMPolicy struct {
23+
Bindings []IAMBinding `json:"bindings"`
24+
}
25+
26+
// IAMBinding binds a role to a set of members.
27+
type IAMBinding struct {
28+
Role string `json:"role"`
29+
Members []string `json:"members"`
30+
}
31+
32+
// AssetResource is nested within the Asset type.
33+
type AssetResource struct {
34+
Version string `json:"version"`
35+
DiscoveryDocumentURI string `json:"discovery_document_uri"`
36+
DiscoveryName string `json:"discovery_name"`
37+
Parent string `json:"parent"`
38+
Data map[string]interface{} `json:"data"`
39+
}
40+
41+
// OrgPolicy is for managing organization policies.
42+
type OrgPolicy struct {
43+
Constraint string `json:"constraint,omitempty"`
44+
ListPolicy *ListPolicy `json:"list_policy,omitempty"`
45+
BooleanPolicy *BooleanPolicy `json:"boolean_policy,omitempty"`
46+
RestoreDefault *RestoreDefault `json:"restore_default,omitempty"`
47+
UpdateTime *Timestamp `json:"update_time,omitempty"`
48+
}
49+
50+
type Timestamp struct {
51+
Seconds int64 `json:"seconds,omitempty"`
52+
Nanos int64 `json:"nanos,omitempty"`
53+
}
54+
55+
func (t Timestamp) MarshalJSON() ([]byte, error) {
56+
return []byte(`"` + time.Unix(0, t.Nanos).UTC().Format(time.RFC3339Nano) + `"`), nil
57+
}
58+
59+
func (t *Timestamp) UnmarshalJSON(b []byte) error {
60+
p, err := time.Parse(time.RFC3339Nano, strings.Trim(string(b), `"`))
61+
if err != nil {
62+
return fmt.Errorf("bad Timestamp: %v", err)
63+
}
64+
t.Seconds = p.Unix()
65+
t.Nanos = p.UnixNano()
66+
return nil
67+
}
68+
69+
// ListPolicyAllValues is used to set `Policies` that apply to all possible
70+
// configuration values rather than specific values in `allowed_values` or
71+
// `denied_values`.
72+
type ListPolicyAllValues int32
73+
74+
// ListPolicy can define specific values and subtrees of Cloud Resource
75+
// Manager resource hierarchy (`Organizations`, `Folders`, `Projects`) that
76+
// are allowed or denied by setting the `allowed_values` and `denied_values`
77+
// fields.
78+
type ListPolicy struct {
79+
AllowedValues []string `json:"allowed_values,omitempty"`
80+
DeniedValues []string `json:"denied_values,omitempty"`
81+
AllValues ListPolicyAllValues `json:"all_values,omitempty"`
82+
SuggestedValue string `json:"suggested_value,omitempty"`
83+
InheritFromParent bool `json:"inherit_from_parent,omitempty"`
84+
}
85+
86+
// BooleanPolicy If `true`, then the `Policy` is enforced. If `false`,
87+
// then any configuration is acceptable.
88+
type BooleanPolicy struct {
89+
Enforced bool `json:"enforced,omitempty"`
90+
}
91+
92+
// RestoreDefault determines if the default values of the `Constraints` are active for the
93+
// resources.
94+
type RestoreDefault struct {
95+
}

go.mod

+38-36
Original file line numberDiff line numberDiff line change
@@ -3,35 +3,47 @@ module github.com/GoogleCloudPlatform/terraform-google-conversion/v2
33
go 1.18
44

55
require (
6-
github.com/GoogleCloudPlatform/terraform-validator v0.19.0
7-
github.com/google/go-cmp v0.5.8
6+
cloud.google.com/go/bigtable v1.17.0
7+
github.com/apparentlymart/go-cidr v1.1.0
8+
github.com/davecgh/go-spew v1.1.1
9+
github.com/google/go-cmp v0.5.9
10+
github.com/grpc-ecosystem/go-grpc-middleware v1.3.0
11+
github.com/hashicorp/errwrap v1.0.0
12+
github.com/hashicorp/go-cleanhttp v0.5.2
813
github.com/hashicorp/go-cty v1.4.1-0.20200414143053-d3edf31b6320
914
github.com/hashicorp/hcl v1.0.0
10-
github.com/hashicorp/hcl/v2 v2.13.0
11-
github.com/hashicorp/terraform-plugin-sdk/v2 v2.18.0
12-
github.com/hashicorp/terraform-provider-google v1.20.1-0.20220926153800-e1b202c49347
13-
github.com/stretchr/testify v1.7.2
14-
github.com/zclconf/go-cty v1.10.0
15+
github.com/hashicorp/hcl/v2 v2.14.1
16+
github.com/hashicorp/terraform-json v0.14.0
17+
github.com/hashicorp/terraform-plugin-sdk/v2 v2.24.0
18+
github.com/hashicorp/terraform-provider-google v1.20.1-0.20221222182143-d5c0cb231df7
19+
github.com/mitchellh/go-homedir v1.1.0
20+
github.com/pkg/errors v0.9.1
21+
github.com/sirupsen/logrus v1.8.1
22+
github.com/stretchr/testify v1.8.1
23+
github.com/zclconf/go-cty v1.11.0
1524
go.uber.org/zap v1.21.0
16-
google.golang.org/api v0.92.0
25+
golang.org/x/oauth2 v0.0.0-20221014153046-6fdb5e3db783
26+
google.golang.org/api v0.103.0
27+
google.golang.org/genproto v0.0.0-20221027153422-115e99e71e1c
28+
google.golang.org/grpc v1.50.1
1729
)
1830

1931
require (
2032
bitbucket.org/creachadair/stringset v0.0.8 // indirect
21-
cloud.google.com/go v0.102.1 // indirect
22-
cloud.google.com/go/bigtable v1.16.0 // indirect
23-
cloud.google.com/go/compute v1.7.0 // indirect
24-
cloud.google.com/go/iam v0.3.0 // indirect
25-
github.com/GoogleCloudPlatform/declarative-resource-client-library v1.21.1 // indirect
33+
cloud.google.com/go v0.105.0 // indirect
34+
cloud.google.com/go/compute v1.12.1 // indirect
35+
cloud.google.com/go/compute/metadata v0.2.1 // indirect
36+
cloud.google.com/go/iam v0.6.0 // indirect
37+
cloud.google.com/go/longrunning v0.1.1 // indirect
38+
github.com/GoogleCloudPlatform/declarative-resource-client-library v1.28.0 // indirect
2639
github.com/agext/levenshtein v1.2.2 // indirect
27-
github.com/apparentlymart/go-cidr v1.1.0 // indirect
2840
github.com/apparentlymart/go-textseg/v13 v13.0.0 // indirect
41+
github.com/benbjohnson/clock v1.1.0 // indirect
2942
github.com/cenkalti/backoff v2.2.1+incompatible // indirect
3043
github.com/census-instrumentation/opencensus-proto v0.3.0 // indirect
3144
github.com/cespare/xxhash/v2 v2.1.2 // indirect
3245
github.com/cncf/udpa/go v0.0.0-20210930031921-04548b0d99d4 // indirect
3346
github.com/cncf/xds/go v0.0.0-20211130200136-a8f946100490 // indirect
34-
github.com/davecgh/go-spew v1.1.1 // indirect
3547
github.com/envoyproxy/go-control-plane v0.10.2-0.20220325020618-49ff273808a1 // indirect
3648
github.com/envoyproxy/protoc-gen-validate v0.6.2 // indirect
3749
github.com/fatih/color v1.13.0 // indirect
@@ -42,55 +54,45 @@ require (
4254
github.com/golang/protobuf v1.5.2 // indirect
4355
github.com/google/go-cpy v0.0.0-20211218193943-a9c933c06932 // indirect
4456
github.com/google/uuid v1.3.0 // indirect
45-
github.com/googleapis/enterprise-certificate-proxy v0.1.0 // indirect
46-
github.com/googleapis/gax-go/v2 v2.4.0 // indirect
47-
github.com/grpc-ecosystem/go-grpc-middleware v1.3.0 // indirect
48-
github.com/hashicorp/errwrap v1.0.0 // indirect
57+
github.com/googleapis/enterprise-certificate-proxy v0.2.0 // indirect
58+
github.com/googleapis/gax-go/v2 v2.7.0 // indirect
4959
github.com/hashicorp/go-checkpoint v0.5.0 // indirect
50-
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
5160
github.com/hashicorp/go-hclog v1.2.1 // indirect
5261
github.com/hashicorp/go-multierror v1.1.1 // indirect
5362
github.com/hashicorp/go-plugin v1.4.4 // indirect
5463
github.com/hashicorp/go-uuid v1.0.3 // indirect
5564
github.com/hashicorp/go-version v1.6.0 // indirect
5665
github.com/hashicorp/hc-install v0.4.0 // indirect
5766
github.com/hashicorp/logutils v1.0.0 // indirect
58-
github.com/hashicorp/terraform-exec v0.17.2 // indirect
59-
github.com/hashicorp/terraform-json v0.14.0 // indirect
60-
github.com/hashicorp/terraform-plugin-go v0.10.0 // indirect
61-
github.com/hashicorp/terraform-plugin-log v0.4.1 // indirect
67+
github.com/hashicorp/terraform-exec v0.17.3 // indirect
68+
github.com/hashicorp/terraform-plugin-go v0.14.0 // indirect
69+
github.com/hashicorp/terraform-plugin-log v0.7.0 // indirect
6270
github.com/hashicorp/terraform-registry-address v0.0.0-20220623143253-7d51757b572c // indirect
6371
github.com/hashicorp/terraform-svchost v0.0.0-20200729002733-f050f53b9734 // indirect
6472
github.com/hashicorp/yamux v0.0.0-20181012175058-2f1d1f20f75d // indirect
6573
github.com/kylelemons/godebug v1.1.0 // indirect
6674
github.com/mattn/go-colorable v0.1.12 // indirect
6775
github.com/mattn/go-isatty v0.0.14 // indirect
6876
github.com/mitchellh/copystructure v1.2.0 // indirect
69-
github.com/mitchellh/go-homedir v1.1.0 // indirect
7077
github.com/mitchellh/go-testing-interface v1.14.1 // indirect
7178
github.com/mitchellh/go-wordwrap v1.0.0 // indirect
7279
github.com/mitchellh/hashstructure v1.1.0 // indirect
7380
github.com/mitchellh/mapstructure v1.5.0 // indirect
7481
github.com/mitchellh/reflectwalk v1.0.2 // indirect
7582
github.com/oklog/run v1.0.0 // indirect
76-
github.com/pkg/errors v0.9.1 // indirect
7783
github.com/pmezard/go-difflib v1.0.0 // indirect
78-
github.com/sirupsen/logrus v1.8.1 // indirect
7984
github.com/vmihailenco/msgpack v4.0.4+incompatible // indirect
8085
github.com/vmihailenco/msgpack/v4 v4.3.12 // indirect
8186
github.com/vmihailenco/tagparser v0.1.1 // indirect
82-
go.opencensus.io v0.23.0 // indirect
87+
go.opencensus.io v0.24.0 // indirect
8388
go.uber.org/atomic v1.9.0 // indirect
8489
go.uber.org/multierr v1.7.0 // indirect
8590
golang.org/x/crypto v0.0.0-20220517005047-85d78b3ac167 // indirect
86-
golang.org/x/net v0.0.0-20220624214902-1bab6f366d9e // indirect
87-
golang.org/x/oauth2 v0.0.0-20220622183110-fd043fe589d2 // indirect
88-
golang.org/x/sys v0.0.0-20220624220833-87e55d714810 // indirect
89-
golang.org/x/text v0.3.7 // indirect
90-
golang.org/x/xerrors v0.0.0-20220609144429-65e65417b02f // indirect
91+
golang.org/x/net v0.0.0-20221014081412-f15817d10f9b // indirect
92+
golang.org/x/sys v0.0.0-20220728004956-3c1f35247d10 // indirect
93+
golang.org/x/text v0.4.0 // indirect
94+
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect
9195
google.golang.org/appengine v1.6.7 // indirect
92-
google.golang.org/genproto v0.0.0-20220725144611-272f38e5d71b // indirect
93-
google.golang.org/grpc v1.48.0 // indirect
94-
google.golang.org/protobuf v1.28.0 // indirect
96+
google.golang.org/protobuf v1.28.1 // indirect
9597
gopkg.in/yaml.v3 v3.0.1 // indirect
9698
)

0 commit comments

Comments
 (0)