Skip to content

Commit

Permalink
feat: change output for describe command
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Guibert committed Apr 6, 2022
1 parent 641f2ea commit 033cfce
Show file tree
Hide file tree
Showing 11 changed files with 1,847 additions and 450 deletions.
335 changes: 335 additions & 0 deletions output
Original file line number Diff line number Diff line change
@@ -0,0 +1,335 @@
{
"options": {
"deep": false,
"only_managed": false,
"only_unmanaged": false
},
"summary": {
"total_resources": 52,
"total_changed": 0,
"total_unmanaged": 41,
"total_missing": 5,
"total_managed": 6,
"total_iac_source_count": 1
},
"managed": [
{
"id": "AKIAXVMHWD4BZYCSQOG3",
"type": "aws_iam_access_key",
"human_readable_attributes": {
"User": "storageservice"
},
"source": {
"source": "tfstate://../driftctl/terraform.tfstate",
"namespace": "",
"internal_name": "storageservice"
}
},
{
"id": "storageservice-arn:aws:iam::526954929923:policy/sqshandlingpolicy",
"type": "aws_iam_policy_attachment"
},
{
"id": "storageservice",
"type": "aws_iam_user",
"source": {
"source": "tfstate://../driftctl/terraform.tfstate",
"namespace": "",
"internal_name": "storageservice"
}
},
{
"id": "arn:aws:iam::526954929923:policy/s3listingpolicy",
"type": "aws_iam_policy",
"source": {
"source": "tfstate://../driftctl/terraform.tfstate",
"namespace": "",
"internal_name": "s3lstpol"
}
},
{
"id": "arn:aws:iam::526954929923:policy/sqshandlingpolicy",
"type": "aws_iam_policy",
"source": {
"source": "tfstate://../driftctl/terraform.tfstate",
"namespace": "",
"internal_name": "sqshandlingpolicy"
}
},
{
"id": "storageservice:storageservice_s3_admin",
"type": "aws_iam_user_policy",
"source": {
"source": "tfstate://../driftctl/terraform.tfstate",
"namespace": "",
"internal_name": "storageservice_s3_admin"
}
}
],
"unmanaged": [
{
"id": "AKIAXVMHWD4BRT2NN4CO",
"type": "aws_iam_access_key",
"human_readable_attributes": {
"User": "admin"
}
},
{
"id": "AKIAXVMHWD4BTMNTJAKL",
"type": "aws_iam_access_key",
"human_readable_attributes": {
"User": "user"
}
},
{
"id": "AKIAXVMHWD4BZ3UGZRVX",
"type": "aws_iam_access_key",
"human_readable_attributes": {
"User": "martin"
}
},
{
"id": "arn:aws:iam::526954929923:policy/driftctl-user-policy",
"type": "aws_iam_policy"
},
{
"id": "AWSServiceRoleForCloudTrail-arn:aws:iam::aws:policy/aws-service-role/CloudTrailServiceRolePolicy",
"type": "aws_iam_policy_attachment"
},
{
"id": "AWSServiceRoleForDynamoDBReplication-arn:aws:iam::aws:policy/aws-service-role/DynamoDBReplicationServiceRolePolicy",
"type": "aws_iam_policy_attachment"
},
{
"id": "AWSServiceRoleForRDS-arn:aws:iam::aws:policy/aws-service-role/AmazonRDSServiceRolePolicy",
"type": "aws_iam_policy_attachment"
},
{
"id": "admin-arn:aws:iam::aws:policy/job-function/SystemAdministrator",
"type": "aws_iam_policy_attachment"
},
{
"id": "martin-arn:aws:iam::aws:policy/AdministratorAccess",
"type": "aws_iam_policy_attachment"
},
{
"id": "user-arn:aws:iam::aws:policy/ReadOnlyAccess",
"type": "aws_iam_policy_attachment"
},
{
"id": "user-arn:aws:iam::aws:policy/job-function/SystemAdministrator",
"type": "aws_iam_policy_attachment"
},
{
"id": "OrganizationAccountAccessRole",
"type": "aws_iam_role"
},
{
"id": "driftctl-role",
"type": "aws_iam_role"
},
{
"id": "iam_for_lambda",
"type": "aws_iam_role"
},
{
"id": "OrganizationAccountAccessRole:AdministratorAccess",
"type": "aws_iam_role_policy"
},
{
"id": "driftctl-role:driftctl-role-policy",
"type": "aws_iam_role_policy"
},
{
"id": "admin",
"type": "aws_iam_user"
},
{
"id": "martin",
"type": "aws_iam_user"
},
{
"id": "user",
"type": "aws_iam_user"
},
{
"id": "igw-08ef26e12512ff7cd",
"type": "aws_internet_gateway"
},
{
"id": "nacl-1234973027",
"type": "aws_network_acl_rule",
"human_readable_attributes": {
"CIDR": "0.0.0.0/0",
"Egress": "true",
"Network": "acl-056cb6e67f7e1fb71",
"Protocol": "All",
"Rule number": "100"
}
},
{
"id": "nacl-2402053966",
"type": "aws_network_acl_rule",
"human_readable_attributes": {
"CIDR": "0.0.0.0/0",
"Egress": "false",
"Network": "acl-056cb6e67f7e1fb71",
"Protocol": "All",
"Rule number": "100"
}
},
{
"id": "r-rtb-03f3651440b10daf4505606960",
"type": "aws_route",
"human_readable_attributes": {
"Destination": "pl-6da54004",
"Table": "rtb-03f3651440b10daf4"
}
},
{
"id": "r-rtb-0892149d8901488e11080289494",
"type": "aws_route",
"human_readable_attributes": {
"Destination": "0.0.0.0/0",
"Table": "rtb-0892149d8901488e1"
}
},
{
"id": "r-rtb-0944d3327d47630431080289494",
"type": "aws_route",
"human_readable_attributes": {
"Destination": "0.0.0.0/0",
"Table": "rtb-0944d3327d4763043"
}
},
{
"id": "r-rtb-0ba6c9d11069ab6e0505606960",
"type": "aws_route",
"human_readable_attributes": {
"Destination": "pl-6da54004",
"Table": "rtb-0ba6c9d11069ab6e0"
}
},
{
"id": "Z0550848EDQNFSD05MSY_blog.martin.ski_A",
"type": "aws_route53_record",
"human_readable_attributes": {
"Type": "A"
}
},
{
"id": "Z0550848EDQNFSD05MSY",
"type": "aws_route53_zone"
},
{
"id": "rtb-03f3651440b10daf4",
"type": "aws_route_table"
},
{
"id": "rtb-0892149d8901488e1",
"type": "aws_route_table"
},
{
"id": "rtb-0944d3327d4763043",
"type": "aws_route_table"
},
{
"id": "rtb-0ba6c9d11069ab6e0",
"type": "aws_route_table"
},
{
"id": "rtbassoc-01613a3c87b176fd3",
"type": "aws_route_table_association",
"human_readable_attributes": {
"Table": "rtb-03f3651440b10daf4"
}
},
{
"id": "rtbassoc-080566085522ca34a",
"type": "aws_route_table_association",
"human_readable_attributes": {
"Table": "rtb-0892149d8901488e1"
}
},
{
"id": "rtbassoc-085e4b4b6f67c185b",
"type": "aws_route_table_association",
"human_readable_attributes": {
"Table": "rtb-0ba6c9d11069ab6e0"
}
},
{
"id": "rtbassoc-0f7a45bd571a24cab",
"type": "aws_route_table_association",
"human_readable_attributes": {
"Table": "rtb-0944d3327d4763043"
}
},
{
"id": "subnet-0180be8b9ca09f545",
"type": "aws_subnet"
},
{
"id": "subnet-064c93baa3e556bd7",
"type": "aws_subnet"
},
{
"id": "subnet-0cad4105a809fabb1",
"type": "aws_subnet"
},
{
"id": "subnet-0ddd9e836236efb03",
"type": "aws_subnet"
},
{
"id": "vpc-00e555cc12bca5b5e",
"type": "aws_vpc"
}
],
"missing": [
{
"id": "AKIAXVMHWD4BRJ6WCGAD",
"type": "aws_iam_access_key",
"human_readable_attributes": {
"User": "loadbalancer"
},
"source": {
"source": "tfstate://../driftctl/terraform.tfstate",
"namespace": "",
"internal_name": "lb"
}
},
{
"id": "loadbalancer-arn:aws:iam::526954929923:policy/s3listingpolicy",
"type": "aws_iam_policy_attachment"
},
{
"id": "loadbalancer-arn:aws:iam::526954929923:policy/sqshandlingpolicy",
"type": "aws_iam_policy_attachment"
},
{
"id": "loadbalancer",
"type": "aws_iam_user",
"source": {
"source": "tfstate://../driftctl/terraform.tfstate",
"namespace": "",
"internal_name": "loadbalancer"
}
},
{
"id": "loadbalancer:lb_ec2_ro",
"type": "aws_iam_user_policy",
"source": {
"source": "tfstate://../driftctl/terraform.tfstate",
"namespace": "",
"internal_name": "lb_ec2_ro"
}
}
],
"differences": null,
"coverage": 11,
"alerts": null,
"provider_name": "aws",
"provider_version": "3.19.0",
"scan_duration": 2
}
17 changes: 7 additions & 10 deletions src/cli/commands/describe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@ import { MethodArgs } from '../args';
import { processCommandArgs } from './process-command-args';
import * as legacyError from '../../lib/errors/legacy-errors';
import {
DCTL_EXIT_CODES,
runDriftCTL,
driftignoreFromPolicy,
parseDriftAnalysisResults,
processDriftctlOutput,
processAnalysis,
} from '../../lib/iac/drift';
import { getIacOrgSettings } from './test/iac-local-execution/org-settings/get-iac-org-settings';
import { UnsupportedEntitlementCommandError } from './test/iac-local-execution/assert-iac-options-flag';
Expand All @@ -16,6 +14,7 @@ import * as analytics from '../../lib/analytics';
import { findAndLoadPolicy } from '../../lib/policy';
import { DescribeRequiredArgumentError } from '../../lib/errors/describe-required-argument-error';
import help from './help';
import { DCTL_EXIT_CODES, runDriftCTL } from '../../lib/iac/drift/driftctl';

export default async (...args: MethodArgs): Promise<any> => {
const { options } = processCommandArgs(...args);
Expand All @@ -42,23 +41,21 @@ export default async (...args: MethodArgs): Promise<any> => {
options: { ...options, kind: 'describe' },
driftIgnore: driftIgnore,
});

process.exitCode = describe.code;

analytics.add('is-iac-drift', true);
analytics.add('iac-drift-exit-code', describe.code);
if (describe.code === DCTL_EXIT_CODES.EXIT_ERROR) {
process.exitCode = describe.code;
throw new Error();
}

// Parse analysis JSON and add to analytics
const analysis = parseDriftAnalysisResults(describe.stdout);
addIacDriftAnalytics(analysis, options);

const fmtResult = await runDriftCTL({
options: { ...options, kind: 'fmt' },
input: describe.stdout,
});
process.stdout.write(processDriftctlOutput(options, fmtResult.stdout));
process.exitCode = describe.code;
const output = await processAnalysis(options, describe);
process.stdout.write(output);
} catch (e) {
if (e instanceof DescribeRequiredArgumentError) {
// when missing a required arg we will display help to explain
Expand Down
2 changes: 1 addition & 1 deletion src/cli/commands/test/iac-local-execution/analytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as analytics from '../../../../lib/analytics';
import { calculatePercentage } from './math-utils';
import { computeCustomRulesBundleChecksum } from './file-utils';
import { DescribeOptions, DriftAnalysis } from '../../../../lib/iac/types';
import { driftctlVersion } from '../../../../lib/iac/drift';
import { driftctlVersion } from '../../../../lib/iac/drift/driftctl';

export function addIacAnalytics(
formattedResults: FormattedResult[],
Expand Down
Loading

0 comments on commit 033cfce

Please sign in to comment.