-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
support report format and collector mode
- Loading branch information
1 parent
aa03c54
commit 9b6d042
Showing
7 changed files
with
86 additions
and
45 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package mondoo | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
|
||
"github.com/hashicorp/terraform/communicator/shared" | ||
"github.com/hashicorp/terraform/terraform" | ||
"github.com/mitchellh/mapstructure" | ||
) | ||
|
||
// see https://www.terraform.io/docs/provisioners/connection.html | ||
type ProvisionerConnection struct { | ||
Type string `mapstructure:"type"` | ||
User string `mapstructure:"user"` | ||
Password string `mapstructure:"password"` | ||
PrivateKey string `mapstructure:"private_key"` | ||
Host string `mapstructure:"host"` | ||
Port int `mapstructure:"port"` | ||
} | ||
|
||
func (p *ProvisionerConnection) ToMondooConnection() (string, error) { | ||
switch p.Type { | ||
case "ssh": | ||
return fmt.Sprintf("ssh://%s@%s", p.User, p.Host), nil | ||
case "local": | ||
return "local://", nil | ||
} | ||
|
||
return "", errors.New(fmt.Sprintf("the requested %s connection type is not supported by mondoo terraform provisioner", p.Type)) | ||
} | ||
|
||
func tfConnection(s *terraform.InstanceState) (*ProvisionerConnection, error) { | ||
connInfo := &ProvisionerConnection{} | ||
decConf := &mapstructure.DecoderConfig{ | ||
WeaklyTypedInput: true, | ||
Result: connInfo, | ||
} | ||
dec, err := mapstructure.NewDecoder(decConf) | ||
if err != nil { | ||
return nil, err | ||
} | ||
if err := dec.Decode(s.Ephemeral.ConnInfo); err != nil { | ||
return nil, err | ||
} | ||
|
||
// format the host if needed, needed for IPv6 | ||
connInfo.Host = shared.IpFormat(connInfo.Host) | ||
return connInfo, nil | ||
} |
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
This file was deleted.
Oops, something went wrong.
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