Skip to content

Commit

Permalink
Update cloudfunction id for 3.0.0 release (#2501)
Browse files Browse the repository at this point in the history
  • Loading branch information
slevenick committed Nov 7, 2019
1 parent b8950f5 commit 696199a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func dataSourceGoogleCloudFunctionsFunctionRead(d *schema.ResourceData, meta int
Name: d.Get("name").(string),
}

d.SetId(cloudFuncId.terraformId())
d.SetId(cloudFuncId.cloudFunctionId())

err = resourceCloudFunctionsRead(d, meta)
if err != nil {
Expand Down
36 changes: 17 additions & 19 deletions third_party/terraform/resources/resource_cloudfunctions_function.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,21 +43,19 @@ func (s *cloudFunctionId) locationId() string {
return fmt.Sprintf("projects/%s/locations/%s", s.Project, s.Region)
}

func (s *cloudFunctionId) terraformId() string {
return fmt.Sprintf("%s/%s/%s", s.Project, s.Region, s.Name)
}

func parseCloudFunctionId(id string, config *Config) (*cloudFunctionId, error) {
if parts := strings.Split(id, "/"); len(parts) == 3 {
return &cloudFunctionId{
Project: parts[0],
Region: parts[1],
Name: parts[2],
}, nil
}

return nil, fmt.Errorf("Invalid CloudFunction id format, expecting " +
"`{projectId}/{regionId}/{cloudFunctionName}`")
func parseCloudFunctionId(d *schema.ResourceData, config *Config) (*cloudFunctionId, error) {
if err := parseImportId([]string{
"projects/(?P<project>[^/]+)/locations/(?P<region>[^/]+)/functions/(?P<name>[^/]+)",
"(?P<project>[^/]+)/(?P<region>[^/]+)/(?P<name>[^/]+)",
"(?P<name>[^/]+)",
}, d, config); err != nil {
return nil, err
}
return &cloudFunctionId{
Project: d.Get("project").(string),
Region: d.Get("region").(string),
Name: d.Get("name").(string),
}, nil
}

func joinMapKeys(mapToJoin *map[int]bool) string {
Expand Down Expand Up @@ -372,7 +370,7 @@ func resourceCloudFunctionsCreate(d *schema.ResourceData, meta interface{}) erro
}

// Name of function should be unique
d.SetId(cloudFuncId.terraformId())
d.SetId(cloudFuncId.cloudFunctionId())

err = cloudFunctionsOperationWait(config.clientCloudFunctions, op, "Creating CloudFunctions Function",
int(d.Timeout(schema.TimeoutCreate).Minutes()))
Expand All @@ -386,7 +384,7 @@ func resourceCloudFunctionsCreate(d *schema.ResourceData, meta interface{}) erro
func resourceCloudFunctionsRead(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)

cloudFuncId, err := parseCloudFunctionId(d.Id(), config)
cloudFuncId, err := parseCloudFunctionId(d, config)
if err != nil {
return err
}
Expand Down Expand Up @@ -447,7 +445,7 @@ func resourceCloudFunctionsUpdate(d *schema.ResourceData, meta interface{}) erro
return err
}

cloudFuncId, err := parseCloudFunctionId(d.Id(), config)
cloudFuncId, err := parseCloudFunctionId(d, config)
if err != nil {
return err
}
Expand Down Expand Up @@ -536,7 +534,7 @@ func resourceCloudFunctionsUpdate(d *schema.ResourceData, meta interface{}) erro
func resourceCloudFunctionsDestroy(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)

cloudFuncId, err := parseCloudFunctionId(d.Id(), config)
cloudFuncId, err := parseCloudFunctionId(d, config)
if err != nil {
return err
}
Expand Down

0 comments on commit 696199a

Please sign in to comment.