...

Source file src/github.com/GoogleCloudPlatform/k8s-config-connector/pkg/resourceoverrides/iam_customrole.go

Documentation: github.com/GoogleCloudPlatform/k8s-config-connector/pkg/resourceoverrides

     1  // Copyright 2022 Google LLC
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //      http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package resourceoverrides
    16  
    17  import (
    18  	"context"
    19  	"fmt"
    20  
    21  	"github.com/GoogleCloudPlatform/k8s-config-connector/pkg/resourceoverrides/operations"
    22  )
    23  
    24  func GetIAMCustomRoleResourceOverrides() ResourceOverrides {
    25  	ro := ResourceOverrides{
    26  		Kind: "IAMCustomRole",
    27  	}
    28  	ro.Overrides = append(ro.Overrides, buildIAMCustomRole())
    29  	return ro
    30  }
    31  
    32  func buildIAMCustomRole() ResourceOverride {
    33  	h := &IAMCustomRole{}
    34  	o := ResourceOverride{
    35  		PreTerraformExport: h.PreTerraformExport,
    36  	}
    37  	return o
    38  }
    39  
    40  type IAMCustomRole struct {
    41  }
    42  
    43  func (h *IAMCustomRole) PreTerraformExport(ctx context.Context, op *operations.TerraformExport) error {
    44  	projectID := op.TerraformState.Attributes["project"]
    45  	orgID := op.TerraformState.Attributes["org_id"]
    46  
    47  	if projectID != "" && orgID != "" {
    48  		return fmt.Errorf("project=%q and org_id=%q were both set", projectID, orgID)
    49  	}
    50  
    51  	if projectID != "" {
    52  		op.TerraformInfo.Type = "google_project_iam_custom_role"
    53  	} else if orgID != "" {
    54  		op.TerraformInfo.Type = "google_organization_iam_custom_role"
    55  	} else {
    56  		return fmt.Errorf("unable to determine whether IAMCustomRole is org or project scoped")
    57  	}
    58  
    59  	return nil
    60  }
    61  

View as plain text