{"action":"created","issue":{"url":"https://api.github.com/repos/guardian/inspector-lambda/issues/18","repository_url":"https://api.github.com/repos/guardian/inspector-lambda","labels_url":"https://api.github.com/repos/guardian/inspector-lambda/issues/18/labels{/name}","comments_url":"https://api.github.com/repos/guardian/inspector-lambda/issues/18/comments","events_url":"https://api.github.com/repos/guardian/inspector-lambda/issues/18/events","html_url":"https://github.com/guardian/inspector-lambda/pull/18","id":319236929,"number":18,"title":"wait after deleting targets with same name but different ARN","user":{"login":"paulmr","id":2242307,"avatar_url":"https://avatars3.githubusercontent.com/u/2242307?v=4","gravatar_id":"","url":"https://api.github.com/users/paulmr","html_url":"https://github.com/paulmr","followers_url":"https://api.github.com/users/paulmr/followers","following_url":"https://api.github.com/users/paulmr/following{/other_user}","gists_url":"https://api.github.com/users/paulmr/gists{/gist_id}","starred_url":"https://api.github.com/users/paulmr/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/paulmr/subscriptions","organizations_url":"https://api.github.com/users/paulmr/orgs","repos_url":"https://api.github.com/users/paulmr/repos","events_url":"https://api.github.com/users/paulmr/events{/privacy}","received_events_url":"https://api.github.com/users/paulmr/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":4,"created_at":"2018-05-01T15:46:16Z","updated_at":"2018-05-02T10:51:36Z","closed_at":"2018-05-02T10:51:36Z","author_association":"MEMBER","pull_request":{"url":"https://api.github.com/repos/guardian/inspector-lambda/pulls/18","html_url":"https://github.com/guardian/inspector-lambda/pull/18","diff_url":"https://github.com/guardian/inspector-lambda/pull/18.diff","patch_url":"https://github.com/guardian/inspector-lambda/pull/18.patch"},"body":"The code which tries to find an existing set of assessment targets, has the functionality to delete targets which have the same name but a different ARN:\r\n\r\n```scala\r\ndef getAssessmentTarget(name: String, arn: String): Option[String] = {\r\n    // ... <SNIP> ...\r\n\r\n    // delete if arn is not correct\r\n    matchingAssessmentTargets\r\n      .filter(!_.getResourceGroupArn.equals(arn))\r\n      .foreach(assessmentTarget => {\r\n        logger.info(s\"Deleting ${assessmentTarget.getArn}\")\r\n        val deleteAssessmentTargetRequest = new DeleteAssessmentTargetRequest()\r\n          .withAssessmentTargetArn(assessmentTarget.getArn)\r\n        client.deleteAssessmentTarget(deleteAssessmentTargetRequest)\r\n      })\r\n```\r\nIf it then finds that there are none left with the correct ARN, it will try to make one (`CheifInspector.scala:47`):\r\n\r\n```\r\nval assessmentTargetArn = inspector.getAssessmentTarget(name, resourceGroupArn) getOrElse inspector.createAssessmentTarget(name, resourceGroupArn)\r\n```\r\n\r\nHowever, if the first code block initiated a deletion, then it may not have finished by the time the second code block attempts to create a new target with the same name, resulting in an exception.\r\n\r\n```\r\n[error] (run-main-b) com.amazonaws.services.inspector.model.InvalidInputException: Create assessmentTarget - Name already exists; Name: AWSInspection--ophan--tracker--PROD ParentOwner: 021353022223 (Service: AmazonInspector; Status Code: 400; Error Code: InvalidInputException; Request ID: dbe90419-4d4a-11e8-b404-71cc2b29381d)\r\n[error] com.amazonaws.services.inspector.model.InvalidInputException: Create assessmentTarget - Name already exists; Name: AWSInspection--ophan--tracker--PROD ParentOwner: 021353022223 (Service: AmazonInspector; Status Code: 400; Error Code: InvalidInputException; Request ID: dbe90419-4d4a-11e8-b404-71cc2b29381d)\r\n```\r\n\r\nThis change forces it to wait for an appropriate amount of time before trying to create the new target."},"comment":{"url":"https://api.github.com/repos/guardian/inspector-lambda/issues/comments/385938459","html_url":"https://github.com/guardian/inspector-lambda/pull/18#issuecomment-385938459","issue_url":"https://api.github.com/repos/guardian/inspector-lambda/issues/18","id":385938459,"user":{"login":"paulmr","id":2242307,"avatar_url":"https://avatars3.githubusercontent.com/u/2242307?v=4","gravatar_id":"","url":"https://api.github.com/users/paulmr","html_url":"https://github.com/paulmr","followers_url":"https://api.github.com/users/paulmr/followers","following_url":"https://api.github.com/users/paulmr/following{/other_user}","gists_url":"https://api.github.com/users/paulmr/gists{/gist_id}","starred_url":"https://api.github.com/users/paulmr/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/paulmr/subscriptions","organizations_url":"https://api.github.com/users/paulmr/orgs","repos_url":"https://api.github.com/users/paulmr/repos","events_url":"https://api.github.com/users/paulmr/events{/privacy}","received_events_url":"https://api.github.com/users/paulmr/received_events","type":"User","site_admin":false},"created_at":"2018-05-02T10:51:36Z","updated_at":"2018-05-02T10:51:36Z","author_association":"MEMBER","body":"Alas, we decided I don't have time to develop the fix further as it is now working for us by either deleting all the targets first, or by applying this fix locally :( Apologies."}}
{"actor":{"display_login":"paulmr"}}