Skip to content

Commit 2f4b7a8

Browse files
authored
tgc: move caiasset folder to the management of magic-modules (#14862)
1 parent 80031d2 commit 2f4b7a8

File tree

2 files changed

+133
-0
lines changed

2 files changed

+133
-0
lines changed

mmv1/provider/terraform_tgc.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,7 @@ func (tgc TerraformGoogleConversion) CopyCommonFiles(outputFolder string, genera
354354
tgc.CopyFileList(outputFolder, retrieveTestSourceCodeWithLocation(".go"))
355355

356356
resourceConverters := map[string]string{
357+
"../caiasset/asset.go": "third_party/tgc/caiasset/asset.go",
357358
"converters/google/resources/cai/constants.go": "third_party/tgc/cai/constants.go",
358359
"converters/google/resources/constants.go": "third_party/tgc/constants.go",
359360
"converters/google/resources/cai.go": "third_party/tgc/cai.go",
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
package caiasset
2+
3+
import (
4+
"fmt"
5+
"strings"
6+
"time"
7+
)
8+
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+
V2OrgPolicies []*V2OrgPolicies `json:"v2_org_policies,omitempty"`
19+
Ancestors []string `json:"ancestors"`
20+
}
21+
22+
// IAMPolicy is the representation of a Cloud IAM policy set on a cloud resource.
23+
type IAMPolicy struct {
24+
Bindings []IAMBinding `json:"bindings"`
25+
}
26+
27+
// IAMBinding binds a role to a set of members.
28+
type IAMBinding struct {
29+
Role string `json:"role"`
30+
Members []string `json:"members"`
31+
}
32+
33+
// AssetResource is nested within the Asset type.
34+
type AssetResource struct {
35+
Version string `json:"version"`
36+
DiscoveryDocumentURI string `json:"discovery_document_uri"`
37+
DiscoveryName string `json:"discovery_name"`
38+
Parent string `json:"parent"`
39+
Data map[string]interface{} `json:"data"`
40+
Location string `json:"location,omitempty"`
41+
}
42+
43+
// OrgPolicy is for managing organization policies.
44+
type OrgPolicy struct {
45+
Constraint string `json:"constraint,omitempty"`
46+
ListPolicy *ListPolicy `json:"list_policy,omitempty"`
47+
BooleanPolicy *BooleanPolicy `json:"boolean_policy,omitempty"`
48+
RestoreDefault *RestoreDefault `json:"restore_default,omitempty"`
49+
UpdateTime *Timestamp `json:"update_time,omitempty"`
50+
}
51+
52+
// V2OrgPolicies is the represtation of V2OrgPolicies
53+
type V2OrgPolicies struct {
54+
Name string `json:"name"`
55+
PolicySpec *PolicySpec `json:"spec,omitempty"`
56+
}
57+
58+
// Spec is the representation of Spec for Custom Org Policy
59+
type PolicySpec struct {
60+
Etag string `json:"etag,omitempty"`
61+
UpdateTime *Timestamp `json:"update_time,omitempty"`
62+
PolicyRules []*PolicyRule `json:"rules,omitempty"`
63+
InheritFromParent bool `json:"inherit_from_parent,omitempty"`
64+
Reset bool `json:"reset,omitempty"`
65+
}
66+
67+
type PolicyRule struct {
68+
Values *StringValues `json:"values,omitempty"`
69+
AllowAll bool `json:"allow_all,omitempty"`
70+
DenyAll bool `json:"deny_all,omitempty"`
71+
Enforce bool `json:"enforce,omitempty"`
72+
Condition *Expr `json:"condition,omitempty"`
73+
}
74+
75+
type StringValues struct {
76+
AllowedValues []string `json:"allowed_values,omitempty"`
77+
DeniedValues []string `json:"denied_values,omitempty"`
78+
}
79+
80+
type Expr struct {
81+
Expression string `json:"expression,omitempty"`
82+
Title string `json:"title,omitempty"`
83+
Description string `json:"description,omitempty"`
84+
Location string `json:"location,omitempty"`
85+
}
86+
87+
type Timestamp struct {
88+
Seconds int64 `json:"seconds,omitempty"`
89+
Nanos int64 `json:"nanos,omitempty"`
90+
}
91+
92+
func (t Timestamp) MarshalJSON() ([]byte, error) {
93+
return []byte(`"` + time.Unix(0, t.Nanos).UTC().Format(time.RFC3339Nano) + `"`), nil
94+
}
95+
96+
func (t *Timestamp) UnmarshalJSON(b []byte) error {
97+
p, err := time.Parse(time.RFC3339Nano, strings.Trim(string(b), `"`))
98+
if err != nil {
99+
return fmt.Errorf("bad Timestamp: %v", err)
100+
}
101+
t.Seconds = p.Unix()
102+
t.Nanos = p.UnixNano()
103+
return nil
104+
}
105+
106+
// ListPolicyAllValues is used to set `Policies` that apply to all possible
107+
// configuration values rather than specific values in `allowed_values` or
108+
// `denied_values`.
109+
type ListPolicyAllValues int32
110+
111+
// ListPolicy can define specific values and subtrees of Cloud Resource
112+
// Manager resource hierarchy (`Organizations`, `Folders`, `Projects`) that
113+
// are allowed or denied by setting the `allowed_values` and `denied_values`
114+
// fields.
115+
type ListPolicy struct {
116+
AllowedValues []string `json:"allowed_values,omitempty"`
117+
DeniedValues []string `json:"denied_values,omitempty"`
118+
AllValues ListPolicyAllValues `json:"all_values,omitempty"`
119+
SuggestedValue string `json:"suggested_value,omitempty"`
120+
InheritFromParent bool `json:"inherit_from_parent,omitempty"`
121+
}
122+
123+
// BooleanPolicy If `true`, then the `Policy` is enforced. If `false`,
124+
// then any configuration is acceptable.
125+
type BooleanPolicy struct {
126+
Enforced bool `json:"enforced,omitempty"`
127+
}
128+
129+
// RestoreDefault determines if the default values of the `Constraints` are active for the
130+
// resources.
131+
type RestoreDefault struct {
132+
}

0 commit comments

Comments
 (0)