This repository has been archived by the owner on Nov 27, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(vertexai): Add IAM resources for Vertex AI FeatureStore EntityTy…
…pe (beta) (#6789) (#1149) * feat: add the iam resources for featurestore entitytype * fix: fix the unit test errors Signed-off-by: Modular Magician <magic-modules@google.com> Signed-off-by: Modular Magician <magic-modules@google.com>
- Loading branch information
1 parent
6ce904c
commit 1bc90f9
Showing
5 changed files
with
311 additions
and
3 deletions.
There are no files selected for viewing
182 changes: 182 additions & 0 deletions
182
converters/google/resources/iam_vertex_ai_featurestore_entitytype.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,182 @@ | ||
// ---------------------------------------------------------------------------- | ||
// | ||
// *** AUTO GENERATED CODE *** Type: MMv1 *** | ||
// | ||
// ---------------------------------------------------------------------------- | ||
// | ||
// This file is automatically generated by Magic Modules and manual | ||
// changes will be clobbered when the file is regenerated. | ||
// | ||
// Please read more about how to change this file in | ||
// .github/CONTRIBUTING.md. | ||
// | ||
// ---------------------------------------------------------------------------- | ||
|
||
package google | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/hashicorp/errwrap" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
"google.golang.org/api/cloudresourcemanager/v1" | ||
) | ||
|
||
var VertexAIFeaturestoreEntitytypeIamSchema = map[string]*schema.Schema{ | ||
"featurestore": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
ForceNew: true, | ||
}, | ||
"entitytype": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
ForceNew: true, | ||
DiffSuppressFunc: compareSelfLinkOrResourceName, | ||
}, | ||
} | ||
|
||
type VertexAIFeaturestoreEntitytypeIamUpdater struct { | ||
featurestore string | ||
entitytype string | ||
d TerraformResourceData | ||
Config *Config | ||
} | ||
|
||
func VertexAIFeaturestoreEntitytypeIamUpdaterProducer(d TerraformResourceData, config *Config) (ResourceIamUpdater, error) { | ||
values := make(map[string]string) | ||
|
||
if v, ok := d.GetOk("featurestore"); ok { | ||
values["featurestore"] = v.(string) | ||
} | ||
|
||
if v, ok := d.GetOk("entitytype"); ok { | ||
values["entitytype"] = v.(string) | ||
} | ||
|
||
// We may have gotten either a long or short name, so attempt to parse long name if possible | ||
m, err := getImportIdQualifiers([]string{"(?P<featurestore>.+)/entityTypes/(?P<entitytype>[^/]+)", "(?P<entitytype>[^/]+)"}, d, config, d.Get("entitytype").(string)) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
for k, v := range m { | ||
values[k] = v | ||
} | ||
|
||
u := &VertexAIFeaturestoreEntitytypeIamUpdater{ | ||
featurestore: values["featurestore"], | ||
entitytype: values["entitytype"], | ||
d: d, | ||
Config: config, | ||
} | ||
|
||
if err := d.Set("featurestore", u.featurestore); err != nil { | ||
return nil, fmt.Errorf("Error setting featurestore: %s", err) | ||
} | ||
if err := d.Set("entitytype", u.GetResourceId()); err != nil { | ||
return nil, fmt.Errorf("Error setting entitytype: %s", err) | ||
} | ||
|
||
return u, nil | ||
} | ||
|
||
func VertexAIFeaturestoreEntitytypeIdParseFunc(d *schema.ResourceData, config *Config) error { | ||
values := make(map[string]string) | ||
|
||
m, err := getImportIdQualifiers([]string{"(?P<featurestore>.+)/entityTypes/(?P<entitytype>[^/]+)", "(?P<entitytype>[^/]+)"}, d, config, d.Id()) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
for k, v := range m { | ||
values[k] = v | ||
} | ||
|
||
u := &VertexAIFeaturestoreEntitytypeIamUpdater{ | ||
featurestore: values["featurestore"], | ||
entitytype: values["entitytype"], | ||
d: d, | ||
Config: config, | ||
} | ||
if err := d.Set("entitytype", u.GetResourceId()); err != nil { | ||
return fmt.Errorf("Error setting entitytype: %s", err) | ||
} | ||
d.SetId(u.GetResourceId()) | ||
return nil | ||
} | ||
|
||
func (u *VertexAIFeaturestoreEntitytypeIamUpdater) GetResourceIamPolicy() (*cloudresourcemanager.Policy, error) { | ||
url, err := u.qualifyFeaturestoreEntitytypeUrl("getIamPolicy") | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
var obj map[string]interface{} | ||
|
||
userAgent, err := generateUserAgentString(u.d, u.Config.userAgent) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
policy, err := sendRequest(u.Config, "POST", "", url, userAgent, obj) | ||
if err != nil { | ||
return nil, errwrap.Wrapf(fmt.Sprintf("Error retrieving IAM policy for %s: {{err}}", u.DescribeResource()), err) | ||
} | ||
|
||
out := &cloudresourcemanager.Policy{} | ||
err = Convert(policy, out) | ||
if err != nil { | ||
return nil, errwrap.Wrapf("Cannot convert a policy to a resource manager policy: {{err}}", err) | ||
} | ||
|
||
return out, nil | ||
} | ||
|
||
func (u *VertexAIFeaturestoreEntitytypeIamUpdater) SetResourceIamPolicy(policy *cloudresourcemanager.Policy) error { | ||
json, err := ConvertToMap(policy) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
obj := make(map[string]interface{}) | ||
obj["policy"] = json | ||
|
||
url, err := u.qualifyFeaturestoreEntitytypeUrl("setIamPolicy") | ||
if err != nil { | ||
return err | ||
} | ||
|
||
userAgent, err := generateUserAgentString(u.d, u.Config.userAgent) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
_, err = sendRequestWithTimeout(u.Config, "POST", "", url, userAgent, obj, u.d.Timeout(schema.TimeoutCreate)) | ||
if err != nil { | ||
return errwrap.Wrapf(fmt.Sprintf("Error setting IAM policy for %s: {{err}}", u.DescribeResource()), err) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (u *VertexAIFeaturestoreEntitytypeIamUpdater) qualifyFeaturestoreEntitytypeUrl(methodIdentifier string) (string, error) { | ||
urlTemplate := fmt.Sprintf("{{VertexAIBasePath}}%s:%s", fmt.Sprintf("%s/entityTypes/%s", u.featurestore, u.entitytype), methodIdentifier) | ||
url, err := replaceVars(u.d, u.Config, urlTemplate) | ||
if err != nil { | ||
return "", err | ||
} | ||
return url, nil | ||
} | ||
|
||
func (u *VertexAIFeaturestoreEntitytypeIamUpdater) GetResourceId() string { | ||
return fmt.Sprintf("%s/entityTypes/%s", u.featurestore, u.entitytype) | ||
} | ||
|
||
func (u *VertexAIFeaturestoreEntitytypeIamUpdater) GetMutexKey() string { | ||
return fmt.Sprintf("iam-vertexai-featurestoreentitytype-%s", u.GetResourceId()) | ||
} | ||
|
||
func (u *VertexAIFeaturestoreEntitytypeIamUpdater) DescribeResource() string { | ||
return fmt.Sprintf("vertexai featurestoreentitytype %q", u.GetResourceId()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
123 changes: 123 additions & 0 deletions
123
converters/google/resources/vertex_ai_featurestore_entitytype_iam.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
// ---------------------------------------------------------------------------- | ||
// | ||
// *** AUTO GENERATED CODE *** Type: MMv1 *** | ||
// | ||
// ---------------------------------------------------------------------------- | ||
// | ||
// This file is automatically generated by Magic Modules and manual | ||
// changes will be clobbered when the file is regenerated. | ||
// | ||
// Please read more about how to change this file in | ||
// .github/CONTRIBUTING.md. | ||
// | ||
// ---------------------------------------------------------------------------- | ||
|
||
package google | ||
|
||
import "fmt" | ||
|
||
// Provide a separate asset type constant so we don't have to worry about name conflicts between IAM and non-IAM converter files | ||
const VertexAIFeaturestoreEntitytypeIAMAssetType string = "{{region}}-aiplatform.googleapis.com/FeaturestoreEntitytype" | ||
|
||
func resourceConverterVertexAIFeaturestoreEntitytypeIamPolicy() ResourceConverter { | ||
return ResourceConverter{ | ||
AssetType: VertexAIFeaturestoreEntitytypeIAMAssetType, | ||
Convert: GetVertexAIFeaturestoreEntitytypeIamPolicyCaiObject, | ||
MergeCreateUpdate: MergeVertexAIFeaturestoreEntitytypeIamPolicy, | ||
} | ||
} | ||
|
||
func resourceConverterVertexAIFeaturestoreEntitytypeIamBinding() ResourceConverter { | ||
return ResourceConverter{ | ||
AssetType: VertexAIFeaturestoreEntitytypeIAMAssetType, | ||
Convert: GetVertexAIFeaturestoreEntitytypeIamBindingCaiObject, | ||
FetchFullResource: FetchVertexAIFeaturestoreEntitytypeIamPolicy, | ||
MergeCreateUpdate: MergeVertexAIFeaturestoreEntitytypeIamBinding, | ||
MergeDelete: MergeVertexAIFeaturestoreEntitytypeIamBindingDelete, | ||
} | ||
} | ||
|
||
func resourceConverterVertexAIFeaturestoreEntitytypeIamMember() ResourceConverter { | ||
return ResourceConverter{ | ||
AssetType: VertexAIFeaturestoreEntitytypeIAMAssetType, | ||
Convert: GetVertexAIFeaturestoreEntitytypeIamMemberCaiObject, | ||
FetchFullResource: FetchVertexAIFeaturestoreEntitytypeIamPolicy, | ||
MergeCreateUpdate: MergeVertexAIFeaturestoreEntitytypeIamMember, | ||
MergeDelete: MergeVertexAIFeaturestoreEntitytypeIamMemberDelete, | ||
} | ||
} | ||
|
||
func GetVertexAIFeaturestoreEntitytypeIamPolicyCaiObject(d TerraformResourceData, config *Config) ([]Asset, error) { | ||
return newVertexAIFeaturestoreEntitytypeIamAsset(d, config, expandIamPolicyBindings) | ||
} | ||
|
||
func GetVertexAIFeaturestoreEntitytypeIamBindingCaiObject(d TerraformResourceData, config *Config) ([]Asset, error) { | ||
return newVertexAIFeaturestoreEntitytypeIamAsset(d, config, expandIamRoleBindings) | ||
} | ||
|
||
func GetVertexAIFeaturestoreEntitytypeIamMemberCaiObject(d TerraformResourceData, config *Config) ([]Asset, error) { | ||
return newVertexAIFeaturestoreEntitytypeIamAsset(d, config, expandIamMemberBindings) | ||
} | ||
|
||
func MergeVertexAIFeaturestoreEntitytypeIamPolicy(existing, incoming Asset) Asset { | ||
existing.IAMPolicy = incoming.IAMPolicy | ||
return existing | ||
} | ||
|
||
func MergeVertexAIFeaturestoreEntitytypeIamBinding(existing, incoming Asset) Asset { | ||
return mergeIamAssets(existing, incoming, mergeAuthoritativeBindings) | ||
} | ||
|
||
func MergeVertexAIFeaturestoreEntitytypeIamBindingDelete(existing, incoming Asset) Asset { | ||
return mergeDeleteIamAssets(existing, incoming, mergeDeleteAuthoritativeBindings) | ||
} | ||
|
||
func MergeVertexAIFeaturestoreEntitytypeIamMember(existing, incoming Asset) Asset { | ||
return mergeIamAssets(existing, incoming, mergeAdditiveBindings) | ||
} | ||
|
||
func MergeVertexAIFeaturestoreEntitytypeIamMemberDelete(existing, incoming Asset) Asset { | ||
return mergeDeleteIamAssets(existing, incoming, mergeDeleteAdditiveBindings) | ||
} | ||
|
||
func newVertexAIFeaturestoreEntitytypeIamAsset( | ||
d TerraformResourceData, | ||
config *Config, | ||
expandBindings func(d TerraformResourceData) ([]IAMBinding, error), | ||
) ([]Asset, error) { | ||
bindings, err := expandBindings(d) | ||
if err != nil { | ||
return []Asset{}, fmt.Errorf("expanding bindings: %v", err) | ||
} | ||
|
||
name, err := assetName(d, config, "//{{region}}-aiplatform.googleapis.com/{{featurestore}}/entityTypes/{{entitytype}}") | ||
if err != nil { | ||
return []Asset{}, err | ||
} | ||
|
||
return []Asset{{ | ||
Name: name, | ||
Type: VertexAIFeaturestoreEntitytypeIAMAssetType, | ||
IAMPolicy: &IAMPolicy{ | ||
Bindings: bindings, | ||
}, | ||
}}, nil | ||
} | ||
|
||
func FetchVertexAIFeaturestoreEntitytypeIamPolicy(d TerraformResourceData, config *Config) (Asset, error) { | ||
// Check if the identity field returns a value | ||
if _, ok := d.GetOk("featurestore"); !ok { | ||
return Asset{}, ErrEmptyIdentityField | ||
} | ||
if _, ok := d.GetOk("entitytype"); !ok { | ||
return Asset{}, ErrEmptyIdentityField | ||
} | ||
|
||
return fetchIamPolicy( | ||
VertexAIFeaturestoreEntitytypeIamUpdaterProducer, | ||
d, | ||
config, | ||
"//{{region}}-aiplatform.googleapis.com/{{featurestore}}/entityTypes/{{entitytype}}", | ||
VertexAIFeaturestoreEntitytypeIAMAssetType, | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters