{"id":2241,"date":"2021-12-16T19:31:05","date_gmt":"2021-12-16T16:31:05","guid":{"rendered":"https:\/\/artem.services\/?p=2208"},"modified":"2022-06-08T20:35:51","modified_gmt":"2022-06-08T17:35:51","slug":"2241","status":"publish","type":"post","link":"https:\/\/artem.services\/?p=2241&lang=en","title":{"rendered":"\u00a0Terraform &#8212; AWS Secrets Manager: Retrieve RDS login\/password"},"content":{"rendered":"<p><img loading=\"lazy\" class=\"aligncenter size-full wp-image-99\" src=\"https:\/\/artem.services\/wp-content\/uploads\/2018\/10\/terraform.png\" alt=\"\" width=\"1210\" height=\"418\" srcset=\"https:\/\/artem.services\/wp-content\/uploads\/2018\/10\/terraform.png 1210w, https:\/\/artem.services\/wp-content\/uploads\/2018\/10\/terraform-300x104.png 300w, https:\/\/artem.services\/wp-content\/uploads\/2018\/10\/terraform-768x265.png 768w, https:\/\/artem.services\/wp-content\/uploads\/2018\/10\/terraform-1024x354.png 1024w, https:\/\/artem.services\/wp-content\/uploads\/2018\/10\/terraform-954x330.png 954w\" sizes=\"(max-width: 1210px) 100vw, 1210px\" \/><\/p>\n<p>It is necessary to extract the login and password from RDS, which are stored in AWS Secret Manager and use their values in the Terraform code. To do this, you can use the following construction:<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n# Should be there before the apply\r\ndata &quot;aws_secretsmanager_secret&quot; &quot;rds-admin-user&quot; {\r\n  name  = &quot;\/ARTEM-SERVICES\/PROD\/RDS\/CREDENTIALS&quot;\r\n}\r\n\r\ndata &quot;aws_secretsmanager_secret_version&quot; &quot;rds-admin-user&quot; {\r\n  secret_id = data.aws_secretsmanager_secret.rds-admin-user.id\r\n}\r\n\r\nlocals {\r\n  additional_rds_username      = jsondecode(data.aws_secretsmanager_secret_version.rds-admin-user.secret_string)[&quot;username&quot;]\r\n  additional_rds_user_password = jsondecode(data.aws_secretsmanager_secret_version.rds-admin-user.secret_string)[&quot;password&quot;]\r\n}\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p><span class=\"VIiyi\" lang=\"en\"><span class=\"JLqJ4b ChMk0b\" data-language-for-alternatives=\"en\" data-language-to-translate-into=\"ru\" data-phrase-index=\"0\" data-number-of-phrases=\"1\"><span class=\"Q4iAWc\">And use variables:<\/span><\/span><\/span><\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\nlocal.additional_rds_username\r\nlocal.additional_rds_user_password\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>It is necessary to extract the login and password from RDS, which are stored in AWS Secret Manager and use their values in the Terraform code. To do this, you can use the following construction: &nbsp; And use variables: &nbsp; &nbsp;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[541],"tags":[543,1813,555],"_links":{"self":[{"href":"https:\/\/artem.services\/index.php?rest_route=\/wp\/v2\/posts\/2241"}],"collection":[{"href":"https:\/\/artem.services\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/artem.services\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/artem.services\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/artem.services\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2241"}],"version-history":[{"count":2,"href":"https:\/\/artem.services\/index.php?rest_route=\/wp\/v2\/posts\/2241\/revisions"}],"predecessor-version":[{"id":2243,"href":"https:\/\/artem.services\/index.php?rest_route=\/wp\/v2\/posts\/2241\/revisions\/2243"}],"wp:attachment":[{"href":"https:\/\/artem.services\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2241"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/artem.services\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2241"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/artem.services\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2241"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}