Skip to content

gcp.ImportSSHKeyE requires projectId #1035

@shawnritchie

Description

@shawnritchie

I m getting an error while doing gcp.ImportSSHKeyE which is mentioning that the projectId is missing, after analyzing the code I made the following local modification and this worked. I m not sure if I am missing maybe some local configuration but form the examples I saw it doesn't seem so.

Problematic function: https://github.com/gruntwork-io/terratest/blob/master/modules/gcp/oslogin.go#L41

func ImportSSHKeyE(t t.TestingT, user, project, key string) error {
	ctx := context.Background()
	service, err := gcp.NewOSLoginServiceE(t)
	if err != nil {
		return err
	}

	parent := fmt.Sprintf("users/%s", user)

	sshPublicKey := &oslogin.SshPublicKey{
		Key: key,
	}

	_, err = service.Users.ImportSshPublicKey(parent, sshPublicKey).ProjectId(project).Context(ctx).Do()
	if err != nil {
		return err
	}

	return nil
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions